-
Notifications
You must be signed in to change notification settings - Fork 19
/
next_update_check_policy_impl.h
98 lines (82 loc) · 3.62 KB
/
next_update_check_policy_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef UPDATE_ENGINE_UPDATE_MANAGER_NEXT_UPDATE_CHECK_POLICY_IMPL_H_
#define UPDATE_ENGINE_UPDATE_MANAGER_NEXT_UPDATE_CHECK_POLICY_IMPL_H_
#include <string>
#include <base/time/time.h>
#include "update_engine/update_manager/policy_utils.h"
#include "update_engine/update_manager/prng.h"
namespace chromeos_update_manager {
// Constants that are provided to the policy implementation.
struct NextUpdateCheckPolicyConstants {
// Default update check timeout interval/fuzz values used to compute the
// NextUpdateCheckTime(), in seconds. Actual fuzz is within +/- half of the
// indicated value.
int timeout_initial_interval;
int timeout_periodic_interval;
int timeout_max_backoff_interval;
int timeout_regular_fuzz;
// Maximum update attempt backoff interval and fuzz.
int attempt_backoff_max_interval_in_days;
int attempt_backoff_fuzz_in_hours;
};
// Ensure that periodic update checks are timed properly.
class NextUpdateCheckTimePolicyImpl : public PolicyImplBase {
public:
explicit NextUpdateCheckTimePolicyImpl(
const NextUpdateCheckPolicyConstants& constants);
// Policy overrides.
EvalStatus UpdateCheckAllowed(EvaluationContext* ec,
State* state,
std::string* error,
UpdateCheckParams* result) const override;
// A private policy implementation returning the wallclock timestamp when
// the next update check should happen.
// TODO(garnold) We should probably change that to infer a monotonic
// timestamp, which will make the update check intervals more resilient to
// clock skews. Might require switching some of the variables exported by the
// UpdaterProvider to report monotonic time, as well.
//
// NOTE:
// Exposed as a public static so that it's logic can be used to test
// Policy implementations that utilize this fragment for their
// timing, without needing to list them all with FRIEND_TEST (so that
// those Policy implementations can exist without modifying this
// class's definition.
//
// The output value from this method (|next_update_check|), isn't
// available via the UpdateCheckParams |result| of the Policy
// method, and so this timing logic needs to be otherwise exposed.
static EvalStatus NextUpdateCheckTime(
EvaluationContext* ec,
State* state,
std::string* error,
base::Time* next_update_check,
const NextUpdateCheckPolicyConstants& constants);
// Returns a TimeDelta based on the provided |interval| seconds +/- half
// |fuzz| seconds. The return value is guaranteed to be a non-negative
// TimeDelta.
static base::TimeDelta FuzzedInterval(PRNG* prng, int interval, int fuzz);
protected:
std::string PolicyName() const override {
return "NextUpdateCheckTimePolicyImpl";
}
private:
const NextUpdateCheckPolicyConstants policy_constants_;
DISALLOW_COPY_AND_ASSIGN(NextUpdateCheckTimePolicyImpl);
};
} // namespace chromeos_update_manager
#endif // UPDATE_ENGINE_UPDATE_MANAGER_NEXT_UPDATE_CHECK_POLICY_IMPL_H_