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/process_manager.h" | 5 #include "extensions/browser/process_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
14 #include "content/public/browser/devtools_agent_host.h" | 14 #include "content/public/browser/devtools_agent_host.h" |
15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
16 #include "content/public/browser/render_frame_host.h" | 16 #include "content/public/browser/render_frame_host.h" |
17 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
18 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
19 #include "content/public/browser/site_instance.h" | 19 #include "content/public/browser/site_instance.h" |
20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
21 #include "content/public/common/url_constants.h" | 21 #include "content/public/common/url_constants.h" |
22 #include "extensions/browser/extension_host.h" | 22 #include "extensions/browser/extension_host.h" |
23 #include "extensions/browser/extension_registry.h" | 23 #include "extensions/browser/extension_registry.h" |
24 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
25 #include "extensions/browser/extensions_browser_client.h" | 25 #include "extensions/browser/extensions_browser_client.h" |
| 26 #include "extensions/browser/lazy_background_task_queue.h" |
26 #include "extensions/browser/notification_types.h" | 27 #include "extensions/browser/notification_types.h" |
27 #include "extensions/browser/process_manager_delegate.h" | 28 #include "extensions/browser/process_manager_delegate.h" |
28 #include "extensions/browser/process_manager_factory.h" | 29 #include "extensions/browser/process_manager_factory.h" |
29 #include "extensions/browser/process_manager_observer.h" | 30 #include "extensions/browser/process_manager_observer.h" |
30 #include "extensions/browser/view_type_utils.h" | 31 #include "extensions/browser/view_type_utils.h" |
31 #include "extensions/common/constants.h" | 32 #include "extensions/common/constants.h" |
32 #include "extensions/common/extension.h" | 33 #include "extensions/common/extension.h" |
33 #include "extensions/common/extension_messages.h" | 34 #include "extensions/common/extension_messages.h" |
34 #include "extensions/common/manifest_handlers/background_info.h" | 35 #include "extensions/common/manifest_handlers/background_info.h" |
35 #include "extensions/common/manifest_handlers/incognito_info.h" | 36 #include "extensions/common/manifest_handlers/incognito_info.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 }; | 101 }; |
101 | 102 |
102 static void CreateBackgroundHostForExtensionLoad( | 103 static void CreateBackgroundHostForExtensionLoad( |
103 ProcessManager* manager, const Extension* extension) { | 104 ProcessManager* manager, const Extension* extension) { |
104 DVLOG(1) << "CreateBackgroundHostForExtensionLoad"; | 105 DVLOG(1) << "CreateBackgroundHostForExtensionLoad"; |
105 if (BackgroundInfo::HasPersistentBackgroundPage(extension)) | 106 if (BackgroundInfo::HasPersistentBackgroundPage(extension)) |
106 manager->CreateBackgroundHost(extension, | 107 manager->CreateBackgroundHost(extension, |
107 BackgroundInfo::GetBackgroundURL(extension)); | 108 BackgroundInfo::GetBackgroundURL(extension)); |
108 } | 109 } |
109 | 110 |
| 111 void PropagateExtensionWakeResult(const base::Callback<void(bool)>& callback, |
| 112 extensions::ExtensionHost* host) { |
| 113 callback.Run(host != nullptr); |
| 114 } |
| 115 |
110 } // namespace | 116 } // namespace |
111 | 117 |
112 struct ProcessManager::BackgroundPageData { | 118 struct ProcessManager::BackgroundPageData { |
113 // The count of things keeping the lazy background page alive. | 119 // The count of things keeping the lazy background page alive. |
114 int lazy_keepalive_count; | 120 int lazy_keepalive_count; |
115 | 121 |
116 // Tracks if an impulse event has occured since the last polling check. | 122 // Tracks if an impulse event has occured since the last polling check. |
117 bool keepalive_impulse; | 123 bool keepalive_impulse; |
118 bool previous_keepalive_impulse; | 124 bool previous_keepalive_impulse; |
119 | 125 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 | 405 |
400 ExtensionHost* ProcessManager::GetBackgroundHostForExtension( | 406 ExtensionHost* ProcessManager::GetBackgroundHostForExtension( |
401 const std::string& extension_id) { | 407 const std::string& extension_id) { |
402 for (ExtensionHost* host : background_hosts_) { | 408 for (ExtensionHost* host : background_hosts_) { |
403 if (host->extension_id() == extension_id) | 409 if (host->extension_id() == extension_id) |
404 return host; | 410 return host; |
405 } | 411 } |
406 return nullptr; | 412 return nullptr; |
407 } | 413 } |
408 | 414 |
| 415 bool ProcessManager::IsEventPageActive(const std::string& extension_id) { |
| 416 return GetBackgroundHostForExtension(extension_id) != nullptr; |
| 417 } |
| 418 |
| 419 bool ProcessManager::WakeEventPage(const std::string& extension_id, |
| 420 const base::Callback<void(bool)>& callback) { |
| 421 if (IsEventPageActive(extension_id)) { |
| 422 return false; |
| 423 } |
| 424 |
| 425 LazyBackgroundTaskQueue* queue = |
| 426 ExtensionSystem::Get(browser_context_)->lazy_background_task_queue(); |
| 427 queue->AddPendingTask(browser_context_, extension_id, |
| 428 base::Bind(&PropagateExtensionWakeResult, callback)); |
| 429 return true; |
| 430 } |
| 431 |
409 bool ProcessManager::IsBackgroundHostClosing(const std::string& extension_id) { | 432 bool ProcessManager::IsBackgroundHostClosing(const std::string& extension_id) { |
410 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); | 433 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
411 return (host && background_page_data_[extension_id].is_closing); | 434 return (host && background_page_data_[extension_id].is_closing); |
412 } | 435 } |
413 | 436 |
414 const Extension* ProcessManager::GetExtensionForRenderFrameHost( | 437 const Extension* ProcessManager::GetExtensionForRenderFrameHost( |
415 content::RenderFrameHost* render_frame_host) { | 438 content::RenderFrameHost* render_frame_host) { |
416 return extension_registry_->enabled_extensions().GetByID( | 439 return extension_registry_->enabled_extensions().GetByID( |
417 GetExtensionID(render_frame_host)); | 440 GetExtensionID(render_frame_host)); |
418 } | 441 } |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 if (extension && !IncognitoInfo::IsSplitMode(extension)) { | 938 if (extension && !IncognitoInfo::IsSplitMode(extension)) { |
916 BrowserContext* original_context = | 939 BrowserContext* original_context = |
917 ExtensionsBrowserClient::Get()->GetOriginalContext(browser_context()); | 940 ExtensionsBrowserClient::Get()->GetOriginalContext(browser_context()); |
918 return ProcessManager::Get(original_context)->GetSiteInstanceForURL(url); | 941 return ProcessManager::Get(original_context)->GetSiteInstanceForURL(url); |
919 } | 942 } |
920 | 943 |
921 return ProcessManager::GetSiteInstanceForURL(url); | 944 return ProcessManager::GetSiteInstanceForURL(url); |
922 } | 945 } |
923 | 946 |
924 } // namespace extensions | 947 } // namespace extensions |
OLD | NEW |