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 | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame^] | 16 | // Parameters for update download URL, as determined by UpdateDownloadUrl. |
| 17 | struct UpdateDownloadUrlResult { |
| 18 | int url_idx; |
| 19 | int url_num_failures; |
| 20 | }; |
| 21 | |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 22 | // Parameters for update scattering, as determined by UpdateNotScattering. |
| 23 | struct UpdateScatteringResult { |
| 24 | bool is_scattering; |
| 25 | base::TimeDelta wait_period; |
| 26 | int check_threshold; |
| 27 | }; |
| 28 | |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 29 | // ChromeOSPolicy implements the policy-related logic used in ChromeOS. |
| 30 | class ChromeOSPolicy : public Policy { |
| 31 | public: |
| 32 | ChromeOSPolicy() {} |
| 33 | virtual ~ChromeOSPolicy() {} |
| 34 | |
| 35 | // Policy overrides. |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 36 | virtual EvalStatus UpdateCheckAllowed( |
| 37 | EvaluationContext* ec, State* state, std::string* error, |
| 38 | UpdateCheckParams* result) const override; |
Gilad Arnold | af2f6ae | 2014-04-28 14:14:52 -0700 | [diff] [blame] | 39 | |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 40 | virtual EvalStatus UpdateCanStart( |
| 41 | EvaluationContext* ec, |
| 42 | State* state, |
| 43 | std::string* error, |
| 44 | UpdateCanStartResult* result, |
| 45 | const bool interactive, |
| 46 | const UpdateState& update_state) const override; |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 47 | |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 48 | virtual EvalStatus UpdateCurrentConnectionAllowed( |
| 49 | EvaluationContext* ec, |
| 50 | State* state, |
| 51 | std::string* error, |
| 52 | bool* result) const override; |
| 53 | |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame^] | 54 | protected: |
| 55 | // Policy override. |
| 56 | virtual std::string PolicyName() const override { |
| 57 | return "ChromeOSPolicy"; |
| 58 | } |
| 59 | |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 60 | private: |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 61 | friend class UmChromeOSPolicyTest; |
| 62 | FRIEND_TEST(UmChromeOSPolicyTest, |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 63 | FirstCheckIsAtMostInitialIntervalAfterStart); |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 64 | FRIEND_TEST(UmChromeOSPolicyTest, ExponentialBackoffIsCapped); |
| 65 | FRIEND_TEST(UmChromeOSPolicyTest, UpdateCheckAllowedWaitsForTheTimeout); |
| 66 | FRIEND_TEST(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 67 | UpdateCanStartNotAllowedScatteringNewWaitPeriodApplies); |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 68 | FRIEND_TEST(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 69 | UpdateCanStartNotAllowedScatteringPrevWaitPeriodStillApplies); |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 70 | FRIEND_TEST(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 71 | UpdateCanStartNotAllowedScatteringNewCountThresholdApplies); |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 72 | FRIEND_TEST(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 73 | UpdateCanStartNotAllowedScatteringPrevCountThresholdStillApplies); |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 74 | FRIEND_TEST(UmChromeOSPolicyTest, UpdateCanStartAllowedScatteringSatisfied); |
| 75 | FRIEND_TEST(UmChromeOSPolicyTest, |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 76 | UpdateCanStartAllowedInteractivePreventsScattering); |
| 77 | |
| 78 | // Auxiliary constant (zero by default). |
| 79 | const base::TimeDelta kZeroInterval; |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 80 | |
| 81 | // Default update check timeout interval/fuzz values used to compute the |
| 82 | // NextUpdateCheckTime(), in seconds. Actual fuzz is within +/- half of the |
| 83 | // indicated value. |
| 84 | static const int kTimeoutInitialInterval = 7 * 60; |
| 85 | static const int kTimeoutPeriodicInterval = 45 * 60; |
| 86 | static const int kTimeoutQuickInterval = 1 * 60; |
| 87 | static const int kTimeoutMaxBackoffInterval = 4 * 60 * 60; |
| 88 | static const int kTimeoutRegularFuzz = 10 * 60; |
| 89 | |
| 90 | // A private policy implementation returning the wallclock timestamp when |
| 91 | // the next update check should happen. |
| 92 | EvalStatus NextUpdateCheckTime(EvaluationContext* ec, State* state, |
| 93 | std::string* error, |
| 94 | base::Time* next_update_check) const; |
| 95 | |
| 96 | // Returns a TimeDelta based on the provided |interval| seconds +/- half |
| 97 | // |fuzz| seconds. The return value is guaranteed to be a non-negative |
| 98 | // TimeDelta. |
| 99 | static base::TimeDelta FuzzedInterval(PRNG* prng, int interval, int fuzz); |
| 100 | |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame^] | 101 | // A private policy for determining which download URL to use. Within |
| 102 | // |update_state|, |download_urls| should contain the download URLs as listed |
| 103 | // in the Omaha response; |download_failures_max| the maximum number of |
| 104 | // failures per URL allowed per the response; |download_url_idx| the index of |
| 105 | // the previously used URL; |download_url_num_failures| the previously known |
| 106 | // number of failures associated with that URL; and |download_url_error_codes| |
| 107 | // the list of failures occurring since the latest evaluation. |
| 108 | // |
| 109 | // Upon successly deciding a URL to use, returns |EvalStatus::kSucceeded| and |
| 110 | // writes the current URL index and the number of failures associated with it |
| 111 | // in |result|. Otherwise, returns |EvalStatus::kFailed|. |
| 112 | EvalStatus UpdateDownloadUrl(EvaluationContext* ec, State* state, |
| 113 | std::string* error, |
| 114 | UpdateDownloadUrlResult* result, |
| 115 | const UpdateState& update_state) const; |
| 116 | |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 117 | // A private policy for checking whether scattering is due. Writes in |result| |
| 118 | // the decision as to whether or not to scatter; a wallclock-based scatter |
| 119 | // wait period, which ranges from zero (do not wait) and no greater than the |
| 120 | // current scatter factor provided by the device policy (if available) or the |
| 121 | // maximum wait period determined by Omaha; and an update check-based |
| 122 | // threshold between zero (no threshold) and the maximum number determined by |
Gilad Arnold | b3b0544 | 2014-05-30 14:25:05 -0700 | [diff] [blame^] | 123 | // the update engine. Within |update_state|, |scatter_wait_period| should |
| 124 | // contain the last scattering period returned by this function, or zero if no |
| 125 | // wait period is known; |scatter_check_threshold| is the last update check |
| 126 | // threshold, or zero if no such threshold is known. If not scattering, or if |
| 127 | // any of the scattering values has changed, returns |EvalStatus::kSucceeded|; |
| 128 | // otherwise, |EvalStatus::kAskMeAgainLater|. |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 129 | EvalStatus UpdateScattering(EvaluationContext* ec, State* state, |
| 130 | std::string* error, |
| 131 | UpdateScatteringResult* result, |
| 132 | const UpdateState& update_state) const; |
| 133 | |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 134 | DISALLOW_COPY_AND_ASSIGN(ChromeOSPolicy); |
| 135 | }; |
| 136 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 137 | } // namespace chromeos_update_manager |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 138 | |
Alex Deymo | 63784a5 | 2014-05-28 10:46:14 -0700 | [diff] [blame] | 139 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_MANAGER_CHROMEOS_POLICY_H_ |