Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 1 | // Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame^] | 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_MANAGER_CHROMEOS_POLICY_H_ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_MANAGER_CHROMEOS_POLICY_H_ |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 7 | |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 8 | #include <base/time/time.h> |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 9 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 10 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame^] | 11 | #include "update_engine/update_manager/policy.h" |
| 12 | #include "update_engine/update_manager/prng.h" |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 13 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame^] | 14 | namespace chromeos_update_manager { |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 15 | |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 16 | // Parameters for update scattering, as determined by UpdateNotScattering. |
| 17 | struct UpdateScatteringResult { |
| 18 | bool is_scattering; |
| 19 | base::TimeDelta wait_period; |
| 20 | int check_threshold; |
| 21 | }; |
| 22 | |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 23 | // ChromeOSPolicy implements the policy-related logic used in ChromeOS. |
| 24 | class ChromeOSPolicy : public Policy { |
| 25 | public: |
| 26 | ChromeOSPolicy() {} |
| 27 | virtual ~ChromeOSPolicy() {} |
| 28 | |
| 29 | // Policy overrides. |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 30 | virtual EvalStatus UpdateCheckAllowed( |
| 31 | EvaluationContext* ec, State* state, std::string* error, |
| 32 | UpdateCheckParams* result) const override; |
Gilad Arnold | af2f6ae | 2014-04-28 14:14:52 -0700 | [diff] [blame] | 33 | |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 34 | virtual EvalStatus UpdateCanStart( |
| 35 | EvaluationContext* ec, |
| 36 | State* state, |
| 37 | std::string* error, |
| 38 | UpdateCanStartResult* result, |
| 39 | const bool interactive, |
| 40 | const UpdateState& update_state) const override; |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 41 | |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 42 | virtual EvalStatus UpdateCurrentConnectionAllowed( |
| 43 | EvaluationContext* ec, |
| 44 | State* state, |
| 45 | std::string* error, |
| 46 | bool* result) const override; |
| 47 | |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 48 | private: |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame^] | 49 | friend class UmChromeOSPolicyTest; |
| 50 | FRIEND_TEST(UmChromeOSPolicyTest, |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 51 | FirstCheckIsAtMostInitialIntervalAfterStart); |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame^] | 52 | FRIEND_TEST(UmChromeOSPolicyTest, ExponentialBackoffIsCapped); |
| 53 | FRIEND_TEST(UmChromeOSPolicyTest, UpdateCheckAllowedWaitsForTheTimeout); |
| 54 | FRIEND_TEST(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 55 | UpdateCanStartNotAllowedScatteringNewWaitPeriodApplies); |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame^] | 56 | FRIEND_TEST(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 57 | UpdateCanStartNotAllowedScatteringPrevWaitPeriodStillApplies); |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame^] | 58 | FRIEND_TEST(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 59 | UpdateCanStartNotAllowedScatteringNewCountThresholdApplies); |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame^] | 60 | FRIEND_TEST(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 61 | UpdateCanStartNotAllowedScatteringPrevCountThresholdStillApplies); |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame^] | 62 | FRIEND_TEST(UmChromeOSPolicyTest, UpdateCanStartAllowedScatteringSatisfied); |
| 63 | FRIEND_TEST(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 64 | UpdateCanStartAllowedInteractivePreventsScattering); |
| 65 | |
| 66 | // Auxiliary constant (zero by default). |
| 67 | const base::TimeDelta kZeroInterval; |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 68 | |
| 69 | // Default update check timeout interval/fuzz values used to compute the |
| 70 | // NextUpdateCheckTime(), in seconds. Actual fuzz is within +/- half of the |
| 71 | // indicated value. |
| 72 | static const int kTimeoutInitialInterval = 7 * 60; |
| 73 | static const int kTimeoutPeriodicInterval = 45 * 60; |
| 74 | static const int kTimeoutQuickInterval = 1 * 60; |
| 75 | static const int kTimeoutMaxBackoffInterval = 4 * 60 * 60; |
| 76 | static const int kTimeoutRegularFuzz = 10 * 60; |
| 77 | |
| 78 | // A private policy implementation returning the wallclock timestamp when |
| 79 | // the next update check should happen. |
| 80 | EvalStatus NextUpdateCheckTime(EvaluationContext* ec, State* state, |
| 81 | std::string* error, |
| 82 | base::Time* next_update_check) const; |
| 83 | |
| 84 | // Returns a TimeDelta based on the provided |interval| seconds +/- half |
| 85 | // |fuzz| seconds. The return value is guaranteed to be a non-negative |
| 86 | // TimeDelta. |
| 87 | static base::TimeDelta FuzzedInterval(PRNG* prng, int interval, int fuzz); |
| 88 | |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 89 | // A private policy for checking whether scattering is due. Writes in |result| |
| 90 | // the decision as to whether or not to scatter; a wallclock-based scatter |
| 91 | // wait period, which ranges from zero (do not wait) and no greater than the |
| 92 | // current scatter factor provided by the device policy (if available) or the |
| 93 | // maximum wait period determined by Omaha; and an update check-based |
| 94 | // threshold between zero (no threshold) and the maximum number determined by |
| 95 | // the update engine. Within |update_state|, |wait_period| should contain the |
| 96 | // last scattering period returned by this function, or zero if no wait period |
| 97 | // is known; |check_threshold| is the last update check threshold, or zero if |
| 98 | // no such threshold is known. If not scattering, or if any of the scattering |
| 99 | // values has changed, returns |EvalStatus::kSucceeded|; otherwise, |
| 100 | // |EvalStatus::kAskMeAgainLater|. |
| 101 | EvalStatus UpdateScattering(EvaluationContext* ec, State* state, |
| 102 | std::string* error, |
| 103 | UpdateScatteringResult* result, |
| 104 | const UpdateState& update_state) const; |
| 105 | |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 106 | DISALLOW_COPY_AND_ASSIGN(ChromeOSPolicy); |
| 107 | }; |
| 108 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame^] | 109 | } // namespace chromeos_update_manager |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 110 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame^] | 111 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_MANAGER_CHROMEOS_POLICY_H_ |