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_POLICY_H_ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_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 <string> |
| 9 | |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 10 | #include "update_engine/policy_manager/evaluation_context.h" |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 11 | #include "update_engine/policy_manager/state.h" |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 12 | |
| 13 | namespace chromeos_policy_manager { |
| 14 | |
| 15 | // The three different results of a policy request. |
Alex Deymo | e636c3c | 2014-03-11 19:02:08 -0700 | [diff] [blame] | 16 | enum class EvalStatus { |
| 17 | kFailed, |
| 18 | kSucceeded, |
| 19 | kAskMeAgainLater, |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 20 | }; |
| 21 | |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 22 | std::string ToString(EvalStatus status); |
| 23 | |
| 24 | // Parameters of an update check. These parameters are determined by the |
| 25 | // UpdateCheckAllowed policy. |
| 26 | struct UpdateCheckParams { |
| 27 | bool updates_enabled; // Whether the auto-updates are enabled on this build. |
| 28 | }; |
| 29 | |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 30 | // Input arguments to UpdateCanStart. |
| 31 | // |
| 32 | // A snapshot of the state of the current update process. |
| 33 | struct UpdateState { |
| 34 | // Time when update was first offered by Omaha. |
| 35 | base::Time first_seen; |
| 36 | // Number of update checks returning the current update. |
| 37 | int num_checks; |
| 38 | // Scattering wallclock-based wait period, as returned by the policy. |
| 39 | base::TimeDelta scatter_wait_period; |
| 40 | // Maximum wait period allowed for this update, as determined by Omaha. |
| 41 | base::TimeDelta scatter_wait_period_max; |
| 42 | // Scattering update check threshold, as returned by the policy. |
| 43 | int scatter_check_threshold; |
| 44 | // Minimum/maximum check threshold values. |
| 45 | // TODO(garnold) These appear to not be related to the current update and so |
Gilad Arnold | ddd3fe3 | 2014-05-22 12:57:09 -0700 | [diff] [blame^] | 46 | // should probably be obtained as variables via UpdaterProvider. |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 47 | int scatter_check_threshold_min; |
| 48 | int scatter_check_threshold_max; |
| 49 | }; |
| 50 | |
| 51 | // Results regarding the downloading and applying of an update, as determined by |
| 52 | // UpdateCanStart. |
| 53 | // |
| 54 | // An enumerator for the reasons of not allowing an update to start. |
| 55 | enum class UpdateCannotStartReason { |
| 56 | kUndefined, |
| 57 | kCheckDue, |
| 58 | kDisabledByPolicy, |
| 59 | kScattering, |
| 60 | }; |
| 61 | |
| 62 | struct UpdateCanStartResult { |
| 63 | // Whether the update attempt is allowed to proceed. |
| 64 | bool update_can_start; |
| 65 | // Attributes pertaining to the case where update is allowed. The update |
| 66 | // engine uses them to choose the means for downloading and applying an |
| 67 | // update. |
| 68 | bool http_allowed; |
| 69 | bool p2p_allowed; |
| 70 | std::string target_channel; |
| 71 | // Attributes pertaining to the case where update is not allowed. Some are |
| 72 | // needed for storing values to persistent storage, others for |
| 73 | // logging/metrics. |
| 74 | UpdateCannotStartReason cannot_start_reason; |
| 75 | base::TimeDelta scatter_wait_period; // Needs to be persisted. |
| 76 | int scatter_check_threshold; // Needs to be persisted. |
| 77 | }; |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 78 | |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 79 | // The Policy class is an interface to the ensemble of policy requests that the |
| 80 | // client can make. A derived class includes the policy implementations of |
| 81 | // these. |
| 82 | // |
| 83 | // When compile-time selection of the policy is required due to missing or extra |
| 84 | // parts in a given platform, a different Policy subclass can be used. |
| 85 | class Policy { |
| 86 | public: |
| 87 | virtual ~Policy() {} |
| 88 | |
| 89 | // List of policy requests. A policy request takes an EvaluationContext as the |
Alex Deymo | 2de23f5 | 2014-02-26 14:30:13 -0800 | [diff] [blame] | 90 | // first argument, a State instance, a returned error message, a returned |
| 91 | // value and optionally followed by one or more arbitrary constant arguments. |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 92 | // |
Alex Deymo | e636c3c | 2014-03-11 19:02:08 -0700 | [diff] [blame] | 93 | // When the implementation fails, the method returns EvalStatus::kFailed and |
| 94 | // sets the |error| string. |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 95 | |
| 96 | // UpdateCheckAllowed returns whether it is allowed to request an update check |
| 97 | // to Omaha. |
Alex Deymo | 0d11c60 | 2014-04-23 20:12:20 -0700 | [diff] [blame] | 98 | virtual EvalStatus UpdateCheckAllowed( |
| 99 | EvaluationContext* ec, State* state, std::string* error, |
| 100 | UpdateCheckParams* result) const = 0; |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 101 | |
Gilad Arnold | f62a4b8 | 2014-05-01 07:41:07 -0700 | [diff] [blame] | 102 | // Returns EvalStatus::kSucceeded if either an update can start being |
| 103 | // processed, or the attempt needs to be aborted. In cases where the update |
| 104 | // needs to wait for some condition to be satisfied, but none of the values |
| 105 | // that need to be persisted has changed, returns |
| 106 | // EvalStatus::kAskMeAgainLater. Arguments include an |interactive| flag that |
| 107 | // tells whether the update is user initiated, and an |update_state| that |
| 108 | // encapsulates data pertaining to the currnet ongoing update process. |
| 109 | virtual EvalStatus UpdateCanStart( |
| 110 | EvaluationContext* ec, |
| 111 | State* state, |
| 112 | std::string* error, |
| 113 | UpdateCanStartResult* result, |
| 114 | const bool interactive, |
| 115 | const UpdateState& update_state) const = 0; |
Gilad Arnold | af2f6ae | 2014-04-28 14:14:52 -0700 | [diff] [blame] | 116 | |
Gilad Arnold | 0adbc94 | 2014-05-12 10:35:43 -0700 | [diff] [blame] | 117 | // Checks whether updating is allowed over the current network connection |
| 118 | // Consults the shill provider as well as the device policy (if available). |
| 119 | // Returns |EvalStatus::kSucceeded|, setting |result| according to whether or |
| 120 | // not the current connection can be used; on failure, returns |
| 121 | // |EvalStatus::kFailed| and sets |error| accordingly. |
| 122 | virtual EvalStatus UpdateCurrentConnectionAllowed( |
| 123 | EvaluationContext* ec, |
| 124 | State* state, |
| 125 | std::string* error, |
| 126 | bool* result) const = 0; |
| 127 | |
Alex Deymo | c705cc8 | 2014-02-19 11:15:00 -0800 | [diff] [blame] | 128 | protected: |
| 129 | Policy() {} |
| 130 | |
| 131 | private: |
| 132 | DISALLOW_COPY_AND_ASSIGN(Policy); |
| 133 | }; |
| 134 | |
| 135 | } // namespace chromeos_policy_manager |
| 136 | |
Gilad Arnold | 2cbb385 | 2014-03-07 12:40:50 -0800 | [diff] [blame] | 137 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_POLICY_MANAGER_POLICY_H_ |