OLD | NEW |
---|---|
(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/observer_list.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: | |
Alexei Svitkine (slow)
2014/09/05 20:00:33
Nit: Indent 1 more, here and private below.
Steven Holte
2014/09/05 21:15:07
Done.
| |
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 DailyInterval(PrefService* pref_service, const char* pref_name); | |
30 ~DailyInterval(); | |
31 | |
32 // Registers the preference used by this interval. | |
33 static void RegisterPref(PrefRegistrySimple* registry, const char* pref_name); | |
34 | |
35 // Adds a observer to be notified when a day elapses. All observers should | |
36 // be registered before the the DailyInterval starts checking time. | |
37 void AddObserver(DailyObserver* observer); | |
38 | |
39 // Check if a day has elapsed. If it has, OnDailyInterval will be called on | |
40 // all observers. | |
41 void CheckInterval(); | |
42 | |
43 private: | |
44 // Handle an interval elapsing. | |
45 void OnInterval(base::Time now); | |
46 | |
47 // A weak pointer to the PrefService object to read and write preferences | |
48 // from. Calling code should ensure this object continues to exist for the | |
49 // lifetime of the DailyInterval object. | |
50 PrefService* pref_service_; | |
51 | |
52 // The name of the preference to store the last fired time in. | |
53 const char* pref_name_; | |
54 | |
55 // List of observers | |
56 ObserverList<DailyObserver> observers_; | |
57 | |
58 // True if we've started checking for events. | |
59 base::Time last_fired_; | |
60 | |
61 DISALLOW_COPY_AND_ASSIGN(DailyInterval); | |
62 }; | |
63 | |
64 } // namespace metrics | |
65 | |
66 #endif // COMPONENTS_METRICS_DAILY_INTERVAL_H_ | |
OLD | NEW |