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 #include "extensions/browser/lazy_background_task_queue.h" | 5 #include "extensions/browser/lazy_background_task_queue.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
10 #include "content/public/browser/notification_service.h" | 10 #include "content/public/browser/notification_service.h" |
11 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
12 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
13 #include "content/public/browser/site_instance.h" | 13 #include "content/public/browser/site_instance.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "extensions/browser/extension_host.h" | 15 #include "extensions/browser/extension_host.h" |
16 #include "extensions/browser/extension_registry.h" | 16 #include "extensions/browser/extension_registry.h" |
17 #include "extensions/browser/extension_system.h" | 17 #include "extensions/browser/extension_system.h" |
18 #include "extensions/browser/extensions_browser_client.h" | 18 #include "extensions/browser/extensions_browser_client.h" |
19 #include "extensions/browser/process_manager.h" | 19 #include "extensions/browser/process_manager.h" |
20 #include "extensions/browser/process_map.h" | 20 #include "extensions/browser/process_map.h" |
21 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
22 #include "extensions/common/extension_messages.h" | 22 #include "extensions/common/extension_messages.h" |
23 #include "extensions/common/manifest_handlers/background_info.h" | 23 #include "extensions/common/manifest_handlers/background_info.h" |
24 #include "extensions/common/view_type.h" | 24 #include "extensions/common/view_type.h" |
25 | 25 |
26 namespace extensions { | 26 namespace extensions { |
27 | 27 |
28 LazyBackgroundTaskQueue::LazyBackgroundTaskQueue( | 28 LazyBackgroundTaskQueue::LazyBackgroundTaskQueue( |
29 content::BrowserContext* browser_context) | 29 content::BrowserContext* browser_context) |
30 : browser_context_(browser_context) { | 30 : browser_context_(browser_context), extension_registry_observer_(this) { |
31 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 31 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
32 content::NotificationService::AllBrowserContextsAndSources()); | 32 content::NotificationService::AllBrowserContextsAndSources()); |
33 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 33 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
34 content::NotificationService::AllBrowserContextsAndSources()); | 34 content::NotificationService::AllBrowserContextsAndSources()); |
35 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, | 35 |
36 content::Source<content::BrowserContext>(browser_context)); | 36 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context)); |
37 } | 37 } |
38 | 38 |
39 LazyBackgroundTaskQueue::~LazyBackgroundTaskQueue() { | 39 LazyBackgroundTaskQueue::~LazyBackgroundTaskQueue() { |
40 } | 40 } |
41 | 41 |
42 bool LazyBackgroundTaskQueue::ShouldEnqueueTask( | 42 bool LazyBackgroundTaskQueue::ShouldEnqueueTask( |
43 content::BrowserContext* browser_context, | 43 content::BrowserContext* browser_context, |
44 const Extension* extension) { | 44 const Extension* extension) { |
45 DCHECK(extension); | 45 DCHECK(extension); |
46 if (BackgroundInfo::HasBackgroundPage(extension)) { | 46 if (BackgroundInfo::HasBackgroundPage(extension)) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // dispatches the tasks below), but is a good extra precaution. | 155 // dispatches the tasks below), but is a good extra precaution. |
156 content::BrowserContext* browser_context = | 156 content::BrowserContext* browser_context = |
157 content::Source<content::BrowserContext>(source).ptr(); | 157 content::Source<content::BrowserContext>(source).ptr(); |
158 ExtensionHost* host = | 158 ExtensionHost* host = |
159 content::Details<ExtensionHost>(details).ptr(); | 159 content::Details<ExtensionHost>(details).ptr(); |
160 if (host->extension_host_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 160 if (host->extension_host_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
161 ProcessPendingTasks(NULL, browser_context, host->extension()); | 161 ProcessPendingTasks(NULL, browser_context, host->extension()); |
162 } | 162 } |
163 break; | 163 break; |
164 } | 164 } |
165 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | |
166 // Notify consumers that the page failed to load. | |
167 content::BrowserContext* browser_context = | |
168 content::Source<content::BrowserContext>(source).ptr(); | |
169 UnloadedExtensionInfo* unloaded = | |
170 content::Details<UnloadedExtensionInfo>(details).ptr(); | |
171 ProcessPendingTasks(NULL, browser_context, unloaded->extension); | |
172 // If this extension is also running in an off-the-record context, | |
173 // notify that task queue as well. | |
174 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); | |
175 if (browser_client->HasOffTheRecordContext(browser_context)) { | |
176 ProcessPendingTasks( | |
177 NULL, | |
178 browser_client->GetOffTheRecordContext(browser_context), | |
179 unloaded->extension); | |
180 } | |
181 break; | |
182 } | |
183 default: | 165 default: |
184 NOTREACHED(); | 166 NOTREACHED(); |
185 break; | 167 break; |
186 } | 168 } |
187 } | 169 } |
188 | 170 |
| 171 void LazyBackgroundTaskQueue::OnExtensionUnloaded( |
| 172 content::BrowserContext* browser_context, |
| 173 const Extension* extension, |
| 174 UnloadedExtensionInfo::Reason reason) { |
| 175 // Notify consumers that the page failed to load. |
| 176 ProcessPendingTasks(NULL, browser_context, extension); |
| 177 // If this extension is also running in an off-the-record context, notify that |
| 178 // task queue as well. |
| 179 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); |
| 180 if (browser_client->HasOffTheRecordContext(browser_context)) { |
| 181 ProcessPendingTasks(NULL, |
| 182 browser_client->GetOffTheRecordContext(browser_context), |
| 183 extension); |
| 184 } |
| 185 } |
| 186 |
189 } // namespace extensions | 187 } // namespace extensions |
OLD | NEW |