blob: 09d937edca2f2c19e50f6502651ae5dff399b325 [file] [log] [blame]
Alex Deymoc705cc82014-02-19 11:15:00 -08001// 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 Arnold2cbb3852014-03-07 12:40:50 -08005#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_CHROMEOS_POLICY_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_CHROMEOS_POLICY_H_
Alex Deymoc705cc82014-02-19 11:15:00 -08007
Alex Deymo0d11c602014-04-23 20:12:20 -07008#include <gtest/gtest_prod.h> // for FRIEND_TEST
9
Alex Deymoc705cc82014-02-19 11:15:00 -080010#include "update_engine/policy_manager/policy.h"
Alex Deymo0d11c602014-04-23 20:12:20 -070011#include "update_engine/policy_manager/prng.h"
Alex Deymoc705cc82014-02-19 11:15:00 -080012
13namespace chromeos_policy_manager {
14
15// ChromeOSPolicy implements the policy-related logic used in ChromeOS.
16class ChromeOSPolicy : public Policy {
17 public:
18 ChromeOSPolicy() {}
19 virtual ~ChromeOSPolicy() {}
20
21 // Policy overrides.
Alex Deymo0d11c602014-04-23 20:12:20 -070022 virtual EvalStatus UpdateCheckAllowed(
23 EvaluationContext* ec, State* state, std::string* error,
24 UpdateCheckParams* result) const override;
Gilad Arnoldaf2f6ae2014-04-28 14:14:52 -070025
26 virtual EvalStatus UpdateDownloadAndApplyAllowed(EvaluationContext* ec,
27 State* state,
28 std::string* error,
29 bool* result) const override;
Alex Deymoc705cc82014-02-19 11:15:00 -080030
31 private:
Alex Deymo0d11c602014-04-23 20:12:20 -070032 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 Deymoc705cc82014-02-19 11:15:00 -080057 DISALLOW_COPY_AND_ASSIGN(ChromeOSPolicy);
58};
59
60} // namespace chromeos_policy_manager
61
Gilad Arnold2cbb3852014-03-07 12:40:50 -080062#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_CHROMEOS_POLICY_H_