Chromium Code Reviews| 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/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.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 | 14 |
| 14 namespace metrics { | 15 namespace metrics { |
| 15 | 16 |
| 16 // Scheduler task to drive a MetricsService object's uploading. | 17 // Scheduler task to drive a MetricsService object's uploading. |
| 17 class MetricsReportingScheduler { | 18 class MetricsReportingScheduler { |
| 18 public: | 19 public: |
| 19 explicit MetricsReportingScheduler(const base::Closure& upload_callback); | 20 explicit MetricsReportingScheduler(const base::Closure& upload_callback); |
| 20 ~MetricsReportingScheduler(); | 21 ~MetricsReportingScheduler(); |
| 21 | 22 |
| 22 // Starts scheduling uploads. This in a no-op if the scheduler is already | 23 // Starts scheduling uploads. This in a no-op if the scheduler is already |
| 23 // running, so it is safe to call more than once. | 24 // running, so it is safe to call more than once. |
| 24 void Start(); | 25 void Start(); |
| 25 | 26 |
| 26 // Stops scheduling uploads. | 27 // Stops scheduling uploads. |
| 27 void Stop(); | 28 void Stop(); |
| 28 | 29 |
| 29 // Callback from MetricsService when the startup init task has completed. | 30 // Callback from MetricsService when the startup init task has completed. |
| 30 void InitTaskComplete(); | 31 void InitTaskComplete(); |
| 31 | 32 |
| 32 // Callback from MetricsService when a triggered upload finishes. | 33 // Callback from MetricsService when a triggered upload finishes. |
| 33 void UploadFinished(bool server_is_healthy, bool more_logs_remaining); | 34 void UploadFinished(bool server_is_healthy, bool more_logs_remaining); |
| 34 | 35 |
| 35 // Callback from MetricsService when a triggered upload is cancelled by the | 36 // Callback from MetricsService when a triggered upload is cancelled by the |
| 36 // MetricsService. | 37 // MetricsService. |
| 37 void UploadCancelled(); | 38 void UploadCancelled(); |
| 38 | 39 |
| 39 // Sets the upload interval to a specific value, exposed for unit tests. | 40 // Sets the upload interval to a specific value, exposed for unit tests. |
| 40 void SetUploadIntervalForTesting(base::TimeDelta interval); | 41 void SetUploadIntervalForTesting(base::TimeDelta interval); |
| 41 | 42 |
| 43 // Sets class variable |network_metrics_provider| for having access to | |
| 44 // connection type. | |
| 45 void SetNetworkMetricsProvider( | |
| 46 const metrics::NetworkMetricsProvider* network_metrics_provider); | |
| 47 | |
| 48 // Returns true if the connection type is 2G, 3G, or 4G. | |
| 49 bool IsCellularConnection(); | |
|
Alexei Svitkine (slow)
2015/02/13 21:11:41
Nit: Add an empty line after this.
gayane -on leave until 09-2017
2015/02/13 22:23:13
Done.
| |
| 42 private: | 50 private: |
| 43 // Timer callback indicating it's time for the MetricsService to upload | 51 // Timer callback indicating it's time for the MetricsService to upload |
| 44 // metrics. | 52 // metrics. |
| 45 void TriggerUpload(); | 53 void TriggerUpload(); |
| 46 | 54 |
| 47 // Schedules a future call to TriggerUpload if one isn't already pending. | 55 // Schedules a future call to TriggerUpload if one isn't already pending. |
| 48 void ScheduleNextUpload(); | 56 void ScheduleNextUpload(); |
| 49 | 57 |
| 50 // Increases the upload interval each time it's called, to handle the case | 58 // Increases the upload interval each time it's called, to handle the case |
| 51 // where the server is having issues. | 59 // where the server is having issues. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 77 // Indicates that the last triggered upload hasn't resolved yet. | 85 // Indicates that the last triggered upload hasn't resolved yet. |
| 78 bool callback_pending_; | 86 bool callback_pending_; |
| 79 | 87 |
| 80 // Whether the InitTaskComplete() callback has been called. | 88 // Whether the InitTaskComplete() callback has been called. |
| 81 bool init_task_complete_; | 89 bool init_task_complete_; |
| 82 | 90 |
| 83 // Whether the initial scheduled upload timer has fired before the init task | 91 // Whether the initial scheduled upload timer has fired before the init task |
| 84 // has been completed. | 92 // has been completed. |
| 85 bool waiting_for_init_task_complete_; | 93 bool waiting_for_init_task_complete_; |
| 86 | 94 |
| 95 // Used to get the connection type for deciding on upload interval. | |
| 96 const metrics::NetworkMetricsProvider* network_metrics_provider_; | |
| 97 | |
| 87 DISALLOW_COPY_AND_ASSIGN(MetricsReportingScheduler); | 98 DISALLOW_COPY_AND_ASSIGN(MetricsReportingScheduler); |
| 88 }; | 99 }; |
| 89 | 100 |
| 90 } // namespace metrics | 101 } // namespace metrics |
| 91 | 102 |
| 92 #endif // COMPONENTS_METRICS_METRICS_REPORTING_SCHEDULER_H_ | 103 #endif // COMPONENTS_METRICS_METRICS_REPORTING_SCHEDULER_H_ |
| OLD | NEW |