| Index: chrome/browser/extensions/api/alarms/alarm_manager.h
|
| diff --git a/chrome/browser/extensions/api/alarms/alarm_manager.h b/chrome/browser/extensions/api/alarms/alarm_manager.h
|
| index 775fd1e4e0b23ac983edf082d69c0128bb5b245b..ddac1b896390213d3665f2dd37e1ef2227c1875f 100644
|
| --- a/chrome/browser/extensions/api/alarms/alarm_manager.h
|
| +++ b/chrome/browser/extensions/api/alarms/alarm_manager.h
|
| @@ -13,6 +13,8 @@
|
| #include "base/timer.h"
|
| #include "chrome/browser/extensions/extension_function.h"
|
| #include "chrome/common/extensions/api/experimental.alarms.h"
|
| +#include "content/public/browser/notification_observer.h"
|
| +#include "content/public/browser/notification_registrar.h"
|
|
|
| class Profile;
|
|
|
| @@ -20,7 +22,7 @@ namespace extensions {
|
|
|
| // Manages the currently pending alarms for every extension in a profile.
|
| // There is one manager per virtual Profile.
|
| -class AlarmManager {
|
| +class AlarmManager : public content::NotificationObserver {
|
| public:
|
| typedef extensions::api::experimental_alarms::Alarm Alarm;
|
| typedef std::vector<linked_ptr<Alarm> > AlarmList;
|
| @@ -66,6 +68,9 @@ class AlarmManager {
|
| // "Not found" is represented by <alarms_.end(), invalid_iterator>.
|
| typedef std::pair<AlarmMap::iterator, AlarmList::iterator> AlarmIterator;
|
|
|
| + // The timer associated with an alarm.
|
| + struct TimerInfo;
|
| +
|
| // Helper to return the iterators within the AlarmMap and AlarmList for the
|
| // matching alarm, or an iterator to the end of the AlarmMap if none were
|
| // found.
|
| @@ -79,14 +84,38 @@ class AlarmManager {
|
| // Callback for when an alarm fires.
|
| void OnAlarm(const std::string& extension_id, const std::string& name);
|
|
|
| + // Internal helper to add an alarm and start the timer with the given delay.
|
| + void AddAlarmImpl(const std::string& extension_id,
|
| + const linked_ptr<Alarm>& alarm,
|
| + base::TimeDelta timer_delay);
|
| +
|
| + // Syncs our alarm data for the given extension to/from the prefs file.
|
| + void WriteToPrefs(const std::string& extension_id);
|
| + void ReadFromPrefs(const std::string& extension_id);
|
| +
|
| + // NotificationObserver:
|
| + virtual void Observe(int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) OVERRIDE;
|
| +
|
| Profile* profile_;
|
| + content::NotificationRegistrar registrar_;
|
| scoped_ptr<Delegate> delegate_;
|
|
|
| // A map of our pending alarms, per extension.
|
| AlarmMap alarms_;
|
|
|
| // A map of the timer associated with each alarm.
|
| - std::map<const Alarm*, linked_ptr<base::Timer> > timers_;
|
| + std::map<const Alarm*, linked_ptr<TimerInfo> > timers_;
|
| +};
|
| +
|
| +// Contains the data we store in the extension prefs for each alarm.
|
| +struct AlarmPref {
|
| + linked_ptr<AlarmManager::Alarm> alarm;
|
| + base::Time scheduled_run_time;
|
| +
|
| + AlarmPref();
|
| + ~AlarmPref();
|
| };
|
|
|
| } // namespace extensions
|
|
|