| 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" | |
| 9 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
| 10 #include "content/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
| 11 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 13 #include "content/public/browser/site_instance.h" | 12 #include "content/public/browser/site_instance.h" |
| 14 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 15 #include "extensions/browser/extension_host.h" | 14 #include "extensions/browser/extension_host.h" |
| 16 #include "extensions/browser/extension_registry.h" | 15 #include "extensions/browser/extension_registry.h" |
| 17 #include "extensions/browser/extension_system.h" | 16 #include "extensions/browser/extension_system.h" |
| 18 #include "extensions/browser/extensions_browser_client.h" | 17 #include "extensions/browser/extensions_browser_client.h" |
| 18 #include "extensions/browser/notification_types.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), extension_registry_observer_(this) { | 30 : browser_context_(browser_context), extension_registry_observer_(this) { |
| 31 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 31 registrar_.Add(this, |
| 32 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, |
| 32 content::NotificationService::AllBrowserContextsAndSources()); | 33 content::NotificationService::AllBrowserContextsAndSources()); |
| 33 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 34 registrar_.Add(this, |
| 35 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 34 content::NotificationService::AllBrowserContextsAndSources()); | 36 content::NotificationService::AllBrowserContextsAndSources()); |
| 35 | 37 |
| 36 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context)); | 38 extension_registry_observer_.Add(ExtensionRegistry::Get(browser_context)); |
| 37 } | 39 } |
| 38 | 40 |
| 39 LazyBackgroundTaskQueue::~LazyBackgroundTaskQueue() { | 41 LazyBackgroundTaskQueue::~LazyBackgroundTaskQueue() { |
| 40 } | 42 } |
| 41 | 43 |
| 42 bool LazyBackgroundTaskQueue::ShouldEnqueueTask( | 44 bool LazyBackgroundTaskQueue::ShouldEnqueueTask( |
| 43 content::BrowserContext* browser_context, | 45 content::BrowserContext* browser_context, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 ExtensionSystem::Get(browser_context)->process_manager()-> | 132 ExtensionSystem::Get(browser_context)->process_manager()-> |
| 131 DecrementLazyKeepaliveCount(extension); | 133 DecrementLazyKeepaliveCount(extension); |
| 132 } | 134 } |
| 133 } | 135 } |
| 134 | 136 |
| 135 void LazyBackgroundTaskQueue::Observe( | 137 void LazyBackgroundTaskQueue::Observe( |
| 136 int type, | 138 int type, |
| 137 const content::NotificationSource& source, | 139 const content::NotificationSource& source, |
| 138 const content::NotificationDetails& details) { | 140 const content::NotificationDetails& details) { |
| 139 switch (type) { | 141 switch (type) { |
| 140 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { | 142 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { |
| 141 // If an on-demand background page finished loading, dispatch queued up | 143 // If an on-demand background page finished loading, dispatch queued up |
| 142 // events for it. | 144 // events for it. |
| 143 ExtensionHost* host = | 145 ExtensionHost* host = |
| 144 content::Details<ExtensionHost>(details).ptr(); | 146 content::Details<ExtensionHost>(details).ptr(); |
| 145 if (host->extension_host_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 147 if (host->extension_host_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
| 146 CHECK(host->did_stop_loading()); | 148 CHECK(host->did_stop_loading()); |
| 147 ProcessPendingTasks(host, host->browser_context(), host->extension()); | 149 ProcessPendingTasks(host, host->browser_context(), host->extension()); |
| 148 } | 150 } |
| 149 break; | 151 break; |
| 150 } | 152 } |
| 151 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: { | 153 case extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED: { |
| 152 // Notify consumers about the load failure when the background host dies. | 154 // Notify consumers about the load failure when the background host dies. |
| 153 // This can happen if the extension crashes. This is not strictly | 155 // This can happen if the extension crashes. This is not strictly |
| 154 // necessary, since we also unload the extension in that case (which | 156 // necessary, since we also unload the extension in that case (which |
| 155 // dispatches the tasks below), but is a good extra precaution. | 157 // dispatches the tasks below), but is a good extra precaution. |
| 156 content::BrowserContext* browser_context = | 158 content::BrowserContext* browser_context = |
| 157 content::Source<content::BrowserContext>(source).ptr(); | 159 content::Source<content::BrowserContext>(source).ptr(); |
| 158 ExtensionHost* host = | 160 ExtensionHost* host = |
| 159 content::Details<ExtensionHost>(details).ptr(); | 161 content::Details<ExtensionHost>(details).ptr(); |
| 160 if (host->extension_host_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 162 if (host->extension_host_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
| 161 ProcessPendingTasks(NULL, browser_context, host->extension()); | 163 ProcessPendingTasks(NULL, browser_context, host->extension()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 178 // task queue as well. | 180 // task queue as well. |
| 179 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); | 181 ExtensionsBrowserClient* browser_client = ExtensionsBrowserClient::Get(); |
| 180 if (browser_client->HasOffTheRecordContext(browser_context)) { | 182 if (browser_client->HasOffTheRecordContext(browser_context)) { |
| 181 ProcessPendingTasks(NULL, | 183 ProcessPendingTasks(NULL, |
| 182 browser_client->GetOffTheRecordContext(browser_context), | 184 browser_client->GetOffTheRecordContext(browser_context), |
| 183 extension); | 185 extension); |
| 184 } | 186 } |
| 185 } | 187 } |
| 186 | 188 |
| 187 } // namespace extensions | 189 } // namespace extensions |
| OLD | NEW |