Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / metrics / metrics_reporting_scheduler.h
blob6e1d108d2be1e9bfc9fe7095be92650655491add
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_METRICS_METRICS_REPORTING_SCHEDULER_H_
6 #define CHROME_BROWSER_METRICS_METRICS_REPORTING_SCHEDULER_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/time/time.h"
12 #include "base/timer/timer.h"
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();
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();
24 // Stops scheduling uploads.
25 void Stop();
27 // Callback from MetricsService when the startup init task has completed.
28 void InitTaskComplete();
30 // Callback from MetricsService when a triggered upload finishes.
31 void UploadFinished(bool server_is_healthy, bool more_logs_remaining);
33 // Callback from MetricsService when a triggered upload is cancelled by the
34 // MetricsService.
35 void UploadCancelled();
37 // Sets the upload interval to a specific value, exposed for unit tests.
38 void SetUploadIntervalForTesting(base::TimeDelta interval);
40 private:
41 // Timer callback indicating it's time for the MetricsService to upload
42 // metrics.
43 void TriggerUpload();
45 // Schedules a future call to TriggerUpload if one isn't already pending.
46 void ScheduleNextUpload();
48 // Increases the upload interval each time it's called, to handle the case
49 // where the server is having issues.
50 void BackOffUploadInterval();
52 // The MetricsService method to call when uploading should happen.
53 const base::Closure upload_callback_;
55 base::OneShotTimer<MetricsReportingScheduler> upload_timer_;
57 // The interval between being told an upload is done and starting the next
58 // upload.
59 base::TimeDelta upload_interval_;
61 // Indicates that the scheduler is running (i.e., that Start has been called
62 // more recently than Stop).
63 bool running_;
65 // Indicates that the last triggered upload hasn't resolved yet.
66 bool callback_pending_;
68 // Whether the InitTaskComplete() callback has been called.
69 bool init_task_complete_;
71 // Whether the initial scheduled upload timer has fired before the init task
72 // has been completed.
73 bool waiting_for_init_task_complete_;
75 DISALLOW_COPY_AND_ASSIGN(MetricsReportingScheduler);
78 #endif // CHROME_BROWSER_METRICS_METRICS_REPORTING_SCHEDULER_H_