Add update reboot metric to the update engine.

This change add the Installer.UpdateNumReboots metric.

This records the number of reboots that occurred while an update was being
attempted. It uses a marker file stored in tmp to discover whether or not
it's already recorded the reboot.

BUG=chromium:226766
TEST=Unittests | ran an update on a test machine and rebooted/resumed and
checked about:histograms to confirm numbers. Also restart update-engine to
verify it didn't double count that.

Change-Id: I5d2af9d5b62a9d974c7c6243a89cb3359051b650
Reviewed-on: https://gerrit.chromium.org/gerrit/47710
Tested-by: Chris Sosa <sosa@chromium.org>
Commit-Queue: Chris Sosa <sosa@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
diff --git a/system_state.cc b/system_state.cc
index 432b99f..da18500 100644
--- a/system_state.cc
+++ b/system_state.cc
@@ -5,6 +5,7 @@
 #include <base/file_util.h>
 
 #include "update_engine/real_system_state.h"
+#include "update_engine/utils.h"
 
 namespace chromeos_update_engine {
 
@@ -14,7 +15,8 @@
 RealSystemState::RealSystemState()
     : device_policy_(NULL),
       connection_manager_(this),
-      request_params_(this) {}
+      request_params_(this),
+      system_rebooted_(false) {}
 
 bool RealSystemState::Initialize(bool enable_gpio) {
   metrics_lib_.Init();
@@ -24,6 +26,14 @@
     return false;
   }
 
+  if (!utils::FileExists(kSystemRebootedMarkerFile)) {
+    if (!utils::WriteFile(kSystemRebootedMarkerFile, "", 0)) {
+      LOG(ERROR) << "Could not create reboot marker file";
+      return false;
+    }
+    system_rebooted_ = true;
+  }
+
   if (!payload_state_.Initialize(this))
     return false;