[email protected] | 39d1002 | 2012-03-02 16:04:46 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_METRICS_METRICS_REPORTING_SCHEDULER_H_ |
| 6 | #define CHROME_BROWSER_METRICS_METRICS_REPORTING_SCHEDULER_H_ |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 7 | |
| 8 | #include "base/basictypes.h" |
| 9 | #include "base/callback.h" |
[email protected] | 8454aeb | 2011-11-19 23:38:20 | [diff] [blame] | 10 | #include "base/memory/weak_ptr.h" |
[email protected] | c62dd9d | 2011-09-21 18:05:41 | [diff] [blame] | 11 | #include "base/time.h" |
[email protected] | 39d1002 | 2012-03-02 16:04:46 | [diff] [blame] | 12 | #include "base/timer.h" |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 13 | |
| 14 | // Scheduler task to drive a MetricsService object's uploading. |
| 15 | class MetricsReportingScheduler { |
| 16 | public: |
| 17 | explicit MetricsReportingScheduler(const base::Closure& upload_callback); |
| 18 | ~MetricsReportingScheduler(); |
| 19 | |
| 20 | // Starts scheduling uploads. This in a no-op if the scheduler is already |
| 21 | // running, so it is safe to call more than once. |
| 22 | void Start(); |
| 23 | |
| 24 | // Stops scheduling uploads. |
| 25 | void Stop(); |
| 26 | |
| 27 | // Callback from MetricsService when a triggered upload finishes. |
| 28 | void UploadFinished(bool server_is_healthy, bool more_logs_remaining); |
| 29 | |
| 30 | // Callback from MetricsService when a triggered upload is cancelled by the |
| 31 | // MetricsService. |
| 32 | void UploadCancelled(); |
| 33 | |
| 34 | private: |
| 35 | // Timer callback indicating it's time for the MetricsService to upload |
| 36 | // metrics. |
| 37 | void TriggerUpload(); |
| 38 | |
| 39 | // Schedules a future call to TriggerUpload if one isn't already pending. |
[email protected] | e28c31db | 2012-06-11 22:53:11 | [diff] [blame] | 40 | void ScheduleNextUpload(); |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 41 | |
| 42 | // Increases the upload interval each time it's called, to handle the case |
| 43 | // where the server is having issues. |
| 44 | void BackOffUploadInterval(); |
| 45 | |
| 46 | // The MetricsService method to call when uploading should happen. |
[email protected] | e28c31db | 2012-06-11 22:53:11 | [diff] [blame] | 47 | const base::Closure upload_callback_; |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 48 | |
[email protected] | 39d1002 | 2012-03-02 16:04:46 | [diff] [blame] | 49 | base::OneShotTimer<MetricsReportingScheduler> upload_timer_; |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 50 | |
| 51 | // The interval between being told an upload is done and starting the next |
| 52 | // upload. |
| 53 | base::TimeDelta upload_interval_; |
| 54 | |
| 55 | // Indicates that the scheduler is running (i.e., that Start has been called |
| 56 | // more recently than Stop). |
| 57 | bool running_; |
| 58 | |
[email protected] | 7f7f196 | 2011-04-20 15:58:16 | [diff] [blame] | 59 | // Indicates that the last triggered upload hasn't resolved yet. |
| 60 | bool callback_pending_; |
| 61 | |
| 62 | DISALLOW_COPY_AND_ASSIGN(MetricsReportingScheduler); |
| 63 | }; |
| 64 | |
| 65 | #endif // CHROME_BROWSER_METRICS_METRICS_REPORTING_SCHEDULER_H_ |