Add D-Bus method to get the duration since an update completed.

This new API can be used by Chrome to automatically reboot the device
at N hours after updating. This is implemented as a D-Bus method that
returns the number of micro-seconds on the wall-clock since the update
completed. If the device has not updated, the D-Bus method returns an
error.

For robustness, durations are measured using the CLOCK_BOOTTIME clock
instead of the usual CLOCK_REALTIME clock. This avoids interference
with NTP adjustments, the RTC clock being wrong and other things.

BUG=chromium:218192
TEST=New unit test + unit tests pass + manual test on a device using
    the gdbus(1) command as the chronos user.

Change-Id: I51d44d69afe2d3024bb0780916c3c4e3f8ebb19e
Reviewed-on: https://chromium-review.googlesource.com/173032
Reviewed-by: David Zeuthen <zeuthen@chromium.org>
Commit-Queue: David Zeuthen <zeuthen@chromium.org>
Tested-by: David Zeuthen <zeuthen@chromium.org>
diff --git a/update_attempter.h b/update_attempter.h
index 74b73f6..70381d9 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -179,6 +179,10 @@
   // from the server asynchronously at its own frequency.
   void RefreshDevicePolicy();
 
+  // Returns the boottime (CLOCK_BOOTTIME) recorded at the last
+  // successful update. Returns false if the device has not updated.
+  bool GetBootTimeAtUpdate(base::Time *out_boot_time);
+
  private:
   // Update server URL for automated lab test.
   static const char* const kTestUpdateUrl;
@@ -203,6 +207,7 @@
   FRIEND_TEST(UpdateAttempterTest, ScheduleErrorEventActionTest);
   FRIEND_TEST(UpdateAttempterTest, UpdateTest);
   FRIEND_TEST(UpdateAttempterTest, ReportDailyMetrics);
+  FRIEND_TEST(UpdateAttempterTest, BootTimeInUpdateMarkerFile);
 
   // Ctor helper method.
   void Init(SystemState* system_state,
@@ -329,6 +334,10 @@
   // started and housekeeping was performed.
   bool StartP2PAtStartup();
 
+  // Writes to the processing completed marker. Does nothing if
+  // |update_completed_marker_| is empty.
+  void WriteUpdateCompletedMarker();
+
   // Last status notification timestamp used for throttling. Use monotonic
   // TimeTicks to ensure that notifications are sent even if the system clock is
   // set back in the middle of an update.