update_engine: Add metrics to duration to apply an update.

Add new metrics that record the time between an update being seen by the client
to the time when the update is actually applied.

This metric will be recorded only for Enterprise enrolled devices.

UpdateEngine.SuccessfulUpdate.TimeRestrictedDurationFromSeenToUpdateMinutes is
recorded when an update is applied while the
DeviceAutoUpdateTimeRestrictions device policy exists.

UpdateEngine.SuccessfulUpdate.DurationFromSeenToUpdateMinutes is
recorded when an update is applied without the policy.

BUG=chromium:852860
TEST=run updater manually and checked chrome://histograms

Change-Id: I4dd54fc4404ef2e66902113617841808c1f9e616
Reviewed-on: https://chromium-review.googlesource.com/1179230
Commit-Ready: May Lippert <[email protected]>
Tested-by: May Lippert <[email protected]>
Reviewed-by: Amin Hassani <[email protected]>
Reviewed-by: Sen Jiang <[email protected]>
diff --git a/metrics_reporter_omaha_unittest.cc b/metrics_reporter_omaha_unittest.cc
index 878a323..a479028 100644
--- a/metrics_reporter_omaha_unittest.cc
+++ b/metrics_reporter_omaha_unittest.cc
@@ -500,4 +500,43 @@
                                     kernel_max_rollforward_success);
 }
 
+TEST_F(MetricsReporterOmahaTest, ReportEnterpriseUpdateSeenToDownloadDays) {
+  constexpr int kDaysToUpdate = 10;
+  constexpr int kMinBucket = 1;
+  constexpr int kMaxBucket = 6 * 30;  // approximately 6 months
+  constexpr int kNumBuckets = 50;
+
+  EXPECT_CALL(*mock_metrics_lib_,
+              SendToUMA(metrics::kMetricSuccessfulUpdateDurationFromSeenDays,
+                        kDaysToUpdate,
+                        kMinBucket,
+                        kMaxBucket,
+                        kNumBuckets))
+      .Times(1);
+
+  reporter_.ReportEnterpriseUpdateSeenToDownloadDays(
+      false /* has_time_restriction_policy */, kDaysToUpdate);
+}
+
+TEST_F(MetricsReporterOmahaTest,
+       ReportEnterpriseTimeRestrictedUpdateSeenToDownloadTime) {
+  const int kDaysToUpdate = 15;
+  constexpr int kMinBucket = 1;
+  constexpr int kMaxBucket = 6 * 30;  // approximately 6 months
+  constexpr int kNumBuckets = 50;
+
+  EXPECT_CALL(
+      *mock_metrics_lib_,
+      SendToUMA(
+          metrics::kMetricSuccessfulUpdateDurationFromSeenTimeRestrictedDays,
+          kDaysToUpdate,
+          kMinBucket,
+          kMaxBucket,
+          kNumBuckets))
+      .Times(1);
+
+  reporter_.ReportEnterpriseUpdateSeenToDownloadDays(
+      true /* has_time_restriction_policy */, kDaysToUpdate);
+}
+
 }  // namespace chromeos_update_engine