• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef COMPONENTS_METRICS_METRICS_UPLOAD_SCHEDULER_H_
6 #define COMPONENTS_METRICS_METRICS_UPLOAD_SCHEDULER_H_
7 
8 #include "base/feature_list.h"
9 #include "base/functional/callback.h"
10 #include "base/time/time.h"
11 #include "components/metrics/metrics_scheduler.h"
12 
13 namespace metrics {
14 
15 // Scheduler task to drive a ReportingService object's uploading.
16 class MetricsUploadScheduler : public MetricsScheduler {
17  public:
18   // Creates MetricsUploadScheduler object with the given |upload_callback|
19   // callback to call when uploading should happen.  The callback must
20   // arrange to call either UploadFinished or UploadCancelled on completion.
21   MetricsUploadScheduler(const base::RepeatingClosure& upload_callback,
22                          bool fast_startup_for_testing);
23 
24   MetricsUploadScheduler(const MetricsUploadScheduler&) = delete;
25   MetricsUploadScheduler& operator=(const MetricsUploadScheduler&) = delete;
26 
27   ~MetricsUploadScheduler() override;
28 
29   // Callback from MetricsService when a triggered upload finishes.
30   void UploadFinished(bool server_is_healthy);
31 
32   // Callback from MetricsService when an upload is cancelled.
33   // Also stops the scheduler.
34   void StopAndUploadCancelled();
35 
36   // Callback from MetricsService when an upload is cancelled because it would
37   // be over the allowed data usage cap.
38   void UploadOverDataUsageCap();
39 
40   // Time delay after a log is uploaded successfully before attempting another.
41   // On mobile, keeping the radio on is very expensive, so prefer to keep this
42   // short and send in bursts.
43   static base::TimeDelta GetUnsentLogsInterval();
44 
45   // Initial time delay after a log uploaded fails before retrying it.
46   static base::TimeDelta GetInitialBackoffInterval();
47 
48  private:
49   // Time to wait between uploads on success.
50   const base::TimeDelta unsent_logs_interval_;
51 
52   // Initial time to wait between upload retry attempts.
53   const base::TimeDelta initial_backoff_interval_;
54 
55   // Time to wait for the next upload attempt if the next one fails.
56   base::TimeDelta backoff_interval_;
57 };
58 
59 }  // namespace metrics
60 
61 #endif  // COMPONENTS_METRICS_METRICS_UPLOAD_SCHEDULER_H_
62