OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ | 5 #ifndef EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ |
6 #define EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ | 6 #define EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 // the page when the first task is queued. | 31 // the page when the first task is queued. |
32 // | 32 // |
33 // It is the consumer's responsibility to use this class when appropriate, i.e. | 33 // It is the consumer's responsibility to use this class when appropriate, i.e. |
34 // only with extensions that have not-yet-loaded lazy background pages. | 34 // only with extensions that have not-yet-loaded lazy background pages. |
35 class LazyBackgroundTaskQueue : public content::NotificationObserver, | 35 class LazyBackgroundTaskQueue : public content::NotificationObserver, |
36 public ExtensionRegistryObserver { | 36 public ExtensionRegistryObserver { |
37 public: | 37 public: |
38 typedef base::Callback<void(ExtensionHost*)> PendingTask; | 38 typedef base::Callback<void(ExtensionHost*)> PendingTask; |
39 | 39 |
40 explicit LazyBackgroundTaskQueue(content::BrowserContext* browser_context); | 40 explicit LazyBackgroundTaskQueue(content::BrowserContext* browser_context); |
41 virtual ~LazyBackgroundTaskQueue(); | 41 ~LazyBackgroundTaskQueue() override; |
42 | 42 |
43 // Returns the number of extensions having pending tasks. | 43 // Returns the number of extensions having pending tasks. |
44 size_t extensions_with_pending_tasks() { return pending_tasks_.size(); } | 44 size_t extensions_with_pending_tasks() { return pending_tasks_.size(); } |
45 | 45 |
46 // Returns true if the task should be added to the queue (that is, if the | 46 // Returns true if the task should be added to the queue (that is, if the |
47 // extension has a lazy background page that isn't ready yet). If the | 47 // extension has a lazy background page that isn't ready yet). If the |
48 // extension has a lazy background page that is being suspended this method | 48 // extension has a lazy background page that is being suspended this method |
49 // cancels that suspension. | 49 // cancels that suspension. |
50 bool ShouldEnqueueTask(content::BrowserContext* context, | 50 bool ShouldEnqueueTask(content::BrowserContext* context, |
51 const Extension* extension); | 51 const Extension* extension); |
(...skipping 13 matching lines...) Expand all Loading... |
65 | 65 |
66 // A map between a BrowserContext/extension_id pair and the queue of tasks | 66 // A map between a BrowserContext/extension_id pair and the queue of tasks |
67 // pending the load of its background page. | 67 // pending the load of its background page. |
68 typedef std::string ExtensionID; | 68 typedef std::string ExtensionID; |
69 typedef std::pair<content::BrowserContext*, ExtensionID> PendingTasksKey; | 69 typedef std::pair<content::BrowserContext*, ExtensionID> PendingTasksKey; |
70 typedef std::vector<PendingTask> PendingTasksList; | 70 typedef std::vector<PendingTask> PendingTasksList; |
71 typedef std::map<PendingTasksKey, | 71 typedef std::map<PendingTasksKey, |
72 linked_ptr<PendingTasksList> > PendingTasksMap; | 72 linked_ptr<PendingTasksList> > PendingTasksMap; |
73 | 73 |
74 // content::NotificationObserver interface. | 74 // content::NotificationObserver interface. |
75 virtual void Observe(int type, | 75 void Observe(int type, |
76 const content::NotificationSource& source, | 76 const content::NotificationSource& source, |
77 const content::NotificationDetails& details) override; | 77 const content::NotificationDetails& details) override; |
78 | 78 |
79 // ExtensionRegistryObserver interface. | 79 // ExtensionRegistryObserver interface. |
80 virtual void OnExtensionUnloaded( | 80 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
81 content::BrowserContext* browser_context, | 81 const Extension* extension, |
82 const Extension* extension, | 82 UnloadedExtensionInfo::Reason reason) override; |
83 UnloadedExtensionInfo::Reason reason) override; | |
84 | 83 |
85 // Called when a lazy background page has finished loading, or has failed to | 84 // Called when a lazy background page has finished loading, or has failed to |
86 // load (host is NULL in that case). All enqueued tasks are run in order. | 85 // load (host is NULL in that case). All enqueued tasks are run in order. |
87 void ProcessPendingTasks( | 86 void ProcessPendingTasks( |
88 ExtensionHost* host, | 87 ExtensionHost* host, |
89 content::BrowserContext* context, | 88 content::BrowserContext* context, |
90 const Extension* extension); | 89 const Extension* extension); |
91 | 90 |
92 content::BrowserContext* browser_context_; | 91 content::BrowserContext* browser_context_; |
93 content::NotificationRegistrar registrar_; | 92 content::NotificationRegistrar registrar_; |
94 PendingTasksMap pending_tasks_; | 93 PendingTasksMap pending_tasks_; |
95 | 94 |
96 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 95 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
97 extension_registry_observer_; | 96 extension_registry_observer_; |
98 }; | 97 }; |
99 | 98 |
100 } // namespace extensions | 99 } // namespace extensions |
101 | 100 |
102 #endif // EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ | 101 #endif // EXTENSIONS_BROWSER_LAZY_BACKGROUND_TASK_QUEUE_H_ |
OLD | NEW |