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 | |
Gilad Arnold | 2cbb385 | 2014-03-07 12:40:50 -0800 | [diff] [blame] | 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_CHROMEOS_POLICY_H_ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_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 | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 11 | #include "update_engine/policy_manager/policy.h" |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 12 | #include "update_engine/policy_manager/prng.h" |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 13 | |
| 14 | namespace chromeos_policy_manager { |
| 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 | |
| 42 | private: |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame^] | 43 | friend class PmChromeOSPolicyTest; |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 44 | FRIEND_TEST(PmChromeOSPolicyTest, |
| 45 | FirstCheckIsAtMostInitialIntervalAfterStart); |
| 46 | FRIEND_TEST(PmChromeOSPolicyTest, ExponentialBackoffIsCapped); |
| 47 | FRIEND_TEST(PmChromeOSPolicyTest, UpdateCheckAllowedWaitsForTheTimeout); |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame^] | 48 | FRIEND_TEST(PmChromeOSPolicyTest, |
| 49 | UpdateCanStartNotAllowedScatteringNewWaitPeriodApplies); |
| 50 | FRIEND_TEST(PmChromeOSPolicyTest, |
| 51 | UpdateCanStartNotAllowedScatteringPrevWaitPeriodStillApplies); |
| 52 | FRIEND_TEST(PmChromeOSPolicyTest, |
| 53 | UpdateCanStartNotAllowedScatteringNewCountThresholdApplies); |
| 54 | FRIEND_TEST(PmChromeOSPolicyTest, |
| 55 | UpdateCanStartNotAllowedScatteringPrevCountThresholdStillApplies); |
| 56 | FRIEND_TEST(PmChromeOSPolicyTest, UpdateCanStartAllowedScatteringSatisfied); |
| 57 | FRIEND_TEST(PmChromeOSPolicyTest, |
| 58 | UpdateCanStartAllowedInteractivePreventsScattering); |
| 59 | |
| 60 | // Auxiliary constant (zero by default). |
| 61 | const base::TimeDelta kZeroInterval; |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 62 | |
| 63 | // Default update check timeout interval/fuzz values used to compute the |
| 64 | // NextUpdateCheckTime(), in seconds. Actual fuzz is within +/- half of the |
| 65 | // indicated value. |
| 66 | static const int kTimeoutInitialInterval = 7 * 60; |
| 67 | static const int kTimeoutPeriodicInterval = 45 * 60; |
| 68 | static const int kTimeoutQuickInterval = 1 * 60; |
| 69 | static const int kTimeoutMaxBackoffInterval = 4 * 60 * 60; |
| 70 | static const int kTimeoutRegularFuzz = 10 * 60; |
| 71 | |
| 72 | // A private policy implementation returning the wallclock timestamp when |
| 73 | // the next update check should happen. |
| 74 | EvalStatus NextUpdateCheckTime(EvaluationContext* ec, State* state, |
| 75 | std::string* error, |
| 76 | base::Time* next_update_check) const; |
| 77 | |
| 78 | // Returns a TimeDelta based on the provided |interval| seconds +/- half |
| 79 | // |fuzz| seconds. The return value is guaranteed to be a non-negative |
| 80 | // TimeDelta. |
| 81 | static base::TimeDelta FuzzedInterval(PRNG* prng, int interval, int fuzz); |
| 82 | |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame^] | 83 | // A private policy for checking whether scattering is due. Writes in |result| |
| 84 | // the decision as to whether or not to scatter; a wallclock-based scatter |
| 85 | // wait period, which ranges from zero (do not wait) and no greater than the |
| 86 | // current scatter factor provided by the device policy (if available) or the |
| 87 | // maximum wait period determined by Omaha; and an update check-based |
| 88 | // threshold between zero (no threshold) and the maximum number determined by |
| 89 | // the update engine. Within |update_state|, |wait_period| should contain the |
| 90 | // last scattering period returned by this function, or zero if no wait period |
| 91 | // is known; |check_threshold| is the last update check threshold, or zero if |
| 92 | // no such threshold is known. If not scattering, or if any of the scattering |
| 93 | // values has changed, returns |EvalStatus::kSucceeded|; otherwise, |
| 94 | // |EvalStatus::kAskMeAgainLater|. |
| 95 | EvalStatus UpdateScattering(EvaluationContext* ec, State* state, |
| 96 | std::string* error, |
| 97 | UpdateScatteringResult* result, |
| 98 | const UpdateState& update_state) const; |
| 99 | |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 100 | DISALLOW_COPY_AND_ASSIGN(ChromeOSPolicy); |
| 101 | }; |
| 102 | |
| 103 | } // namespace chromeos_policy_manager |
| 104 | |
Gilad Arnold | 2cbb385 | 2014-03-07 12:40:50 -0800 | [diff] [blame] | 105 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_CHROMEOS_POLICY_H_ |