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 "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.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/extensions_browser_client.h" | 17 #include "extensions/browser/extensions_browser_client.h" |
18 #include "extensions/browser/lazy_background_task_queue_factory.h" | 18 #include "extensions/browser/lazy_background_task_queue_factory.h" |
| 19 #include "extensions/browser/lazy_context_id.h" |
19 #include "extensions/browser/notification_types.h" | 20 #include "extensions/browser/notification_types.h" |
20 #include "extensions/browser/process_manager.h" | 21 #include "extensions/browser/process_manager.h" |
21 #include "extensions/browser/process_map.h" | 22 #include "extensions/browser/process_map.h" |
22 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
23 #include "extensions/common/manifest_handlers/background_info.h" | 24 #include "extensions/common/manifest_handlers/background_info.h" |
24 #include "extensions/common/view_type.h" | 25 #include "extensions/common/view_type.h" |
25 | 26 |
26 namespace extensions { | 27 namespace extensions { |
27 | 28 |
| 29 namespace { |
| 30 |
| 31 // Adapts a LazyBackgroundTaskQueue pending task callback to |
| 32 // LazyContextTaskQueue's callback. |
| 33 void PendingTaskAdapter(const LazyContextTaskQueue::PendingTask& original_task, |
| 34 ExtensionHost* host) { |
| 35 if (!host) { |
| 36 original_task.Run(nullptr); |
| 37 } else { |
| 38 original_task.Run(base::MakeUnique<LazyContextTaskQueue::ContextInfo>( |
| 39 host->extension()->id(), host->render_process_host(), |
| 40 kNonWorkerThreadId, host->GetURL())); |
| 41 } |
| 42 } |
| 43 |
| 44 } // namespace |
| 45 |
28 LazyBackgroundTaskQueue::LazyBackgroundTaskQueue( | 46 LazyBackgroundTaskQueue::LazyBackgroundTaskQueue( |
29 content::BrowserContext* browser_context) | 47 content::BrowserContext* browser_context) |
30 : browser_context_(browser_context), extension_registry_observer_(this) { | 48 : browser_context_(browser_context), extension_registry_observer_(this) { |
31 registrar_.Add(this, | 49 registrar_.Add(this, |
32 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, | 50 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, |
33 content::NotificationService::AllBrowserContextsAndSources()); | 51 content::NotificationService::AllBrowserContextsAndSources()); |
34 registrar_.Add(this, | 52 registrar_.Add(this, |
35 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 53 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
36 content::NotificationService::AllBrowserContextsAndSources()); | 54 content::NotificationService::AllBrowserContextsAndSources()); |
37 | 55 |
(...skipping 21 matching lines...) Expand all Loading... |
59 pm->GetBackgroundHostForExtension(extension->id()); | 77 pm->GetBackgroundHostForExtension(extension->id()); |
60 if (!background_host || !background_host->has_loaded_once()) | 78 if (!background_host || !background_host->has_loaded_once()) |
61 return true; | 79 return true; |
62 if (pm->IsBackgroundHostClosing(extension->id())) | 80 if (pm->IsBackgroundHostClosing(extension->id())) |
63 pm->CancelSuspend(extension); | 81 pm->CancelSuspend(extension); |
64 } | 82 } |
65 | 83 |
66 return false; | 84 return false; |
67 } | 85 } |
68 | 86 |
| 87 void LazyBackgroundTaskQueue::AddPendingTaskToDispatchEvent( |
| 88 LazyContextId* context_id, |
| 89 const LazyContextTaskQueue::PendingTask& task) { |
| 90 AddPendingTask(context_id->browser_context(), context_id->extension_id(), |
| 91 base::Bind(&PendingTaskAdapter, task)); |
| 92 } |
| 93 |
69 void LazyBackgroundTaskQueue::AddPendingTask( | 94 void LazyBackgroundTaskQueue::AddPendingTask( |
70 content::BrowserContext* browser_context, | 95 content::BrowserContext* browser_context, |
71 const std::string& extension_id, | 96 const std::string& extension_id, |
72 const PendingTask& task) { | 97 const PendingTask& task) { |
73 if (ExtensionsBrowserClient::Get()->IsShuttingDown()) { | 98 if (ExtensionsBrowserClient::Get()->IsShuttingDown()) { |
74 task.Run(NULL); | 99 task.Run(NULL); |
75 return; | 100 return; |
76 } | 101 } |
77 PendingTasksList* tasks_list = NULL; | 102 PendingTasksList* tasks_list = NULL; |
78 PendingTasksKey key(browser_context, extension_id); | 103 PendingTasksKey key(browser_context, extension_id); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // task queue as well. | 210 // task queue as well. |
186 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); | 211 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); |
187 if (browser_client->HasOffTheRecordContext(browser_context)) { | 212 if (browser_client->HasOffTheRecordContext(browser_context)) { |
188 ProcessPendingTasks(NULL, | 213 ProcessPendingTasks(NULL, |
189 browser_client->GetOffTheRecordContext(browser_context), | 214 browser_client->GetOffTheRecordContext(browser_context), |
190 extension); | 215 extension); |
191 } | 216 } |
192 } | 217 } |
193 | 218 |
194 } // namespace extensions | 219 } // namespace extensions |
OLD | NEW |