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 "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
9 #include "content/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
10 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
11 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
12 #include "content/public/browser/site_instance.h" | 12 #include "content/public/browser/site_instance.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "extensions/browser/extension_host.h" | 14 #include "extensions/browser/extension_host.h" |
15 #include "extensions/browser/extension_registry.h" | 15 #include "extensions/browser/extension_registry.h" |
16 #include "extensions/browser/extensions_browser_client.h" | 16 #include "extensions/browser/extensions_browser_client.h" |
| 17 #include "extensions/browser/lazy_background_task_queue_factory.h" |
17 #include "extensions/browser/notification_types.h" | 18 #include "extensions/browser/notification_types.h" |
18 #include "extensions/browser/process_manager.h" | 19 #include "extensions/browser/process_manager.h" |
19 #include "extensions/browser/process_map.h" | 20 #include "extensions/browser/process_map.h" |
20 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
21 #include "extensions/common/manifest_handlers/background_info.h" | 22 #include "extensions/common/manifest_handlers/background_info.h" |
22 #include "extensions/common/view_type.h" | 23 #include "extensions/common/view_type.h" |
23 | 24 |
24 namespace extensions { | 25 namespace extensions { |
25 | 26 |
26 LazyBackgroundTaskQueue::LazyBackgroundTaskQueue( | 27 LazyBackgroundTaskQueue::LazyBackgroundTaskQueue( |
27 content::BrowserContext* browser_context) | 28 content::BrowserContext* browser_context) |
28 : browser_context_(browser_context), extension_registry_observer_(this) { | 29 : browser_context_(browser_context), extension_registry_observer_(this) { |
29 registrar_.Add(this, | 30 registrar_.Add(this, |
30 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, | 31 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, |
31 content::NotificationService::AllBrowserContextsAndSources()); | 32 content::NotificationService::AllBrowserContextsAndSources()); |
32 registrar_.Add(this, | 33 registrar_.Add(this, |
33 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 34 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
34 content::NotificationService::AllBrowserContextsAndSources()); | 35 content::NotificationService::AllBrowserContextsAndSources()); |
35 | 36 |
36 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context)); | 37 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context)); |
37 } | 38 } |
38 | 39 |
39 LazyBackgroundTaskQueue::~LazyBackgroundTaskQueue() { | 40 LazyBackgroundTaskQueue::~LazyBackgroundTaskQueue() { |
40 } | 41 } |
41 | 42 |
| 43 // static |
| 44 LazyBackgroundTaskQueue* LazyBackgroundTaskQueue::Get( |
| 45 content::BrowserContext* browser_context) { |
| 46 return LazyBackgroundTaskQueueFactory::GetForBrowserContext(browser_context); |
| 47 } |
| 48 |
42 bool LazyBackgroundTaskQueue::ShouldEnqueueTask( | 49 bool LazyBackgroundTaskQueue::ShouldEnqueueTask( |
43 content::BrowserContext* browser_context, | 50 content::BrowserContext* browser_context, |
44 const Extension* extension) { | 51 const Extension* extension) { |
45 // Note: browser_context may not be the same as browser_context_ for incognito | 52 // Note: browser_context may not be the same as browser_context_ for incognito |
46 // extension tasks. | 53 // extension tasks. |
47 DCHECK(extension); | 54 DCHECK(extension); |
48 if (BackgroundInfo::HasBackgroundPage(extension)) { | 55 if (BackgroundInfo::HasBackgroundPage(extension)) { |
49 ProcessManager* pm = ProcessManager::Get(browser_context); | 56 ProcessManager* pm = ProcessManager::Get(browser_context); |
50 ExtensionHost* background_host = | 57 ExtensionHost* background_host = |
51 pm->GetBackgroundHostForExtension(extension->id()); | 58 pm->GetBackgroundHostForExtension(extension->id()); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // task queue as well. | 184 // task queue as well. |
178 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); | 185 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); |
179 if (browser_client->HasOffTheRecordContext(browser_context)) { | 186 if (browser_client->HasOffTheRecordContext(browser_context)) { |
180 ProcessPendingTasks(NULL, | 187 ProcessPendingTasks(NULL, |
181 browser_client->GetOffTheRecordContext(browser_context), | 188 browser_client->GetOffTheRecordContext(browser_context), |
182 extension); | 189 extension); |
183 } | 190 } |
184 } | 191 } |
185 | 192 |
186 } // namespace extensions | 193 } // namespace extensions |
OLD | NEW |