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 | |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 8 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 9 | |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 10 | #include "update_engine/policy_manager/policy.h" |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 11 | #include "update_engine/policy_manager/prng.h" |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 12 | |
| 13 | namespace chromeos_policy_manager { |
| 14 | |
| 15 | // ChromeOSPolicy implements the policy-related logic used in ChromeOS. |
| 16 | class ChromeOSPolicy : public Policy { |
| 17 | public: |
| 18 | ChromeOSPolicy() {} |
| 19 | virtual ~ChromeOSPolicy() {} |
| 20 | |
| 21 | // Policy overrides. |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 22 | virtual EvalStatus UpdateCheckAllowed( |
| 23 | EvaluationContext* ec, State* state, std::string* error, |
| 24 | UpdateCheckParams* result) const override; |
Gilad Arnold | af2f6ae | 2014-04-28 14:14:52 -0700 | [diff] [blame] | 25 | |
| 26 | virtual EvalStatus UpdateDownloadAndApplyAllowed(EvaluationContext* ec, |
| 27 | State* state, |
| 28 | std::string* error, |
| 29 | bool* result) const override; |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 30 | |
| 31 | private: |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 32 | FRIEND_TEST(PmChromeOSPolicyTest, |
| 33 | FirstCheckIsAtMostInitialIntervalAfterStart); |
| 34 | FRIEND_TEST(PmChromeOSPolicyTest, ExponentialBackoffIsCapped); |
| 35 | FRIEND_TEST(PmChromeOSPolicyTest, UpdateCheckAllowedWaitsForTheTimeout); |
| 36 | |
| 37 | // Default update check timeout interval/fuzz values used to compute the |
| 38 | // NextUpdateCheckTime(), in seconds. Actual fuzz is within +/- half of the |
| 39 | // indicated value. |
| 40 | static const int kTimeoutInitialInterval = 7 * 60; |
| 41 | static const int kTimeoutPeriodicInterval = 45 * 60; |
| 42 | static const int kTimeoutQuickInterval = 1 * 60; |
| 43 | static const int kTimeoutMaxBackoffInterval = 4 * 60 * 60; |
| 44 | static const int kTimeoutRegularFuzz = 10 * 60; |
| 45 | |
| 46 | // A private policy implementation returning the wallclock timestamp when |
| 47 | // the next update check should happen. |
| 48 | EvalStatus NextUpdateCheckTime(EvaluationContext* ec, State* state, |
| 49 | std::string* error, |
| 50 | base::Time* next_update_check) const; |
| 51 | |
| 52 | // Returns a TimeDelta based on the provided |interval| seconds +/- half |
| 53 | // |fuzz| seconds. The return value is guaranteed to be a non-negative |
| 54 | // TimeDelta. |
| 55 | static base::TimeDelta FuzzedInterval(PRNG* prng, int interval, int fuzz); |
| 56 | |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 57 | DISALLOW_COPY_AND_ASSIGN(ChromeOSPolicy); |
| 58 | }; |
| 59 | |
| 60 | } // namespace chromeos_policy_manager |
| 61 | |
Gilad Arnold | 2cbb385 | 2014-03-07 12:40:50 -0800 | [diff] [blame] | 62 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_CHROMEOS_POLICY_H_ |