Serialize "ismachine" as part of the updater state in ComponentUpdater

Bug: 615187
Change-Id: Ia1e7ceb05eec146bb62f00260075e2f2f1af7dbf
Reviewed-on: https://chromium-review.googlesource.com/899920
Reviewed-by: Joshua Pawlicki <[email protected]>
Commit-Queue: Sorin Jianu <[email protected]>
Cr-Commit-Position: refs/heads/master@{#534446}
diff --git a/components/update_client/protocol_builder_unittest.cc b/components/update_client/protocol_builder_unittest.cc
index cc2a665f..1a6dc5a 100644
--- a/components/update_client/protocol_builder_unittest.cc
+++ b/components/update_client/protocol_builder_unittest.cc
@@ -43,6 +43,7 @@
   EXPECT_EQ(std::string::npos, request.find("<updater"));
 
   UpdaterState::Attributes attributes;
+  attributes["ismachine"] = "1";
   attributes["domainjoined"] = "1";
   attributes["name"] = "Omaha";
   attributes["version"] = "1.2.3.4";
@@ -55,7 +56,7 @@
       std::make_unique<UpdaterState::Attributes>(attributes));
   EXPECT_NE(std::string::npos, request.find(" domainjoined=\"1\""));
   const std::string updater_element =
-      "<updater autoupdatecheckenabled=\"0\" "
+      "<updater autoupdatecheckenabled=\"0\" ismachine=\"1\" "
       "lastchecked=\"2\" laststarted=\"1\" name=\"Omaha\" "
       "updatepolicy=\"-1\" version=\"1.2.3.4\"/>";
 #if defined(GOOGLE_CHROME_BUILD)
diff --git a/components/update_client/update_checker.cc b/components/update_client/update_checker.cc
index 8f9de17..1bd3915 100644
--- a/components/update_client/update_checker.cc
+++ b/components/update_client/update_checker.cc
@@ -20,6 +20,7 @@
 #include "base/task_scheduler/post_task.h"
 #include "base/threading/thread_checker.h"
 #include "base/threading/thread_task_runner_handle.h"
+#include "build/build_config.h"
 #include "components/update_client/component.h"
 #include "components/update_client/configurator.h"
 #include "components/update_client/persisted_data.h"
@@ -118,8 +119,16 @@
 
 // This function runs on the blocking pool task runner.
 void UpdateCheckerImpl::ReadUpdaterStateAttributes() {
-  const bool is_machine_install = !config_->IsPerUserInstall();
-  updater_state_attributes_ = UpdaterState::GetState(is_machine_install);
+#if defined(OS_WIN)
+  // On Windows, the Chrome and the updater install modes are matched by design.
+  updater_state_attributes_ =
+      UpdaterState::GetState(!config_->IsPerUserInstall());
+#elif defined(OS_MACOSX) && !defined(OS_IOS)
+  // MacOS ignores this value in the current implementation but this may change.
+  updater_state_attributes_ = UpdaterState::GetState(false);
+#else
+// Other platforms don't have updaters.
+#endif  // OS_WIN
 }
 
 void UpdateCheckerImpl::CheckForUpdatesHelper(
diff --git a/components/update_client/updater_state.cc b/components/update_client/updater_state.cc
index b810253..c9bd83c 100644
--- a/components/update_client/updater_state.cc
+++ b/components/update_client/updater_state.cc
@@ -53,6 +53,10 @@
 UpdaterState::Attributes UpdaterState::BuildAttributes() const {
   Attributes attributes;
 
+#if defined(OS_WIN)
+  // Only Windows implements this attribute in a meaningful way.
+  attributes["ismachine"] = is_machine_ ? "1" : "0";
+#endif  // OS_WIN
   attributes[kIsEnterpriseManaged] = is_enterprise_managed_ ? "1" : "0";
 
   attributes["name"] = updater_name_;
diff --git a/components/update_client/updater_state.h b/components/update_client/updater_state.h
index ea8b64e..7b6d3a4b 100644
--- a/components/update_client/updater_state.h
+++ b/components/update_client/updater_state.h
@@ -23,7 +23,8 @@
 
   // Returns a map of items representing the state of an updater. These items
   // can be serialized as XML attributes in the request building.
-  // |is_machine| is true for per-system installs of Chrome. Returns nullptr on
+  // If |is_machine| is true, this indicates that the updater state corresponds
+  // to the machine instance of the updater. Returns nullptr on
   // the platforms and builds where this feature is not supported.
   static std::unique_ptr<Attributes> GetState(bool is_machine);
 
@@ -52,7 +53,10 @@
 
   static std::string NormalizeTimeDelta(const base::TimeDelta& delta);
 
-  bool is_machine_ = false;
+  // True if the Omaha updater is installed per-machine.
+  // The MacOS implementation ignores the value of this member but this may
+  // change in the future.
+  bool is_machine_;
   std::string updater_name_;
   base::Version updater_version_;
   base::Time last_autoupdate_started_;
diff --git a/components/update_client/updater_state_unittest.cc b/components/update_client/updater_state_unittest.cc
index 86ad660..d9d028c 100644
--- a/components/update_client/updater_state_unittest.cc
+++ b/components/update_client/updater_state_unittest.cc
@@ -43,12 +43,19 @@
   EXPECT_STREQ("1", attributes.at("updatepolicy").c_str());
 
 #if defined(GOOGLE_CHROME_BUILD)
-  #if defined(OS_WIN)
-    // The name of the Windows updater for Chrome.
-    EXPECT_STREQ("Omaha", UpdaterState::GetState(false)->at("name").c_str());
+#if defined(OS_WIN)
+  // The value of "ismachine".
+  EXPECT_STREQ("0", UpdaterState::GetState(false)->at("ismachine").c_str());
+  EXPECT_STREQ("1", UpdaterState::GetState(true)->at("ismachine").c_str());
+
+  // The name of the Windows updater for Chrome.
+  EXPECT_STREQ("Omaha", UpdaterState::GetState(false)->at("name").c_str());
 #elif defined(OS_MACOSX) && !defined(OS_IOS)
+  // MacOS does not serialize "ismachine".
+  EXPECT(0, UpdaterState::GetState(false).count("ismachine"));
+  EXPECT(0, UpdaterState::GetState(true).count("ismachine"));
   EXPECT_STREQ("Keystone", UpdaterState::GetState(false)->at("name").c_str());
-#endif
+#endif  // OS_WIN
 #endif  // GOOGLE_CHROME_BUILD
 
   // Tests some of the remaining values.
diff --git a/components/update_client/updater_state_win.cc b/components/update_client/updater_state_win.cc
index 9b81183..13e5dd68 100644
--- a/components/update_client/updater_state_win.cc
+++ b/components/update_client/updater_state_win.cc
@@ -4,6 +4,8 @@
 
 #include "components/update_client/updater_state.h"
 
+#include <windows.h>
+
 #include <string>
 #include <utility>
 
@@ -15,8 +17,6 @@
 #include "base/win/registry.h"
 #include "base/win/win_util.h"
 
-#include <windows.h>
-
 // TODO(sorin): implement this in terms of
 // chrome/installer/util/google_update_settings (crbug.com/615187).