update_engine: UM: UpdateCheckAllowed returns target version prefix.
This piece of information is also provided by the device policy and
needed when performing the update check. Borrows logic currently in
UpdateAttempter::CalculateUpdateParams().
BUG=chromium:358269
TEST=Unit tests.
Change-Id: I5259404df1763be8944b445d51e1fafbca946306
Reviewed-on: https://chromium-review.googlesource.com/209228
Reviewed-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/update_manager/chromeos_policy.cc b/update_manager/chromeos_policy.cc
index 7032074..af1d8ac 100644
--- a/update_manager/chromeos_policy.cc
+++ b/update_manager/chromeos_policy.cc
@@ -155,6 +155,7 @@
// Set the default return values.
result->updates_enabled = true;
result->target_channel.clear();
+ result->target_version_prefix.clear();
result->is_interactive = false;
DevicePolicyProvider* const dp_provider = state->device_policy_provider();
@@ -179,6 +180,12 @@
if (update_disabled_p && *update_disabled_p)
return EvalStatus::kAskMeAgainLater;
+ // Determine whether a target version prefix is dictated by policy.
+ const string* target_version_prefix_p = ec->GetValue(
+ dp_provider->var_target_version_prefix());
+ if (target_version_prefix_p)
+ result->target_version_prefix = *target_version_prefix_p;
+
// Determine whether a target channel is dictated by policy.
const bool* release_channel_delegated_p = ec->GetValue(
dp_provider->var_release_channel_delegated());
diff --git a/update_manager/chromeos_policy_unittest.cc b/update_manager/chromeos_policy_unittest.cc
index f79c4fc..d231a7c 100644
--- a/update_manager/chromeos_policy_unittest.cc
+++ b/update_manager/chromeos_policy_unittest.cc
@@ -338,6 +338,8 @@
SetUpdateCheckAllowed(true);
// Override specific device policy attributes.
+ fake_state_.device_policy_provider()->var_target_version_prefix()->
+ reset(new string("1.2"));
fake_state_.device_policy_provider()->var_release_channel_delegated()->
reset(new bool(false));
fake_state_.device_policy_provider()->var_release_channel()->
@@ -347,6 +349,7 @@
ExpectPolicyStatus(EvalStatus::kSucceeded,
&Policy::UpdateCheckAllowed, &result);
EXPECT_TRUE(result.updates_enabled);
+ EXPECT_EQ("1.2", result.target_version_prefix);
EXPECT_EQ("foo-channel", result.target_channel);
EXPECT_FALSE(result.is_interactive);
}
diff --git a/update_manager/default_policy.cc b/update_manager/default_policy.cc
index 91b1bba..98c2786 100644
--- a/update_manager/default_policy.cc
+++ b/update_manager/default_policy.cc
@@ -24,6 +24,7 @@
UpdateCheckParams* result) const {
result->updates_enabled = true;
result->target_channel.clear();
+ result->target_version_prefix.clear();
result->is_interactive = false;
// Ensure that the minimum interval is set. If there's no clock, this defaults
diff --git a/update_manager/policy.h b/update_manager/policy.h
index 9a7d620..8ec5c9e 100644
--- a/update_manager/policy.h
+++ b/update_manager/policy.h
@@ -30,6 +30,8 @@
// Attributes pertaining to the case where update checks are allowed.
//
+ // A target version prefix, if imposed by policy; otherwise, an empty string.
+ std::string target_version_prefix;
// A target channel, if so imposed by policy; otherwise, an empty string.
std::string target_channel;