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( |
Alexei Svitkine (slow)
2015/02/17 20:50:04
Nit: Remove explicit since there's two params. Add
gayane -on leave until 09-2017
2015/02/18 00:30:35
Done.
| |
21 const base::Closure& upload_callback, | |
22 const base::Closure& is_cellular_connection_func); | |
Alexei Svitkine (slow)
2015/02/17 20:50:04
Nit: func -> callback
gayane -on leave until 09-2017
2015/02/18 00:30:35
Done.
| |
20 ~MetricsReportingScheduler(); | 23 ~MetricsReportingScheduler(); |
21 | 24 |
22 // Starts scheduling uploads. This in a no-op if the scheduler is already | 25 // Starts scheduling uploads. This in a no-op if the scheduler is already |
23 // running, so it is safe to call more than once. | 26 // running, so it is safe to call more than once. |
24 void Start(); | 27 void Start(); |
25 | 28 |
26 // Stops scheduling uploads. | 29 // Stops scheduling uploads. |
27 void Stop(); | 30 void Stop(); |
28 | 31 |
29 // Callback from MetricsService when the startup init task has completed. | 32 // Callback from MetricsService when the startup init task has completed. |
30 void InitTaskComplete(); | 33 void InitTaskComplete(); |
31 | 34 |
32 // Callback from MetricsService when a triggered upload finishes. | 35 // Callback from MetricsService when a triggered upload finishes. |
33 void UploadFinished(bool server_is_healthy, bool more_logs_remaining); | 36 void UploadFinished(bool server_is_healthy, bool more_logs_remaining); |
34 | 37 |
35 // Callback from MetricsService when a triggered upload is cancelled by the | 38 // Callback from MetricsService when a triggered upload is cancelled by the |
36 // MetricsService. | 39 // MetricsService. |
37 void UploadCancelled(); | 40 void UploadCancelled(); |
38 | 41 |
39 // Sets the upload interval to a specific value, exposed for unit tests. | 42 // Sets the upload interval to a specific value, exposed for unit tests. |
40 void SetUploadIntervalForTesting(base::TimeDelta interval); | 43 void SetUploadIntervalForTesting(base::TimeDelta interval); |
41 | 44 |
45 // Sets whether the network connection is cellular or not. | |
46 void SetConnectionType(bool is_cellular); | |
47 | |
42 private: | 48 private: |
43 // Timer callback indicating it's time for the MetricsService to upload | 49 // Timer callback indicating it's time for the MetricsService to upload |
44 // metrics. | 50 // metrics. |
45 void TriggerUpload(); | 51 void TriggerUpload(); |
46 | 52 |
47 // Schedules a future call to TriggerUpload if one isn't already pending. | 53 // Schedules a future call to TriggerUpload if one isn't already pending. |
48 void ScheduleNextUpload(); | 54 void ScheduleNextUpload(); |
49 | 55 |
50 // Increases the upload interval each time it's called, to handle the case | 56 // Increases the upload interval each time it's called, to handle the case |
51 // where the server is having issues. | 57 // where the server is having issues. |
52 void BackOffUploadInterval(); | 58 void BackOffUploadInterval(); |
53 | 59 |
54 // Returns upload interval based on the system and experiment that the user is | 60 // Returns upload interval based on the system and experiment that the user is |
55 // assigned to. | 61 // assigned to. |
56 // TODO(gayane): Only for experimenting with upload interval for Android | 62 // TODO(gayane): Only for experimenting with upload interval for Android |
57 // (bug: 17391128). Should be removed once the experiments are done. | 63 // (bug: 17391128). Should be removed once the experiments are done. |
58 base::TimeDelta GetStandardUploadInterval(); | 64 base::TimeDelta GetStandardUploadInterval(); |
59 | 65 |
66 // Returns true if the user is assigned to the experiment group for enabled | |
67 // cellular uploads. | |
68 bool IsCellularEnabledByExperiment(); | |
69 | |
60 // The MetricsService method to call when uploading should happen. | 70 // The MetricsService method to call when uploading should happen. |
61 const base::Closure upload_callback_; | 71 const base::Closure upload_callback_; |
62 | 72 |
63 base::OneShotTimer<MetricsReportingScheduler> upload_timer_; | 73 base::OneShotTimer<MetricsReportingScheduler> upload_timer_; |
64 | 74 |
65 // The interval between being told an upload is done and starting the next | 75 // The interval between being told an upload is done and starting the next |
66 // upload. | 76 // upload. |
67 base::TimeDelta upload_interval_; | 77 base::TimeDelta upload_interval_; |
68 | 78 |
69 // The tick count of the last time log upload has been finished and null if no | 79 // The tick count of the last time log upload has been finished and null if no |
70 // upload has been done yet. | 80 // upload has been done yet. |
71 base::TimeTicks last_upload_finish_time_; | 81 base::TimeTicks last_upload_finish_time_; |
72 | 82 |
73 // Indicates that the scheduler is running (i.e., that Start has been called | 83 // Indicates that the scheduler is running (i.e., that Start has been called |
74 // more recently than Stop). | 84 // more recently than Stop). |
75 bool running_; | 85 bool running_; |
76 | 86 |
77 // Indicates that the last triggered upload hasn't resolved yet. | 87 // Indicates that the last triggered upload hasn't resolved yet. |
78 bool callback_pending_; | 88 bool callback_pending_; |
79 | 89 |
80 // Whether the InitTaskComplete() callback has been called. | 90 // Whether the InitTaskComplete() callback has been called. |
81 bool init_task_complete_; | 91 bool init_task_complete_; |
82 | 92 |
83 // Whether the initial scheduled upload timer has fired before the init task | 93 // Whether the initial scheduled upload timer has fired before the init task |
84 // has been completed. | 94 // has been completed. |
85 bool waiting_for_init_task_complete_; | 95 bool waiting_for_init_task_complete_; |
86 | 96 |
97 // Pointer to |MetricsServcie::IsCellularConnection| function. | |
Alexei Svitkine (slow)
2015/02/17 20:50:04
Can you explain instead what the callback does?
gayane -on leave until 09-2017
2015/02/18 00:30:35
Done.
| |
98 base::Closure update_connection_type_func_; | |
99 | |
100 // Indicates whether network connection is cellular or not. | |
101 // Default value is |true| because cellular mode is more conservative. | |
102 bool is_cellular_connection_; | |
103 | |
87 DISALLOW_COPY_AND_ASSIGN(MetricsReportingScheduler); | 104 DISALLOW_COPY_AND_ASSIGN(MetricsReportingScheduler); |
88 }; | 105 }; |
89 | 106 |
90 } // namespace metrics | 107 } // namespace metrics |
91 | 108 |
92 #endif // COMPONENTS_METRICS_METRICS_REPORTING_SCHEDULER_H_ | 109 #endif // COMPONENTS_METRICS_METRICS_REPORTING_SCHEDULER_H_ |
OLD | NEW |