| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 class Delegate { | 62 class Delegate { |
| 63 public: | 63 public: |
| 64 virtual ~Delegate() {} | 64 virtual ~Delegate() {} |
| 65 // Called when an alarm fires. | 65 // Called when an alarm fires. |
| 66 virtual void OnAlarm(const std::string& extension_id, | 66 virtual void OnAlarm(const std::string& extension_id, |
| 67 const Alarm& alarm) = 0; | 67 const Alarm& alarm) = 0; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 explicit AlarmManager(content::BrowserContext* context); | 70 explicit AlarmManager(content::BrowserContext* context); |
| 71 virtual ~AlarmManager(); | 71 ~AlarmManager() override; |
| 72 | 72 |
| 73 // Override the default delegate. Callee assumes onwership. Used for testing. | 73 // Override the default delegate. Callee assumes onwership. Used for testing. |
| 74 void set_delegate(Delegate* delegate) { delegate_.reset(delegate); } | 74 void set_delegate(Delegate* delegate) { delegate_.reset(delegate); } |
| 75 | 75 |
| 76 typedef base::Callback<void()> AddAlarmCallback; | 76 typedef base::Callback<void()> AddAlarmCallback; |
| 77 // Adds |alarm| for the given extension, and starts the timer. Invokes | 77 // Adds |alarm| for the given extension, and starts the timer. Invokes |
| 78 // |callback| when done. | 78 // |callback| when done. |
| 79 void AddAlarm(const std::string& extension_id, | 79 void AddAlarm(const std::string& extension_id, |
| 80 const Alarm& alarm, | 80 const Alarm& alarm, |
| 81 const AddAlarmCallback& callback); | 81 const AddAlarmCallback& callback); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 // Polls the alarms, running any that have elapsed. After running them and | 196 // Polls the alarms, running any that have elapsed. After running them and |
| 197 // rescheduling repeating alarms, schedule the next poll. | 197 // rescheduling repeating alarms, schedule the next poll. |
| 198 void PollAlarms(); | 198 void PollAlarms(); |
| 199 | 199 |
| 200 // Executes |action| for given extension, making sure that the extension's | 200 // Executes |action| for given extension, making sure that the extension's |
| 201 // alarm data has been synced from the storage. | 201 // alarm data has been synced from the storage. |
| 202 void RunWhenReady(const std::string& extension_id, const ReadyAction& action); | 202 void RunWhenReady(const std::string& extension_id, const ReadyAction& action); |
| 203 | 203 |
| 204 // ExtensionRegistryObserver implementation. | 204 // ExtensionRegistryObserver implementation. |
| 205 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, | 205 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 206 const Extension* extension) override; | 206 const Extension* extension) override; |
| 207 virtual void OnExtensionUninstalled( | 207 void OnExtensionUninstalled(content::BrowserContext* browser_context, |
| 208 content::BrowserContext* browser_context, | 208 const Extension* extension, |
| 209 const Extension* extension, | 209 extensions::UninstallReason reason) override; |
| 210 extensions::UninstallReason reason) override; | |
| 211 | 210 |
| 212 // BrowserContextKeyedAPI implementation. | 211 // BrowserContextKeyedAPI implementation. |
| 213 static const char* service_name() { | 212 static const char* service_name() { |
| 214 return "AlarmManager"; | 213 return "AlarmManager"; |
| 215 } | 214 } |
| 216 static const bool kServiceHasOwnInstanceInIncognito = true; | 215 static const bool kServiceHasOwnInstanceInIncognito = true; |
| 217 | 216 |
| 218 content::BrowserContext* const browser_context_; | 217 content::BrowserContext* const browser_context_; |
| 219 scoped_ptr<base::Clock> clock_; | 218 scoped_ptr<base::Clock> clock_; |
| 220 scoped_ptr<Delegate> delegate_; | 219 scoped_ptr<Delegate> delegate_; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 239 | 238 |
| 240 // Next poll's time. | 239 // Next poll's time. |
| 241 base::Time next_poll_time_; | 240 base::Time next_poll_time_; |
| 242 | 241 |
| 243 DISALLOW_COPY_AND_ASSIGN(AlarmManager); | 242 DISALLOW_COPY_AND_ASSIGN(AlarmManager); |
| 244 }; | 243 }; |
| 245 | 244 |
| 246 } // namespace extensions | 245 } // namespace extensions |
| 247 | 246 |
| 248 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ | 247 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ |
| OLD | NEW |