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 // Creates MetricsServiceScheduler object with the given |upload_callback| |
21 // callback to call when uploading should happen and |cellular_callback| | |
22 // callback to get current network connection type. | |
23 MetricsReportingScheduler( | |
24 const base::Closure& upload_callback, | |
25 const base::Callback<void(bool*)>& cellular_callback); | |
20 ~MetricsReportingScheduler(); | 26 ~MetricsReportingScheduler(); |
21 | 27 |
22 // Starts scheduling uploads. This in a no-op if the scheduler is already | 28 // Starts scheduling uploads. This in a no-op if the scheduler is already |
23 // running, so it is safe to call more than once. | 29 // running, so it is safe to call more than once. |
24 void Start(); | 30 void Start(); |
25 | 31 |
26 // Stops scheduling uploads. | 32 // Stops scheduling uploads. |
27 void Stop(); | 33 void Stop(); |
28 | 34 |
29 // Callback from MetricsService when the startup init task has completed. | 35 // Callback from MetricsService when the startup init task has completed. |
30 void InitTaskComplete(); | 36 void InitTaskComplete(); |
31 | 37 |
32 // Callback from MetricsService when a triggered upload finishes. | 38 // Callback from MetricsService when a triggered upload finishes. |
33 void UploadFinished(bool server_is_healthy, bool more_logs_remaining); | 39 void UploadFinished(bool server_is_healthy, bool more_logs_remaining); |
34 | 40 |
35 // Callback from MetricsService when a triggered upload is cancelled by the | 41 // Callback from MetricsService when a triggered upload is cancelled by the |
36 // MetricsService. | 42 // MetricsService. |
37 void UploadCancelled(); | 43 void UploadCancelled(); |
38 | 44 |
39 // Sets the upload interval to a specific value, exposed for unit tests. | 45 // Sets the upload interval to a specific value, exposed for unit tests. |
40 void SetUploadIntervalForTesting(base::TimeDelta interval); | 46 void SetUploadIntervalForTesting(base::TimeDelta interval); |
41 | 47 |
48 // Sets whether the network connection is cellular or not. | |
49 void SetConnectionType(bool is_cellular); | |
Alexei Svitkine (slow)
2015/02/18 22:03:09
Is this needed anymore?
gayane -on leave until 09-2017
2015/02/19 16:24:35
Removed.
| |
50 | |
42 private: | 51 private: |
43 // Timer callback indicating it's time for the MetricsService to upload | 52 // Timer callback indicating it's time for the MetricsService to upload |
44 // metrics. | 53 // metrics. |
45 void TriggerUpload(); | 54 void TriggerUpload(); |
46 | 55 |
47 // Schedules a future call to TriggerUpload if one isn't already pending. | 56 // Schedules a future call to TriggerUpload if one isn't already pending. |
48 void ScheduleNextUpload(); | 57 void ScheduleNextUpload(); |
49 | 58 |
50 // Increases the upload interval each time it's called, to handle the case | 59 // Increases the upload interval each time it's called, to handle the case |
51 // where the server is having issues. | 60 // where the server is having issues. |
(...skipping 25 matching lines...) Expand all Loading... | |
77 // Indicates that the last triggered upload hasn't resolved yet. | 86 // Indicates that the last triggered upload hasn't resolved yet. |
78 bool callback_pending_; | 87 bool callback_pending_; |
79 | 88 |
80 // Whether the InitTaskComplete() callback has been called. | 89 // Whether the InitTaskComplete() callback has been called. |
81 bool init_task_complete_; | 90 bool init_task_complete_; |
82 | 91 |
83 // Whether the initial scheduled upload timer has fired before the init task | 92 // Whether the initial scheduled upload timer has fired before the init task |
84 // has been completed. | 93 // has been completed. |
85 bool waiting_for_init_task_complete_; | 94 bool waiting_for_init_task_complete_; |
86 | 95 |
96 // Callback function from MetricsService used to get current network | |
Alexei Svitkine (slow)
2015/02/18 22:03:09
Don't say "from MetricsService" - just what it's f
gayane -on leave until 09-2017
2015/02/19 16:24:35
Done.
| |
97 // connection type. | |
98 base::Callback<void(bool*)> cellular_callback_; | |
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_; | |
Alexei Svitkine (slow)
2015/02/18 22:03:08
This isn't needed anymore, right?
gayane -on leave until 09-2017
2015/02/19 16:24:35
Done.
| |
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 |