blob: 65f236c1b1deec19723453fbec8797102b99b717 [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
Alex Deymo63784a52014-05-28 10:46:14 -07005#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_MANAGER_POLICY_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_MANAGER_POLICY_H_
Alex Deymoc705cc82014-02-19 11:15:00 -08007
Alex Deymo0d11c602014-04-23 20:12:20 -07008#include <string>
9
Alex Deymo63784a52014-05-28 10:46:14 -070010#include "update_engine/update_manager/evaluation_context.h"
11#include "update_engine/update_manager/state.h"
Alex Deymoc705cc82014-02-19 11:15:00 -080012
Alex Deymo63784a52014-05-28 10:46:14 -070013namespace chromeos_update_manager {
Alex Deymoc705cc82014-02-19 11:15:00 -080014
15// The three different results of a policy request.
Alex Deymoe636c3c2014-03-11 19:02:08 -070016enum class EvalStatus {
17 kFailed,
18 kSucceeded,
19 kAskMeAgainLater,
Alex Deymoc705cc82014-02-19 11:15:00 -080020};
21
Alex Deymo0d11c602014-04-23 20:12:20 -070022std::string ToString(EvalStatus status);
23
24// Parameters of an update check. These parameters are determined by the
25// UpdateCheckAllowed policy.
26struct UpdateCheckParams {
27 bool updates_enabled; // Whether the auto-updates are enabled on this build.
28};
29
Gilad Arnoldf62a4b82014-05-01 07:41:07 -070030// Input arguments to UpdateCanStart.
31//
32// A snapshot of the state of the current update process.
33struct 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 Arnoldddd3fe32014-05-22 12:57:09 -070046 // should probably be obtained as variables via UpdaterProvider.
Gilad Arnoldf62a4b82014-05-01 07:41:07 -070047 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.
55enum class UpdateCannotStartReason {
56 kUndefined,
57 kCheckDue,
58 kDisabledByPolicy,
59 kScattering,
60};
61
62struct 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 Deymo0d11c602014-04-23 20:12:20 -070078
Alex Deymoc705cc82014-02-19 11:15:00 -080079// 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.
85class Policy {
86 public:
87 virtual ~Policy() {}
88
89 // List of policy requests. A policy request takes an EvaluationContext as the
Alex Deymo2de23f52014-02-26 14:30:13 -080090 // first argument, a State instance, a returned error message, a returned
91 // value and optionally followed by one or more arbitrary constant arguments.
Alex Deymoc705cc82014-02-19 11:15:00 -080092 //
Alex Deymoe636c3c2014-03-11 19:02:08 -070093 // When the implementation fails, the method returns EvalStatus::kFailed and
94 // sets the |error| string.
Alex Deymoc705cc82014-02-19 11:15:00 -080095
96 // UpdateCheckAllowed returns whether it is allowed to request an update check
97 // to Omaha.
Alex Deymo0d11c602014-04-23 20:12:20 -070098 virtual EvalStatus UpdateCheckAllowed(
99 EvaluationContext* ec, State* state, std::string* error,
100 UpdateCheckParams* result) const = 0;
Alex Deymoc705cc82014-02-19 11:15:00 -0800101
Gilad Arnoldf62a4b82014-05-01 07:41:07 -0700102 // 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 Arnoldaf2f6ae2014-04-28 14:14:52 -0700116
Gilad Arnold0adbc942014-05-12 10:35:43 -0700117 // 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 Deymoc705cc82014-02-19 11:15:00 -0800128 protected:
129 Policy() {}
130
131 private:
132 DISALLOW_COPY_AND_ASSIGN(Policy);
133};
134
Alex Deymo63784a52014-05-28 10:46:14 -0700135} // namespace chromeos_update_manager
Alex Deymoc705cc82014-02-19 11:15:00 -0800136
Alex Deymo63784a52014-05-28 10:46:14 -0700137#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_UPDATE_MANAGER_POLICY_H_