Chromium Code Reviews| 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..13f5eb37425b478edad234f55db370e8d68578e1 |
| --- /dev/null |
| +++ b/components/metrics/daily_interval.h |
| @@ -0,0 +1,62 @@ |
| +// 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 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.
|
| +// 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.
|
| +class DailyInterval { |
| +public: |
| + // Constructs DailyInterval monitor which stores the time it last fired |
| + // in the preference |pref_name|. |
| + // Caller is responsible for ensuring |pref_service| outlives the |
| + // 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.
|
| + 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); |
| + |
| + // 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. |
|
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.
|
| + 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_ |