Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Unified Diff: chrome/browser/metrics/metrics_reporting_scheduler.h

Issue 6869034: Factor a scheduler object out of MetricsService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to trunk Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/metrics/metrics_reporting_scheduler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/metrics/metrics_reporting_scheduler.h
diff --git a/chrome/browser/metrics/metrics_reporting_scheduler.h b/chrome/browser/metrics/metrics_reporting_scheduler.h
new file mode 100644
index 0000000000000000000000000000000000000000..7774ec53e1794299d57d7dbfd894cb0f28194c09
--- /dev/null
+++ b/chrome/browser/metrics/metrics_reporting_scheduler.h
@@ -0,0 +1,68 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_METRICS_METRICS_REPORTING_SCHEDULER_H_
+#define CHROME_BROWSER_METRICS_METRICS_REPORTING_SCHEDULER_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/task.h"
+
+// Scheduler task to drive a MetricsService object's uploading.
+class MetricsReportingScheduler {
+ public:
+ explicit MetricsReportingScheduler(const base::Closure& upload_callback);
+ ~MetricsReportingScheduler();
+
+ // Starts scheduling uploads. This in a no-op if the scheduler is already
+ // running, so it is safe to call more than once.
+ void Start();
+
+ // Stops scheduling uploads.
+ void Stop();
+
+ // Callback from MetricsService when a triggered upload finishes.
+ void UploadFinished(bool server_is_healthy, bool more_logs_remaining);
+
+ // Callback from MetricsService when a triggered upload is cancelled by the
+ // MetricsService.
+ void UploadCancelled();
+
+ private:
+ // Timer callback indicating it's time for the MetricsService to upload
+ // metrics.
+ void TriggerUpload();
+
+ // Schedules a future call to TriggerUpload if one isn't already pending.
+ void ScheduleNextCallback();
+
+ // Increases the upload interval each time it's called, to handle the case
+ // where the server is having issues.
+ void BackOffUploadInterval();
+
+ // The MetricsService method to call when uploading should happen.
+ base::Closure upload_callback_;
+
+ ScopedRunnableMethodFactory<MetricsReportingScheduler> upload_timer_factory_;
+
+ // The interval between being told an upload is done and starting the next
+ // upload.
+ base::TimeDelta upload_interval_;
+
+ // Indicates that the scheduler is running (i.e., that Start has been called
+ // more recently than Stop).
+ bool running_;
+
+ // Indicates that a timer for triggering the next upload has already been
+ // started.
+ bool timer_pending_;
+
+ // Indicates that the last triggered upload hasn't resolved yet.
+ bool callback_pending_;
+
+ DISALLOW_COPY_AND_ASSIGN(MetricsReportingScheduler);
+};
+
+#endif // CHROME_BROWSER_METRICS_METRICS_REPORTING_SCHEDULER_H_
« no previous file with comments | « no previous file | chrome/browser/metrics/metrics_reporting_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698