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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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.
4
5 #ifndef COMPONENTS_METRICS_DAILY_INTERVAL_H_
6 #define COMPONENTS_METRICS_DAILY_INTERVAL_H_
7
8 #include "base/macros.h"
9 #include "base/memory/scoped_vector.h"
10 #include "base/time/time.h"
11 #include "components/metrics/daily_observer.h"
12
13 class PrefRegistrySimple;
14 class PrefService;
15
16 namespace metrics {
17
18 // DailyInterval is used for throttling an event to about once per day, even if
19 // chrome is restarted more frequently. It is based on local machine time, so
20 // it could be fired more often if the clock is changed.
21 class DailyInterval {
22 public:
23 // Constructs DailyInterval monitor which stores the time it last fired
24 // in the preference |pref_name|.
25 // |pref_name| should be registered by calling RegisterPref before using this
26 // object.
27 // Caller is responsible for ensuring |pref_service| outlives the
28 // DailyInterval.
29 // |histogram_name| is the name of the UMA metric which record when this
30 // interval fires, and should be registered in histograms.xml
31 DailyInterval(PrefService* pref_service,
32 const char* pref_name,
33 const std::string& histogram_name);
34 ~DailyInterval();
35
36 // Adds a observer to be notified when a day elapses. All observers should
37 // be registered before the the DailyInterval starts checking time.
38 // The interval takes ownership of all of it's observers.
39 void AddObserver(DailyObserver* observer);
40
41 // Check if a day has elapsed. If it has, OnDailyInterval will be called on
42 // all observers.
43 void CheckInterval();
44
45 // Registers the preference used by this interval.
46 static void RegisterPref(PrefRegistrySimple* registry, const char* pref_name);
47
48 private:
49 // Handle an interval elapsing.
50 void OnInterval(base::Time now);
51
52 // A weak pointer to the PrefService object to read and write preferences
53 // from. Calling code should ensure this object continues to exist for the
54 // lifetime of the DailyInterval object.
55 PrefService* pref_service_;
56
57 // The name of the preference to store the last fired time in.
58 const char* pref_name_;
59
60 // The name of the histogram to record intervals.
61 std::string histogram_name_;
62
63 // List of observers
64 ScopedVector<DailyObserver> observers_;
65
66 // True if we've started checking for events.
67 base::Time last_fired_;
68
69 DISALLOW_COPY_AND_ASSIGN(DailyInterval);
70 };
71
72 } // namespace metrics
73
74 #endif // COMPONENTS_METRICS_DAILY_INTERVAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698