Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: extensions/browser/process_manager.cc

Issue 1096313003: Create interface "EventPageTracker" for checking an extension's (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix IWYU linter error while I'm at it. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/process_manager.h ('k') | extensions/extensions.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <vector>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/logging.h" 10 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
11 #include "base/stl_util.h" 13 #include "base/stl_util.h"
12 #include "base/time/time.h" 14 #include "base/time/time.h"
13 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/devtools_agent_host.h" 16 #include "content/public/browser/devtools_agent_host.h"
15 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/render_frame_host.h" 18 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/render_view_host.h" 20 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/site_instance.h" 21 #include "content/public/browser/site_instance.h"
20 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
21 #include "content/public/common/url_constants.h" 23 #include "content/public/common/url_constants.h"
22 #include "extensions/browser/extension_host.h" 24 #include "extensions/browser/extension_host.h"
23 #include "extensions/browser/extension_registry.h" 25 #include "extensions/browser/extension_registry.h"
24 #include "extensions/browser/extension_system.h" 26 #include "extensions/browser/extension_system.h"
25 #include "extensions/browser/extensions_browser_client.h" 27 #include "extensions/browser/extensions_browser_client.h"
28 #include "extensions/browser/lazy_background_task_queue.h"
26 #include "extensions/browser/notification_types.h" 29 #include "extensions/browser/notification_types.h"
27 #include "extensions/browser/process_manager_delegate.h" 30 #include "extensions/browser/process_manager_delegate.h"
28 #include "extensions/browser/process_manager_factory.h" 31 #include "extensions/browser/process_manager_factory.h"
29 #include "extensions/browser/process_manager_observer.h" 32 #include "extensions/browser/process_manager_observer.h"
30 #include "extensions/browser/view_type_utils.h" 33 #include "extensions/browser/view_type_utils.h"
31 #include "extensions/common/constants.h" 34 #include "extensions/common/constants.h"
32 #include "extensions/common/extension.h" 35 #include "extensions/common/extension.h"
33 #include "extensions/common/extension_messages.h" 36 #include "extensions/common/extension_messages.h"
34 #include "extensions/common/manifest_handlers/background_info.h" 37 #include "extensions/common/manifest_handlers/background_info.h"
35 #include "extensions/common/manifest_handlers/incognito_info.h" 38 #include "extensions/common/manifest_handlers/incognito_info.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 }; 103 };
101 104
102 static void CreateBackgroundHostForExtensionLoad( 105 static void CreateBackgroundHostForExtensionLoad(
103 ProcessManager* manager, const Extension* extension) { 106 ProcessManager* manager, const Extension* extension) {
104 DVLOG(1) << "CreateBackgroundHostForExtensionLoad"; 107 DVLOG(1) << "CreateBackgroundHostForExtensionLoad";
105 if (BackgroundInfo::HasPersistentBackgroundPage(extension)) 108 if (BackgroundInfo::HasPersistentBackgroundPage(extension))
106 manager->CreateBackgroundHost(extension, 109 manager->CreateBackgroundHost(extension,
107 BackgroundInfo::GetBackgroundURL(extension)); 110 BackgroundInfo::GetBackgroundURL(extension));
108 } 111 }
109 112
113 void PropagateExtensionWakeResult(const base::Callback<void(bool)>& callback,
114 extensions::ExtensionHost* host) {
115 callback.Run(host != nullptr);
116 }
117
110 } // namespace 118 } // namespace
111 119
112 struct ProcessManager::BackgroundPageData { 120 struct ProcessManager::BackgroundPageData {
113 // The count of things keeping the lazy background page alive. 121 // The count of things keeping the lazy background page alive.
114 int lazy_keepalive_count; 122 int lazy_keepalive_count;
115 123
116 // Tracks if an impulse event has occured since the last polling check. 124 // Tracks if an impulse event has occured since the last polling check.
117 bool keepalive_impulse; 125 bool keepalive_impulse;
118 bool previous_keepalive_impulse; 126 bool previous_keepalive_impulse;
119 127
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 407
400 ExtensionHost* ProcessManager::GetBackgroundHostForExtension( 408 ExtensionHost* ProcessManager::GetBackgroundHostForExtension(
401 const std::string& extension_id) { 409 const std::string& extension_id) {
402 for (ExtensionHost* host : background_hosts_) { 410 for (ExtensionHost* host : background_hosts_) {
403 if (host->extension_id() == extension_id) 411 if (host->extension_id() == extension_id)
404 return host; 412 return host;
405 } 413 }
406 return nullptr; 414 return nullptr;
407 } 415 }
408 416
417 bool ProcessManager::IsEventPageSuspended(const std::string& extension_id) {
418 return GetBackgroundHostForExtension(extension_id) == nullptr;
419 }
420
421 bool ProcessManager::WakeEventPage(const std::string& extension_id,
422 const base::Callback<void(bool)>& callback) {
423 if (GetBackgroundHostForExtension(extension_id)) {
424 // Run the callback immediately if the extension is already awake.
425 return false;
426 }
427 LazyBackgroundTaskQueue* queue =
428 ExtensionSystem::Get(browser_context_)->lazy_background_task_queue();
429 queue->AddPendingTask(browser_context_, extension_id,
430 base::Bind(&PropagateExtensionWakeResult, callback));
431 return true;
432 }
433
409 bool ProcessManager::IsBackgroundHostClosing(const std::string& extension_id) { 434 bool ProcessManager::IsBackgroundHostClosing(const std::string& extension_id) {
410 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); 435 ExtensionHost* host = GetBackgroundHostForExtension(extension_id);
411 return (host && background_page_data_[extension_id].is_closing); 436 return (host && background_page_data_[extension_id].is_closing);
412 } 437 }
413 438
414 const Extension* ProcessManager::GetExtensionForRenderFrameHost( 439 const Extension* ProcessManager::GetExtensionForRenderFrameHost(
415 content::RenderFrameHost* render_frame_host) { 440 content::RenderFrameHost* render_frame_host) {
416 return extension_registry_->enabled_extensions().GetByID( 441 return extension_registry_->enabled_extensions().GetByID(
417 GetExtensionID(render_frame_host)); 442 GetExtensionID(render_frame_host));
418 } 443 }
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 if (extension && !IncognitoInfo::IsSplitMode(extension)) { 940 if (extension && !IncognitoInfo::IsSplitMode(extension)) {
916 BrowserContext* original_context = 941 BrowserContext* original_context =
917 ExtensionsBrowserClient::Get()->GetOriginalContext(browser_context()); 942 ExtensionsBrowserClient::Get()->GetOriginalContext(browser_context());
918 return ProcessManager::Get(original_context)->GetSiteInstanceForURL(url); 943 return ProcessManager::Get(original_context)->GetSiteInstanceForURL(url);
919 } 944 }
920 945
921 return ProcessManager::GetSiteInstanceForURL(url); 946 return ProcessManager::GetSiteInstanceForURL(url);
922 } 947 }
923 948
924 } // namespace extensions 949 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/process_manager.h ('k') | extensions/extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698