PM: Policy for checking whether an update can start.
This policy is based on existing logic found in the following locations
through the current update engine code base:
- UpdateAttempter::CalculateUpdateParams(), which applies various device
policy attributes and sets the update params.
- UpdateAttempter::CalculateScatteringParams(), called by the former for
deciding the scatter wait period for the current update. Calls
UpdateAttempter::GenerateNewWaitingPeriod() to compute a new wait
period.
- OmahaRequestAction::IsWallClockBasedWaitingSatisfied() and
OmahaRequestAction::IsUpdateCheckCountBasedWaitingSatisfied, which
check whether a scattering derived wait period has elapsed and whether
a check threshold counter was satisfied, respectively.
- UpdateAttempter::CalculateP2PParams() and
P2PManagerImpl::IsP2PEnabled(), which decide whether P2P can be used.
- PayloadState::ComputeCandidateUrls(), where there's logic for deciding
whether HTTP downloads are allowed.
Note that this policy request is based on two others. One is the public
UpdateCheckAllowed(), whose positive return value invalidates the
current update attempt. The second is a private policy
UpdateScattering() that decides whether the current update attempt is
subject to scattering.
BUG=chromium:358323
TEST=Unit tests.
Change-Id: I889a3d1c10e1722585fdc1aa87fb6f9d627b60c7
Reviewed-on: https://chromium-review.googlesource.com/198781
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/policy_manager/policy.h b/policy_manager/policy.h
index 334a5bd..8ec3ace 100644
--- a/policy_manager/policy.h
+++ b/policy_manager/policy.h
@@ -27,6 +27,54 @@
bool updates_enabled; // Whether the auto-updates are enabled on this build.
};
+// Input arguments to UpdateCanStart.
+//
+// A snapshot of the state of the current update process.
+struct UpdateState {
+ // Time when update was first offered by Omaha.
+ base::Time first_seen;
+ // Number of update checks returning the current update.
+ int num_checks;
+ // Scattering wallclock-based wait period, as returned by the policy.
+ base::TimeDelta scatter_wait_period;
+ // Maximum wait period allowed for this update, as determined by Omaha.
+ base::TimeDelta scatter_wait_period_max;
+ // Scattering update check threshold, as returned by the policy.
+ int scatter_check_threshold;
+ // Minimum/maximum check threshold values.
+ // TODO(garnold) These appear to not be related to the current update and so
+ // should probably be obtained vs variables ia UpdaterProvider.
+ int scatter_check_threshold_min;
+ int scatter_check_threshold_max;
+};
+
+// Results regarding the downloading and applying of an update, as determined by
+// UpdateCanStart.
+//
+// An enumerator for the reasons of not allowing an update to start.
+enum class UpdateCannotStartReason {
+ kUndefined,
+ kCheckDue,
+ kDisabledByPolicy,
+ kScattering,
+};
+
+struct UpdateCanStartResult {
+ // Whether the update attempt is allowed to proceed.
+ bool update_can_start;
+ // Attributes pertaining to the case where update is allowed. The update
+ // engine uses them to choose the means for downloading and applying an
+ // update.
+ bool http_allowed;
+ bool p2p_allowed;
+ std::string target_channel;
+ // Attributes pertaining to the case where update is not allowed. Some are
+ // needed for storing values to persistent storage, others for
+ // logging/metrics.
+ UpdateCannotStartReason cannot_start_reason;
+ base::TimeDelta scatter_wait_period; // Needs to be persisted.
+ int scatter_check_threshold; // Needs to be persisted.
+};
// The Policy class is an interface to the ensemble of policy requests that the
// client can make. A derived class includes the policy implementations of
@@ -51,11 +99,20 @@
EvaluationContext* ec, State* state, std::string* error,
UpdateCheckParams* result) const = 0;
- // Returns whether an update can be downloaded/applied.
- virtual EvalStatus UpdateDownloadAndApplyAllowed(EvaluationContext* ec,
- State* state,
- std::string* error,
- bool* result) const = 0;
+ // Returns EvalStatus::kSucceeded if either an update can start being
+ // processed, or the attempt needs to be aborted. In cases where the update
+ // needs to wait for some condition to be satisfied, but none of the values
+ // that need to be persisted has changed, returns
+ // EvalStatus::kAskMeAgainLater. Arguments include an |interactive| flag that
+ // tells whether the update is user initiated, and an |update_state| that
+ // encapsulates data pertaining to the currnet ongoing update process.
+ virtual EvalStatus UpdateCanStart(
+ EvaluationContext* ec,
+ State* state,
+ std::string* error,
+ UpdateCanStartResult* result,
+ const bool interactive,
+ const UpdateState& update_state) const = 0;
protected:
Policy() {}