blob: b1fa958e8a09d6ee9e62b111e5b4a1cab2bc62a1 [file] [log] [blame]
holte68395852017-01-10 20:40:211// Copyright 2017 The Chromium Authors. All rights reserved.
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/callback.h"
holte85bbd9d2017-02-14 20:55:589#include "base/feature_list.h"
holte68395852017-01-10 20:40:2110#include "base/macros.h"
11#include "base/time/time.h"
12#include "components/metrics/metrics_scheduler.h"
13
14namespace metrics {
15
holte85bbd9d2017-02-14 20:55:5816extern const base::Feature kUploadSchedulerFeature;
17
holtea3b24112017-03-14 02:08:2418// Scheduler task to drive a ReportingService object's uploading.
holte68395852017-01-10 20:40:2119class MetricsUploadScheduler : public MetricsScheduler {
20 public:
21 // Creates MetricsUploadScheduler object with the given |upload_callback|
22 // callback to call when uploading should happen. The callback must
23 // arrange to call either UploadFinished or UploadCancelled on completion.
24 explicit MetricsUploadScheduler(const base::Closure& upload_callback);
25 ~MetricsUploadScheduler() override;
26
27 // Callback from MetricsService when a triggered upload finishes.
28 void UploadFinished(bool server_is_healthy);
29
30 // Callback from MetricsService when an upload is cancelled.
holte85bbd9d2017-02-14 20:55:5831 // Also stops the scheduler.
32 void StopAndUploadCancelled();
holte68395852017-01-10 20:40:2133
34 // Callback from MetricsService when an upload is cancelled because it would
35 // be over the allowed data usage cap.
36 void UploadOverDataUsageCap();
37
38 private:
holte85bbd9d2017-02-14 20:55:5839 // Time to wait between uploads on success.
40 const base::TimeDelta unsent_logs_interval_;
41
42 // Initial time to wait between upload retry attempts.
43 const base::TimeDelta initial_backoff_interval_;
44
45 // Time to wait for the next upload attempt if the next one fails.
46 base::TimeDelta backoff_interval_;
holte68395852017-01-10 20:40:2147
48 DISALLOW_COPY_AND_ASSIGN(MetricsUploadScheduler);
49};
50
51} // namespace metrics
52
53#endif // COMPONENTS_METRICS_METRICS_UPLOAD_SCHEDULER_H_