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

Unified Diff: components/metrics/daily_interval.h

Issue 511623002: Add a mechanism for collecting Rappor samples on a daily interval. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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: components/metrics/daily_interval.h
diff --git a/components/metrics/daily_interval.h b/components/metrics/daily_interval.h
new file mode 100644
index 0000000000000000000000000000000000000000..f208a2ab965275159a107ab7831115a734f1b0a2
--- /dev/null
+++ b/components/metrics/daily_interval.h
@@ -0,0 +1,66 @@
+// Copyright 2014 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 COMPONENTS_METRICS_DAILY_INTERVAL_H_
+#define COMPONENTS_METRICS_DAILY_INTERVAL_H_
+
+#include "base/macros.h"
+#include "base/observer_list.h"
+#include "base/time/time.h"
+#include "components/metrics/daily_observer.h"
+
+class PrefRegistrySimple;
+class PrefService;
+
+namespace metrics {
+
+// DailyInterval is used for throttling an event to about once per day, even if
+// chrome is restarted more frequently. It is based on local machine time, so
+// it could be fired more often if the clock is changed.
+class DailyInterval {
+ public:
+ // Constructs DailyInterval monitor which stores the time it last fired
+ // in the preference |pref_name|.
+ // |pref_name| should be registered by calling RegisterPref before using this
+ // object.
+ // Caller is responsible for ensuring |pref_service| outlives the
+ // DailyInterval.
+ DailyInterval(PrefService* pref_service, const char* pref_name);
+ ~DailyInterval();
+
+ // Registers the preference used by this interval.
+ static void RegisterPref(PrefRegistrySimple* registry, const char* pref_name);
Alexei Svitkine (slow) 2014/09/08 15:34:20 Nit: I think in other metrics files we order stati
Steven Holte 2014/09/12 21:23:31 Done.
+
+ // Adds a observer to be notified when a day elapses. All observers should
+ // be registered before the the DailyInterval starts checking time.
+ void AddObserver(DailyObserver* observer);
+
+ // Check if a day has elapsed. If it has, OnDailyInterval will be called on
+ // all observers.
+ void CheckInterval();
+
+ private:
+ // Handle an interval elapsing.
+ void OnInterval(base::Time now);
+
+ // A weak pointer to the PrefService object to read and write preferences
+ // from. Calling code should ensure this object continues to exist for the
+ // lifetime of the DailyInterval object.
+ PrefService* pref_service_;
+
+ // The name of the preference to store the last fired time in.
+ const char* pref_name_;
+
+ // List of observers
+ ObserverList<DailyObserver> observers_;
+
+ // True if we've started checking for events.
+ base::Time last_fired_;
+
+ DISALLOW_COPY_AND_ASSIGN(DailyInterval);
+};
+
+} // namespace metrics
+
+#endif // COMPONENTS_METRICS_DAILY_INTERVAL_H_

Powered by Google App Engine
This is Rietveld 408576698