| 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..da29dbb53fbc774cbdafcb2b7bcb3b83ebf9cc26
|
| --- /dev/null
|
| +++ b/components/metrics/daily_interval.h
|
| @@ -0,0 +1,74 @@
|
| +// 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/memory/scoped_vector.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.
|
| + // |histogram_name| is the name of the UMA metric which record when this
|
| + // interval fires, and should be registered in histograms.xml
|
| + DailyInterval(PrefService* pref_service,
|
| + const char* pref_name,
|
| + const std::string& histogram_name);
|
| + ~DailyInterval();
|
| +
|
| + // Adds a observer to be notified when a day elapses. All observers should
|
| + // be registered before the the DailyInterval starts checking time.
|
| + // The interval takes ownership of all of it's observers.
|
| + void AddObserver(DailyObserver* observer);
|
| +
|
| + // Check if a day has elapsed. If it has, OnDailyInterval will be called on
|
| + // all observers.
|
| + void CheckInterval();
|
| +
|
| + // Registers the preference used by this interval.
|
| + static void RegisterPref(PrefRegistrySimple* registry, const char* pref_name);
|
| +
|
| + 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_;
|
| +
|
| + // The name of the histogram to record intervals.
|
| + std::string histogram_name_;
|
| +
|
| + // List of observers
|
| + ScopedVector<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_
|
|
|