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 OnExtensionLoad(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 void ProcessManager::WakeExtension(const std::string& extension_id, | |
416 const base::Callback<void(bool)>& callback) { | |
417 if (GetBackgroundHostForExtension(extension_id)) { | |
418 // Run the callback immediately if the extension is already awake. | |
419 callback.Run(true); | |
not at google - send to devlin
2015/04/24 20:05:08
Re-entrant callbacks lead to insidious bugs. Eithe
Kevin Marshall
2015/04/24 21:04:53
Good point, using return value. Updated docs.
| |
420 } | |
421 LazyBackgroundTaskQueue* queue = | |
422 ExtensionSystem::Get(browser_context_)->lazy_background_task_queue(); | |
423 queue->AddPendingTask(browser_context_, extension_id, | |
424 base::Bind(&OnExtensionLoad, callback)); | |
not at google - send to devlin
2015/04/24 20:05:08
Is there a better / more descriptive name than jus
Kevin Marshall
2015/04/24 21:04:53
How's this? "PropagateExtensionWakeResult"
| |
425 } | |
426 | |
409 bool ProcessManager::IsBackgroundHostClosing(const std::string& extension_id) { | 427 bool ProcessManager::IsBackgroundHostClosing(const std::string& extension_id) { |
410 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); | 428 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
411 return (host && background_page_data_[extension_id].is_closing); | 429 return (host && background_page_data_[extension_id].is_closing); |
412 } | 430 } |
413 | 431 |
414 const Extension* ProcessManager::GetExtensionForRenderFrameHost( | 432 const Extension* ProcessManager::GetExtensionForRenderFrameHost( |
415 content::RenderFrameHost* render_frame_host) { | 433 content::RenderFrameHost* render_frame_host) { |
416 return extension_registry_->enabled_extensions().GetByID( | 434 return extension_registry_->enabled_extensions().GetByID( |
417 GetExtensionID(render_frame_host)); | 435 GetExtensionID(render_frame_host)); |
418 } | 436 } |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
915 if (extension && !IncognitoInfo::IsSplitMode(extension)) { | 933 if (extension && !IncognitoInfo::IsSplitMode(extension)) { |
916 BrowserContext* original_context = | 934 BrowserContext* original_context = |
917 ExtensionsBrowserClient::Get()->GetOriginalContext(browser_context()); | 935 ExtensionsBrowserClient::Get()->GetOriginalContext(browser_context()); |
918 return ProcessManager::Get(original_context)->GetSiteInstanceForURL(url); | 936 return ProcessManager::Get(original_context)->GetSiteInstanceForURL(url); |
919 } | 937 } |
920 | 938 |
921 return ProcessManager::GetSiteInstanceForURL(url); | 939 return ProcessManager::GetSiteInstanceForURL(url); |
922 } | 940 } |
923 | 941 |
924 } // namespace extensions | 942 } // namespace extensions |
OLD | NEW |