Add new metrics.

The current metrics (Installer.* namespace) have several shortcomings,
for example it's not immediately clear when and how frequent each
metric is reported. This CL introduces new metrics that addresses this
and other problems. The new metrics are all in the UpdateEngine.*
namespace and fall into five categories

 UpdateEngine.Daily.*               Reported daily.
 UpdateEngine.Check.*               On every check.
 UpdateEngine.Attempt.*             On every attempt.
 UpdateEngine.SuccessfulUpdate.*    With every successful update.
 UpdateEngine.*                     Miscellaneous

Most of the new metrics mimic existing metrics and also leverage the
existing code, book-keeping and unit tests. The plan is to remove the
Installer.* metrics once we're happy with the new ones.

I've also tested this manually by performing updates and verifying
that chrome://histograms looks correct.

BUG=chromium:355745
TEST=New unit tests + unit tests pass + manual testing.

Change-Id: I7a3f68d75910384b116c7e4664776e25d3997584
Reviewed-on: https://chromium-review.googlesource.com/191314
Reviewed-by: David Zeuthen <zeuthen@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 bb47f1a..1035404 100644
--- a/payload_state.h
+++ b/payload_state.h
@@ -117,6 +117,10 @@
   FRIEND_TEST(PayloadStateTest, RollbackVersion);
   FRIEND_TEST(PayloadStateTest, UpdateSuccessWithWipedPrefs);
 
+  // Helper called when an attempt has begun, is called by
+  // UpdateResumed() and UpdateRestarted().
+  void AttemptStarted();
+
   // Increments the payload attempt number used for metrics.
   void IncrementPayloadAttemptNumber();
 
@@ -149,23 +153,14 @@
   // that were downloaded recently.
   void UpdateBytesDownloaded(size_t count);
 
-  // Reports the various metrics related to the number of bytes downloaded.
-  void ReportBytesDownloadedMetrics();
+  // Calculates the PayloadType we're using.
+  PayloadType CalculatePayloadType();
 
-  // Reports the metric related to number of URL switches.
-  void ReportUpdateUrlSwitchesMetric();
+  // Collects and reports the various metrics related to an update attempt.
+  void CollectAndReportAttemptMetrics(ErrorCode code);
 
-  // Reports the various metrics related to rebooting during an update.
-  void ReportRebootMetrics();
-
-  // Reports the various metrics related to update duration.
-  void ReportDurationMetrics();
-
-  // Reports the metric related to the applied payload type.
-  void ReportPayloadTypeMetric();
-
-  // Reports the various metrics related to update attempts counts.
-  void ReportAttemptsCountMetrics();
+  // Collects and reports the various metrics related to a successful update.
+  void CollectAndReportSuccessfulUpdateMetrics();
 
   // Checks if we were expecting to be running in the new version but the
   // boot into the new version failed for some reason. If that's the case, an
@@ -327,11 +322,6 @@
   // Initializes |num_responses_seen_| from persisted state.
   void LoadNumResponsesSeen();
 
-  // Reports metric conveying how many times updates were abandoned
-  // before an update was applied. This metric is reported when an update is
-  // successfully applied.
-  void ReportUpdatesAbandonedCountMetric();
-
   // Reports metric conveying how many times updates were abandoned since
   // the last update was applied. The difference between this metric and the
   // previous ReportUpdatesAbandonedCountMetric() one is that this metric is
@@ -503,6 +493,15 @@
   // The cached value of |kPrefsP2PNumAttempts|.
   int p2p_num_attempts_;
 
+  // The number of bytes downloaded per attempt.
+  int64_t attempt_num_bytes_downloaded_;
+
+  // The boot time when the attempt was started.
+  base::Time attempt_start_time_boot_;
+
+  // The monotonic time when the attempt was started.
+  base::Time attempt_start_time_monotonic_;
+
   DISALLOW_COPY_AND_ASSIGN(PayloadState);
 };