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 firing an event about once per day, even if chrome | |
jwd
2014/08/29 15:24:16
Hmm, this implies to me that DailyInterval is caus
Steven Holte
2014/09/03 19:33:45
Done.
| |
19 // is restarted more or less frequently. | |
jwd
2014/08/29 15:24:16
Maybe mention it's based on local machine time, an
Steven Holte
2014/09/03 19:33:45
Done.
| |
20 class DailyInterval { | |
21 public: | |
22 // Constructs DailyInterval monitor which stores the time it last fired | |
23 // in the preference |pref_name|. | |
24 // Caller is responsible for ensuring |pref_service| outlives the | |
25 // DailyInterval. | |
jwd
2014/08/29 15:24:15
Mention that RegisterPref had to be called with th
Steven Holte
2014/09/03 19:33:45
Done.
| |
26 DailyInterval(PrefService* pref_service, const char* pref_name); | |
27 ~DailyInterval(); | |
28 | |
29 // Registers the preference used by this interval. | |
30 static void RegisterPref(PrefRegistrySimple* registry, const char* pref_name); | |
31 | |
32 // Adds a observer to be notified when a day elapses. All observers should | |
33 // be registered before the the DailyInterval starts checking time. | |
34 void AddObserver(DailyObserver* observer); | |
35 | |
36 // Check if a day has elapsed. | |
jwd
2014/08/29 15:24:15
Mention the event is called when the day has elaps
Steven Holte
2014/09/03 19:33:45
Done.
| |
37 void CheckInterval(); | |
38 | |
39 private: | |
40 // Handle an interval elapsing. | |
41 void OnInterval(base::Time now); | |
42 | |
43 // A weak pointer to the PrefService object to read and write preferences | |
44 // from. Calling code should ensure this object continues to exist for the | |
45 // lifetime of the DailyInterval object. | |
46 PrefService* pref_service_; | |
47 | |
48 // The name of the preference to store the last fired time in. | |
49 const char* pref_name_; | |
50 | |
51 // List of observers | |
52 ObserverList<DailyObserver> observers_; | |
53 | |
54 // True if we've started checking for events. | |
55 base::Time last_fired_; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(DailyInterval); | |
58 }; | |
59 | |
60 } // namespace metrics | |
61 | |
62 #endif // COMPONENTS_METRICS_DAILY_INTERVAL_H_ | |
OLD | NEW |