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

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: Comment fix 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
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..adf3cd5ca81051a6ceee649683a49b49cf30afe0
--- /dev/null
+++ b/chrome/browser/metrics/metrics_reporting_scheduler.h
@@ -0,0 +1,69 @@
+// 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/task.h"
+
+class MetricsService;
+
+// Scheduler task to drive a MetricsService object's uploading.
+class MetricsReportingScheduler {
+ public:
+ explicit MetricsReportingScheduler(MetricsService* metrics_service);
+ virtual ~MetricsReportingScheduler();
jar (doing other things) 2011/04/16 02:03:13 Why the virtual destructor? There is no base, and
stuartmorgan 2011/04/18 17:03:00 Just habit; removed.
+
+ // 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();
+
+ // Weak reference to the MetricsService being scheduled.
+ MetricsService* metrics_service_;
+
+ 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_

Powered by Google App Engine
This is Rietveld 408576698