Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2088)

Side by Side Diff: chrome/browser/extensions/api/alarms/alarm_manager.h

Issue 299393002: Use ExtensionRegistryObserver instead of deprecated extension notification from c/b/extension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/api/alarms/alarm_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/scoped_observer.h" 15 #include "base/scoped_observer.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "chrome/common/extensions/api/alarms.h" 17 #include "chrome/common/extensions/api/alarms.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20 #include "extensions/browser/browser_context_keyed_api_factory.h" 18 #include "extensions/browser/browser_context_keyed_api_factory.h"
21 #include "extensions/browser/extension_function.h"
22 #include "extensions/browser/extension_registry_observer.h" 19 #include "extensions/browser/extension_registry_observer.h"
23 20
24 namespace base { 21 namespace base {
25 class Clock; 22 class Clock;
26 } // namespace base 23 } // namespace base
27 24
28 namespace content { 25 namespace content {
29 class BrowserContext; 26 class BrowserContext;
30 } // namespace content 27 } // namespace content
31 28
(...skipping 17 matching lines...) Expand all
49 // constructor argument. 46 // constructor argument.
50 base::TimeDelta granularity; 47 base::TimeDelta granularity;
51 // The minimum granularity is the minimum allowed polling rate. This stops 48 // The minimum granularity is the minimum allowed polling rate. This stops
52 // alarms from polling too often. 49 // alarms from polling too often.
53 base::TimeDelta minimum_granularity; 50 base::TimeDelta minimum_granularity;
54 }; 51 };
55 52
56 // Manages the currently pending alarms for every extension in a profile. 53 // Manages the currently pending alarms for every extension in a profile.
57 // There is one manager per virtual Profile. 54 // There is one manager per virtual Profile.
58 class AlarmManager : public BrowserContextKeyedAPI, 55 class AlarmManager : public BrowserContextKeyedAPI,
59 public content::NotificationObserver,
60 public ExtensionRegistryObserver, 56 public ExtensionRegistryObserver,
61 public base::SupportsWeakPtr<AlarmManager> { 57 public base::SupportsWeakPtr<AlarmManager> {
62 public: 58 public:
63 typedef std::vector<Alarm> AlarmList; 59 typedef std::vector<Alarm> AlarmList;
64 60
65 class Delegate { 61 class Delegate {
66 public: 62 public:
67 virtual ~Delegate() {} 63 virtual ~Delegate() {}
68 // Called when an alarm fires. 64 // Called when an alarm fires.
69 virtual void OnAlarm(const std::string& extension_id, 65 virtual void OnAlarm(const std::string& extension_id,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 void ScheduleNextPoll(); 193 void ScheduleNextPoll();
198 194
199 // Polls the alarms, running any that have elapsed. After running them and 195 // Polls the alarms, running any that have elapsed. After running them and
200 // rescheduling repeating alarms, schedule the next poll. 196 // rescheduling repeating alarms, schedule the next poll.
201 void PollAlarms(); 197 void PollAlarms();
202 198
203 // Executes |action| for given extension, making sure that the extension's 199 // Executes |action| for given extension, making sure that the extension's
204 // alarm data has been synced from the storage. 200 // alarm data has been synced from the storage.
205 void RunWhenReady(const std::string& extension_id, const ReadyAction& action); 201 void RunWhenReady(const std::string& extension_id, const ReadyAction& action);
206 202
207 // NotificationObserver: 203 // ExtensionRegistryObserver implementation.
208 virtual void Observe(int type,
209 const content::NotificationSource& source,
210 const content::NotificationDetails& details) OVERRIDE;
211
212 // Overridden from extensions::ExtensionRegistryObserver.
213 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, 204 virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
214 const Extension* extension) OVERRIDE; 205 const Extension* extension) OVERRIDE;
206 virtual void OnExtensionUninstalled(content::BrowserContext* browser_context,
207 const Extension* extension) OVERRIDE;
215 208
216 // BrowserContextKeyedAPI implementation. 209 // BrowserContextKeyedAPI implementation.
217 static const char* service_name() { 210 static const char* service_name() {
218 return "AlarmManager"; 211 return "AlarmManager";
219 } 212 }
220 static const bool kServiceHasOwnInstanceInIncognito = true; 213 static const bool kServiceHasOwnInstanceInIncognito = true;
221 214
222 content::BrowserContext* const browser_context_; 215 content::BrowserContext* const browser_context_;
223 scoped_ptr<base::Clock> clock_; 216 scoped_ptr<base::Clock> clock_;
224 content::NotificationRegistrar registrar_;
225 scoped_ptr<Delegate> delegate_; 217 scoped_ptr<Delegate> delegate_;
226 218
227 // Listen to extension load notifications. 219 // Listen to extension load notifications.
228 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> 220 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
229 extension_registry_observer_; 221 extension_registry_observer_;
230 222
231 // The timer for this alarm manager. 223 // The timer for this alarm manager.
232 base::OneShotTimer<AlarmManager> timer_; 224 base::OneShotTimer<AlarmManager> timer_;
233 225
234 // A map of our pending alarms, per extension. 226 // A map of our pending alarms, per extension.
235 // Invariant: None of the AlarmLists are empty. 227 // Invariant: None of the AlarmLists are empty.
236 AlarmMap alarms_; 228 AlarmMap alarms_;
237 229
238 // A map of actions waiting for alarm data to be synced from storage, per 230 // A map of actions waiting for alarm data to be synced from storage, per
239 // extension. 231 // extension.
240 ReadyMap ready_actions_; 232 ReadyMap ready_actions_;
241 233
242 // The previous time that alarms were run. 234 // The previous time that alarms were run.
243 base::Time last_poll_time_; 235 base::Time last_poll_time_;
244 236
245 // Next poll's time. 237 // Next poll's time.
246 base::Time next_poll_time_; 238 base::Time next_poll_time_;
247 239
248 DISALLOW_COPY_AND_ASSIGN(AlarmManager); 240 DISALLOW_COPY_AND_ASSIGN(AlarmManager);
249 }; 241 };
250 242
251 } // namespace extensions 243 } // namespace extensions
252 244
253 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__ 245 #endif // CHROME_BROWSER_EXTENSIONS_API_ALARMS_ALARM_MANAGER_H__
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/alarms/alarm_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698