metrics: Add UpdateEngine.Rollback.Result metric.

Add a metric to track if rollback succeeds or fails. The main use case
for this metric is to record how often rollback actually happens.

Right now we only track success/failure but if we see a lot of
failures in the future, we could add a new metric, for example

 UpdateEngine.Rollback.FailureErrorCode

to convey more detail.

BUG=None
TEST=New unit test + unit tests pass.

Change-Id: I5c32d8585dc8e4b6d38c540d2f754ede5b2ad50b
Reviewed-on: https://chromium-review.googlesource.com/195203
Reviewed-by: David Zeuthen <zeuthen@chromium.org>
Commit-Queue: David Zeuthen <zeuthen@chromium.org>
Tested-by: David Zeuthen <zeuthen@chromium.org>
diff --git a/payload_state.cc b/payload_state.cc
index 4c8efa0..c176238 100644
--- a/payload_state.cc
+++ b/payload_state.cc
@@ -203,10 +203,16 @@
   CalculateUpdateDurationUptime();
   SetUpdateTimestampEnd(system_state_->clock()->GetWallclockTime());
 
-  // Only report metrics on an update, not on a rollback.
-  if (attempt_type_ == AttemptType::kUpdate) {
-    CollectAndReportAttemptMetrics(kErrorCodeSuccess);
-    CollectAndReportSuccessfulUpdateMetrics();
+  switch (attempt_type_) {
+    case AttemptType::kUpdate:
+      CollectAndReportAttemptMetrics(kErrorCodeSuccess);
+      CollectAndReportSuccessfulUpdateMetrics();
+      break;
+
+    case AttemptType::kRollback:
+      metrics::ReportRollbackMetrics(system_state_,
+                                     metrics::RollbackResult::kSuccess);
+      break;
   }
 
   // Reset the number of responses seen since it counts from the last
@@ -229,9 +235,16 @@
     return;
   }
 
-  // Only report metrics on an update, not on a rollback.
-  if (attempt_type_ == AttemptType::kUpdate)
-    CollectAndReportAttemptMetrics(base_error);
+  switch (attempt_type_) {
+    case AttemptType::kUpdate:
+      CollectAndReportAttemptMetrics(base_error);
+      break;
+
+    case AttemptType::kRollback:
+      metrics::ReportRollbackMetrics(system_state_,
+                                     metrics::RollbackResult::kFailed);
+      break;
+  }
 
   switch (base_error) {
     // Errors which are good indicators of a problem with a particular URL or