Chromium Code Reviews| 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 0e2bd002d4f80aabf1d290c5105aa0c91ce11c1d..5e19067dd7fe0c77a9fbaf7e9bd74ab4309ee78e 100644 |
| --- a/chrome/browser/extensions/api/alarms/alarm_manager.h |
| +++ b/chrome/browser/extensions/api/alarms/alarm_manager.h |
| @@ -11,6 +11,7 @@ |
| #include "base/memory/weak_ptr.h" |
| #include "base/timer.h" |
| +#include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
| #include "chrome/browser/extensions/extension_function.h" |
| #include "chrome/common/extensions/api/alarms.h" |
| #include "content/public/browser/notification_observer.h" |
| @@ -47,7 +48,8 @@ struct Alarm { |
| // There is one manager per virtual Profile. |
| class AlarmManager |
| : public content::NotificationObserver, |
| - public base::SupportsWeakPtr<AlarmManager> { |
| + public base::SupportsWeakPtr<AlarmManager>, |
| + public ProfileKeyedAPI { |
|
Devlin
2013/04/17 01:30:59
Nit: this is the most important inheritance; put i
Patrick Riordan
2013/04/17 03:40:39
Done.
|
| public: |
| typedef std::vector<Alarm> AlarmList; |
| @@ -59,9 +61,7 @@ class AlarmManager |
| const Alarm& alarm) = 0; |
| }; |
| - // |clock| is usually a base::DefaultClock, but can be something |
| - // else for testing. |
| - explicit AlarmManager(Profile* profile, base::Clock* clock); |
| + explicit AlarmManager(Profile* profile); |
| virtual ~AlarmManager(); |
| // Override the default delegate. Callee assumes onwership. Used for testing. |
| @@ -86,6 +86,15 @@ class AlarmManager |
| // Cancels and removes all alarms for the given extension. |
| void RemoveAllAlarms(const std::string& extension_id); |
| + // Deletes AlarmManager's owned clock and replaces it with |clock|. |
| + void SetClockForTesting(base::Clock* clock); |
| + |
| + // ProfileKeyedAPI implementation. |
| + static ProfileKeyedAPIFactory<AlarmManager>* GetFactoryInstance(); |
| + |
| + // Convenience method to get the AlarmManager for a profile. |
| + static AlarmManager* Get(Profile* profile); |
| + |
| private: |
| FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsTest, CreateRepeating); |
| FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsTest, Clear); |
| @@ -94,6 +103,7 @@ class AlarmManager |
| FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, |
| ReleasedExtensionPollsInfrequently); |
| FRIEND_TEST_ALL_PREFIXES(ExtensionAlarmsSchedulingTest, TimerRunning); |
| + friend class ProfileKeyedAPIFactory<AlarmManager>; |
| typedef std::string ExtensionId; |
| typedef std::map<ExtensionId, AlarmList> AlarmMap; |
| @@ -137,8 +147,16 @@ class AlarmManager |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) OVERRIDE; |
| + // ProfileKeyedAPI implementation. |
| + static const char* service_name() { |
| + return "AlarmManager"; |
| + } |
| + |
| Profile* const profile_; |
| - base::Clock* const clock_; |
| + base::Clock* clock_; |
| + // Whether or not we own |clock_|. When it's passed in for testing |
| + // this is false. |
| + bool owns_clock_; |
|
Devlin
2013/04/17 01:30:59
This is bad. What if we instead have AlarmManager
Patrick Riordan
2013/04/17 03:40:39
Done.
|
| content::NotificationRegistrar registrar_; |
| scoped_ptr<Delegate> delegate_; |