UpdateManager: Move logic from UpdateCanStart to UpdateCheckAllowed.
The following should be part of the policy that is consulted before
performing an update check:
1) Whether updates are disabled by device policy.
2) Whether a specific target channel is dictated by the device policy.
This CL moves it from UpdateCanStart into UpdateCheckAllowed.
Another change is renaming the output construct of UpdateCanStart into
'UpdateDownloadParams'; this is in line with the naming of the output
struct of UpdateCheckAllowed, and reflects the fact that it contains
information regarding the download of an update, to be used by the
caller.
BUG=chromium:388386
TEST=Unit tests.
Change-Id: I0631a4464800db77807d7da9a2a2c256b519c5c3
Reviewed-on: https://chromium-review.googlesource.com/205728
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
diff --git a/update_manager/chromeos_policy.cc b/update_manager/chromeos_policy.cc
index e2de820..5273ea4 100644
--- a/update_manager/chromeos_policy.cc
+++ b/update_manager/chromeos_policy.cc
@@ -152,17 +152,44 @@
EvalStatus ChromeOSPolicy::UpdateCheckAllowed(
EvaluationContext* ec, State* state, string* error,
UpdateCheckParams* result) const {
+ // Set the default return values.
+ result->updates_enabled = true;
+ result->target_channel.clear();
+
+ DevicePolicyProvider* const dp_provider = state->device_policy_provider();
+
+ const bool* device_policy_is_loaded_p = ec->GetValue(
+ dp_provider->var_device_policy_is_loaded());
+ if (device_policy_is_loaded_p && *device_policy_is_loaded_p) {
+ // Check whether updates are disabled by policy.
+ const bool* update_disabled_p = ec->GetValue(
+ dp_provider->var_update_disabled());
+ if (update_disabled_p && *update_disabled_p) {
+ result->updates_enabled = false;
+ return EvalStatus::kAskMeAgainLater;
+ }
+
+ // Determine whether a target channel is dictated by policy.
+ const bool* release_channel_delegated_p = ec->GetValue(
+ dp_provider->var_release_channel_delegated());
+ if (release_channel_delegated_p && !(*release_channel_delegated_p)) {
+ const string* release_channel_p = ec->GetValue(
+ dp_provider->var_release_channel());
+ if (release_channel_p)
+ result->target_channel = *release_channel_p;
+ }
+ }
+
+ // Ensure that update checks are timed properly.
Time next_update_check;
if (NextUpdateCheckTime(ec, state, error, &next_update_check) !=
EvalStatus::kSucceeded) {
return EvalStatus::kFailed;
}
-
if (!ec->IsTimeGreaterThan(next_update_check))
return EvalStatus::kAskMeAgainLater;
// It is time to check for an update.
- result->updates_enabled = true;
return EvalStatus::kSucceeded;
}
@@ -170,13 +197,12 @@
EvaluationContext* ec,
State* state,
string* error,
- UpdateCanStartResult* result,
+ UpdateDownloadParams* result,
const bool interactive,
const UpdateState& update_state) const {
// Set the default return values.
result->update_can_start = true;
result->p2p_allowed = false;
- result->target_channel.clear();
result->cannot_start_reason = UpdateCannotStartReason::kUndefined;
result->scatter_wait_period = kZeroInterval;
result->scatter_check_threshold = 0;
@@ -200,15 +226,6 @@
const bool* device_policy_is_loaded_p = ec->GetValue(
dp_provider->var_device_policy_is_loaded());
if (device_policy_is_loaded_p && *device_policy_is_loaded_p) {
- // Ensure that update is enabled.
- const bool* update_disabled_p = ec->GetValue(
- dp_provider->var_update_disabled());
- if (update_disabled_p && *update_disabled_p) {
- result->update_can_start = false;
- result->cannot_start_reason = UpdateCannotStartReason::kDisabledByPolicy;
- return EvalStatus::kAskMeAgainLater;
- }
-
// Check whether scattering applies to this update attempt. We should not be
// scattering if this is an interactive update check, or if OOBE is enabled
// but not completed.
@@ -251,16 +268,6 @@
const bool* policy_au_p2p_enabled_p = ec->GetValue(
dp_provider->var_au_p2p_enabled());
result->p2p_allowed = policy_au_p2p_enabled_p && *policy_au_p2p_enabled_p;
-
- // Determine whether a target channel is dictated by policy.
- const bool* release_channel_delegated_p = ec->GetValue(
- dp_provider->var_release_channel_delegated());
- if (release_channel_delegated_p && !(*release_channel_delegated_p)) {
- const string* release_channel_p = ec->GetValue(
- dp_provider->var_release_channel());
- if (release_channel_p)
- result->target_channel = *release_channel_p;
- }
}
// Enable P2P, if so mandated by the updater configuration.