holte | 6839585 | 2017-01-10 20:40:21 | [diff] [blame] | 1 | // 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" |
holte | 85bbd9d | 2017-02-14 20:55:58 | [diff] [blame] | 9 | #include "base/feature_list.h" |
holte | 6839585 | 2017-01-10 20:40:21 | [diff] [blame] | 10 | #include "base/macros.h" |
| 11 | #include "base/time/time.h" |
| 12 | #include "components/metrics/metrics_scheduler.h" |
| 13 | |
| 14 | namespace metrics { |
| 15 | |
holte | 85bbd9d | 2017-02-14 20:55:58 | [diff] [blame] | 16 | extern const base::Feature kUploadSchedulerFeature; |
| 17 | |
holte | a3b2411 | 2017-03-14 02:08:24 | [diff] [blame] | 18 | // Scheduler task to drive a ReportingService object's uploading. |
holte | 6839585 | 2017-01-10 20:40:21 | [diff] [blame] | 19 | class 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. |
holte | 85bbd9d | 2017-02-14 20:55:58 | [diff] [blame] | 31 | // Also stops the scheduler. |
| 32 | void StopAndUploadCancelled(); |
holte | 6839585 | 2017-01-10 20:40:21 | [diff] [blame] | 33 | |
| 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: |
holte | 85bbd9d | 2017-02-14 20:55:58 | [diff] [blame] | 39 | // 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_; |
holte | 6839585 | 2017-01-10 20:40:21 | [diff] [blame] | 47 | |
| 48 | DISALLOW_COPY_AND_ASSIGN(MetricsUploadScheduler); |
| 49 | }; |
| 50 | |
| 51 | } // namespace metrics |
| 52 | |
| 53 | #endif // COMPONENTS_METRICS_METRICS_UPLOAD_SCHEDULER_H_ |