Add Installer.UpdatesAbandonedCount metric

This patch adds a new metric Installer.UpdatesAbandonedCount to track
the number of update attempts that didn't complete because a newer
update was detected during the download. This is implemented by
counting the number of different responses seen since the last
successful update.

Updates are typically only abandoned if a device is suspended or
powered off while an update is happening. This can happen either
because the device was not turned on for a very long time or because
it had little or no connectivity to Omaha and/or the servers serving
the payload.

This metric will help show how many users run into this problem.

BUG=chromium:248800
TEST=New units tests + Unit tests pass + Manually tested

Change-Id: I524a380a931c2fb30916d033b7e5b0c700f57103
Reviewed-on: https://gerrit.chromium.org/gerrit/59098
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: David Zeuthen <zeuthen@chromium.org>
Commit-Queue: David Zeuthen <zeuthen@chromium.org>
diff --git a/payload_state.h b/payload_state.h
index e28d5e8..f8a2d0c 100644
--- a/payload_state.h
+++ b/payload_state.h
@@ -61,6 +61,10 @@
     return url_switch_count_;
   }
 
+  virtual inline int GetNumResponsesSeen() {
+    return num_responses_seen_;
+  }
+
   virtual inline base::Time GetBackoffExpiryTime() {
     return backoff_expiry_time_;
   }
@@ -251,6 +255,16 @@
   // the Omaha response.
   void ComputeCandidateUrls();
 
+  // Sets |num_responses_seen_| and persist it to disk.
+  void SetNumResponsesSeen(int num_responses_seen);
+
+  // Initializes |num_responses_seen_| from persisted state.
+  void LoadNumResponsesSeen();
+
+  // Reports metric conveying how many times updates were abandoned
+  // before an update was applied.
+  void ReportUpdatesAbandonedCountMetric();
+
   // The global state of the system.
   SystemState* system_state_;
 
@@ -307,6 +321,11 @@
   // data we read from the socket.
   DownloadSource current_download_source_;
 
+  // The number of different Omaha responses seen. Increases every time
+  // a new response is seen. Resets to 0 only when the system has been
+  // successfully updated.
+  int num_responses_seen_;
+
   // The number of system reboots during an update attempt. Technically since
   // we don't go out of our way to not update it when not attempting an update,
   // also records the number of reboots before the next update attempt starts.