metrics: Emit kAbnormalTermination if last update attempt failed.

This allows us to track how many update attempts terminates
abnormally, for example if the device is rebooted in the middle of an
update or if update_engine crashes. We use a marker state variable
(aka a "prefs" file) to keep track of this.

Note that we don't currently report any of the other metrics in the
UpdateEngine.Attempt.* namespace. If necessary, this can be changed in
the future - I left a TODO item in the code with more details.

BUG=chromium:357676
TEST=New unit tests + Unit tests pass + Manual tests.

Change-Id: I83fe284c7c46917c0c55b92314c58098e2fd1789
Reviewed-on: https://chromium-review.googlesource.com/197175
Reviewed-by: Alex Deymo <deymo@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 9ad4377..f8cc678 100644
--- a/payload_state.h
+++ b/payload_state.h
@@ -165,6 +165,18 @@
   // Collects and reports the various metrics related to an update attempt.
   void CollectAndReportAttemptMetrics(ErrorCode code);
 
+  // Persists values related to the UpdateEngine.Attempt.* metrics so
+  // we can identify later if an update attempt ends abnormally.
+  void PersistAttemptMetrics();
+
+  // Clears persistent state previously set using AttemptMetricsPersist().
+  void ClearPersistedAttemptMetrics();
+
+  // Checks if persistent state previously set using AttemptMetricsPersist()
+  // exists and, if so, emits it with |attempt_result| set to
+  // metrics::AttemptResult::kAbnormalTermination.
+  void ReportAndClearPersistedAttemptMetrics();
+
   // Collects and reports the various metrics related to a successful update.
   void CollectAndReportSuccessfulUpdateMetrics();