[go: nahoru, domu]

When Browser goes offline, add metrics on pending Aggregatable reports

Upon storing an Aggregatable Report at `creation_time`, it is scheduled with a`reporting_delay` to send at time `report_time` and is pending
until then.

If the browser closes or the device goes offline, and until it re-opens
or re-connects, we are unable to send reports. On such events, for each
pending reports, we record two {TimeSpan}s:
[1] TimeSinceCreation: The time elapsed since the report was created
(creation_time - now).
[2] TimeUntilReportTime: The time remaining for the report to be sent
(report_time - now).

The metrics will enable us to quantify the extent to which reducing
`reporting_delay` would increase the number of reports sent before an
unavailability event.

[Limitation] To limit memory usage, a maximum of 50 pending reports
timings are handled. Past this number, reports are dropped (until
reports get sent or an unavailability event occurs). Given that the most
recent reports can be dropped, we can expect the `TimeSinceCreation` to
be biased down slightly and `TimeUntilReportTime` to be biased up slightly. We expect this situation to be infrequent given the 10-60
minutes reporting window.

Bug: 1422713
Change-Id: If3e96b829e0b12916acdf0f59eece3a7177c9411
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4296410
Commit-Queue: Anthony Garant <anthonygarant@chromium.org>
Reviewed-by: John Delaney <johnidel@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1115728}
diff --git a/content/browser/aggregation_service/report_scheduler_timer.h b/content/browser/aggregation_service/report_scheduler_timer.h
index dcdc93a..843231c 100644
--- a/content/browser/aggregation_service/report_scheduler_timer.h
+++ b/content/browser/aggregation_service/report_scheduler_timer.h
@@ -48,6 +48,12 @@
     // call, that will be passed the same `now`.
     virtual void OnReportingTimeReached(base::Time now) = 0;
 
+    // Called when the connection changes from online to offline. When this
+    // happens the timer is paused which means `OnReportingTimeReached` will not
+    // be called until it gets resumed. Before resuming the timer,
+    // `AdjustOfflinereportTimes` will be called.
+    virtual void OnReportingPaused(base::Time now) {}
+
     // Called when the connection changes from offline to online. May also be
     // called on a connection change if there are no stored reports, see
     // `OnConnectionChanged()`. Running the callback will call `MaybeSet()` with