| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_METRICS_METRICS_UPLOAD_SCHEDULER_H_ | 5 #ifndef COMPONENTS_METRICS_METRICS_UPLOAD_SCHEDULER_H_ |
| 6 #define COMPONENTS_METRICS_METRICS_UPLOAD_SCHEDULER_H_ | 6 #define COMPONENTS_METRICS_METRICS_UPLOAD_SCHEDULER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/feature_list.h" | 9 #include "base/feature_list.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "components/metrics/metrics_scheduler.h" | 12 #include "components/metrics/metrics_scheduler.h" |
| 13 | 13 |
| 14 namespace metrics { | 14 namespace metrics { |
| 15 | 15 |
| 16 extern const base::Feature kUploadSchedulerFeature; | 16 extern const base::Feature kUploadSchedulerFeature; |
| 17 | 17 |
| 18 // Scheduler task to drive a MetricsService object's uploading. | 18 // Scheduler task to drive a ReportingService object's uploading. |
| 19 class MetricsUploadScheduler : public MetricsScheduler { | 19 class MetricsUploadScheduler : public MetricsScheduler { |
| 20 public: | 20 public: |
| 21 // Creates MetricsUploadScheduler object with the given |upload_callback| | 21 // Creates MetricsUploadScheduler object with the given |upload_callback| |
| 22 // callback to call when uploading should happen. The callback must | 22 // callback to call when uploading should happen. The callback must |
| 23 // arrange to call either UploadFinished or UploadCancelled on completion. | 23 // arrange to call either UploadFinished or UploadCancelled on completion. |
| 24 explicit MetricsUploadScheduler(const base::Closure& upload_callback); | 24 explicit MetricsUploadScheduler(const base::Closure& upload_callback); |
| 25 ~MetricsUploadScheduler() override; | 25 ~MetricsUploadScheduler() override; |
| 26 | 26 |
| 27 // Callback from MetricsService when a triggered upload finishes. | 27 // Callback from MetricsService when a triggered upload finishes. |
| 28 void UploadFinished(bool server_is_healthy); | 28 void UploadFinished(bool server_is_healthy); |
| 29 | 29 |
| 30 // Callback from MetricsService when an upload is cancelled. | 30 // Callback from MetricsService when an upload is cancelled. |
| 31 // Also stops the scheduler. | 31 // Also stops the scheduler. |
| 32 void StopAndUploadCancelled(); | 32 void StopAndUploadCancelled(); |
| 33 | 33 |
| 34 // Callback from MetricsService when an upload is cancelled because it would | 34 // Callback from MetricsService when an upload is cancelled because it would |
| 35 // be over the allowed data usage cap. | 35 // be over the allowed data usage cap. |
| 36 void UploadOverDataUsageCap(); | 36 void UploadOverDataUsageCap(); |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 // Record the upload interval time. | |
| 40 virtual void LogActualUploadInterval(base::TimeDelta interval); | |
| 41 | |
| 42 // MetricsScheduler: | |
| 43 void TriggerTask() override; | |
| 44 | |
| 45 // The tick count of the last time log upload has been finished and null if no | |
| 46 // upload has been done yet. | |
| 47 base::TimeTicks last_upload_finish_time_; | |
| 48 | |
| 49 // Time to wait between uploads on success. | 39 // Time to wait between uploads on success. |
| 50 const base::TimeDelta unsent_logs_interval_; | 40 const base::TimeDelta unsent_logs_interval_; |
| 51 | 41 |
| 52 // Initial time to wait between upload retry attempts. | 42 // Initial time to wait between upload retry attempts. |
| 53 const base::TimeDelta initial_backoff_interval_; | 43 const base::TimeDelta initial_backoff_interval_; |
| 54 | 44 |
| 55 // Time to wait for the next upload attempt if the next one fails. | 45 // Time to wait for the next upload attempt if the next one fails. |
| 56 base::TimeDelta backoff_interval_; | 46 base::TimeDelta backoff_interval_; |
| 57 | 47 |
| 58 DISALLOW_COPY_AND_ASSIGN(MetricsUploadScheduler); | 48 DISALLOW_COPY_AND_ASSIGN(MetricsUploadScheduler); |
| 59 }; | 49 }; |
| 60 | 50 |
| 61 } // namespace metrics | 51 } // namespace metrics |
| 62 | 52 |
| 63 #endif // COMPONENTS_METRICS_METRICS_UPLOAD_SCHEDULER_H_ | 53 #endif // COMPONENTS_METRICS_METRICS_UPLOAD_SCHEDULER_H_ |
| OLD | NEW |