update_engine: move autoupdate_token to cohorthint attribute
If policy DeviceQuickFixBuildToken is set and is not empty then set "cohorthint" attribute
to the value of DeviceQuickFixBuildToken in update request. Takes precedence over kPrefsOmahaCohortHint pref.
BUG=chromium:932465
TEST=./build_packages --board=amd64-generic && \
cros_run_unit_tests --board=amd64-generic --packages update_engine
Change-Id: Ia4143b0854742ec22a535ce75b3b54a937a47b5a
diff --git a/omaha_request_builder_xml.cc b/omaha_request_builder_xml.cc
index 3e4a335..95fb183 100644
--- a/omaha_request_builder_xml.cc
+++ b/omaha_request_builder_xml.cc
@@ -118,12 +118,6 @@
app_body += " rollback_allowed=\"true\"";
}
}
- string autoupdate_token = params_->autoupdate_token();
- if (!autoupdate_token.empty()) {
- app_body += base::StringPrintf(
- " token=\"%s\"", XmlEncodeWithDefault(autoupdate_token).c_str());
- }
-
app_body += "></updatecheck>\n";
}
@@ -172,14 +166,20 @@
}
string OmahaRequestBuilderXml::GetCohortArg(const string arg_name,
- const string prefs_key) const {
- // There's nothing wrong with not having a given cohort setting, so we check
- // existence first to avoid the warning log message.
- if (!prefs_->Exists(prefs_key))
- return "";
+ const string prefs_key,
+ const string override_value) const {
string cohort_value;
- if (!prefs_->GetString(prefs_key, &cohort_value) || cohort_value.empty())
- return "";
+ if (!override_value.empty()) {
+ // |override_value| take precedence over pref value.
+ cohort_value = override_value;
+ } else {
+ // There's nothing wrong with not having a given cohort setting, so we check
+ // existence first to avoid the warning log message.
+ if (!prefs_->Exists(prefs_key))
+ return "";
+ if (!prefs_->GetString(prefs_key, &cohort_value) || cohort_value.empty())
+ return "";
+ }
// This is a sanity check to avoid sending a huge XML file back to Ohama due
// to a compromised stateful partition making the update check fail in low
// network environments envent after a reboot.
@@ -246,9 +246,14 @@
string app_cohort_args;
app_cohort_args += GetCohortArg("cohort", kPrefsOmahaCohort);
- app_cohort_args += GetCohortArg("cohorthint", kPrefsOmahaCohortHint);
app_cohort_args += GetCohortArg("cohortname", kPrefsOmahaCohortName);
+ // Policy provided value overrides pref.
+ string autoupdate_token = params_->autoupdate_token();
+ app_cohort_args += GetCohortArg("cohorthint",
+ kPrefsOmahaCohortHint,
+ autoupdate_token /* override_value */);
+
string fingerprint_arg;
if (!params_->os_build_fingerprint().empty()) {
fingerprint_arg = "fingerprint=\"" +