| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_REPORTING_SCHEDULER_H_ | 5 #ifndef COMPONENTS_METRICS_METRICS_REPORTING_SCHEDULER_H_ |
| 6 #define COMPONENTS_METRICS_METRICS_REPORTING_SCHEDULER_H_ | 6 #define COMPONENTS_METRICS_METRICS_REPORTING_SCHEDULER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 13 #include "components/metrics/net/network_metrics_provider.h" | 13 #include "components/metrics/net/network_metrics_provider.h" |
| 14 | 14 |
| 15 namespace metrics { | 15 namespace metrics { |
| 16 | 16 |
| 17 // Scheduler task to drive a MetricsService object's uploading. | 17 // Scheduler task to drive a MetricsService object's uploading. |
| 18 class MetricsReportingScheduler { | 18 class MetricsReportingScheduler { |
| 19 public: | 19 public: |
| 20 // Creates MetricsServiceScheduler object with the given |upload_callback| | 20 // Creates MetricsServiceScheduler object with the given |upload_callback| |
| 21 // callback to call when uploading should happen and | 21 // callback to call when uploading should happen and |
| 22 // |upload_interval_callback| to determine the interval between uploads | 22 // |upload_interval_callback| to determine the interval between uploads |
| 23 // in steady state. | 23 // in steady state. |
| 24 MetricsReportingScheduler( | 24 MetricsReportingScheduler( |
| 25 const base::Closure& upload_callback, | 25 const base::Closure& upload_callback, |
| 26 const base::Callback<base::TimeDelta(void)>& upload_interval_callback); | 26 const base::Callback<base::TimeDelta(void)>& upload_interval_callback); |
| 27 ~MetricsReportingScheduler(); | 27 virtual ~MetricsReportingScheduler(); |
| 28 | 28 |
| 29 // Starts scheduling uploads. This in a no-op if the scheduler is already | 29 // Starts scheduling uploads. This in a no-op if the scheduler is already |
| 30 // running, so it is safe to call more than once. | 30 // running, so it is safe to call more than once. |
| 31 void Start(); | 31 void Start(); |
| 32 | 32 |
| 33 // Stops scheduling uploads. | 33 // Stops scheduling uploads. |
| 34 void Stop(); | 34 void Stop(); |
| 35 | 35 |
| 36 // Callback from MetricsService when the startup init task has completed. | 36 // Callback from MetricsService when the startup init task has completed. |
| 37 void InitTaskComplete(); | 37 void InitTaskComplete(); |
| 38 | 38 |
| 39 // Callback from MetricsService when a triggered upload finishes. | 39 // Callback from MetricsService when a triggered upload finishes. |
| 40 void UploadFinished(bool server_is_healthy, bool more_logs_remaining); | 40 void UploadFinished(bool server_is_healthy, bool more_logs_remaining); |
| 41 | 41 |
| 42 // Callback from MetricsService when a triggered upload is cancelled by the | 42 // Callback from MetricsService when a triggered upload is cancelled by the |
| 43 // MetricsService. | 43 // MetricsService. |
| 44 void UploadCancelled(); | 44 void UploadCancelled(); |
| 45 | 45 |
| 46 // Sets the upload interval to a specific value, exposed for unit tests. | 46 // Sets the upload interval to a specific value, exposed for unit tests. |
| 47 void SetUploadIntervalForTesting(base::TimeDelta interval); | 47 void SetUploadIntervalForTesting(base::TimeDelta interval); |
| 48 | 48 |
| 49 protected: |
| 50 enum InitSequence { |
| 51 TIMER_FIRED_FIRST, |
| 52 INIT_TASK_COMPLETED_FIRST, |
| 53 INIT_SEQUENCE_ENUM_SIZE, |
| 54 }; |
| 55 |
| 49 private: | 56 private: |
| 57 // Record the init sequence order histogram. |
| 58 virtual void LogMetricsInitSequence(InitSequence sequence); |
| 59 |
| 60 // Record the upload interval time. |
| 61 virtual void LogActualUploadInterval(base::TimeDelta interval); |
| 62 |
| 50 // Timer callback indicating it's time for the MetricsService to upload | 63 // Timer callback indicating it's time for the MetricsService to upload |
| 51 // metrics. | 64 // metrics. |
| 52 void TriggerUpload(); | 65 void TriggerUpload(); |
| 53 | 66 |
| 54 // Schedules a future call to TriggerUpload if one isn't already pending. | 67 // Schedules a future call to TriggerUpload if one isn't already pending. |
| 55 void ScheduleNextUpload(); | 68 void ScheduleNextUpload(); |
| 56 | 69 |
| 57 // Increases the upload interval each time it's called, to handle the case | 70 // Increases the upload interval each time it's called, to handle the case |
| 58 // where the server is having issues. | 71 // where the server is having issues. |
| 59 void BackOffUploadInterval(); | 72 void BackOffUploadInterval(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 90 | 103 |
| 91 // Callback function used to get the standard upload time. | 104 // Callback function used to get the standard upload time. |
| 92 base::Callback<base::TimeDelta(void)> upload_interval_callback_; | 105 base::Callback<base::TimeDelta(void)> upload_interval_callback_; |
| 93 | 106 |
| 94 DISALLOW_COPY_AND_ASSIGN(MetricsReportingScheduler); | 107 DISALLOW_COPY_AND_ASSIGN(MetricsReportingScheduler); |
| 95 }; | 108 }; |
| 96 | 109 |
| 97 } // namespace metrics | 110 } // namespace metrics |
| 98 | 111 |
| 99 #endif // COMPONENTS_METRICS_METRICS_REPORTING_SCHEDULER_H_ | 112 #endif // COMPONENTS_METRICS_METRICS_REPORTING_SCHEDULER_H_ |
| OLD | NEW |