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

Unified Diff: extensions/browser/process_manager.cc

Issue 2419943002: [DevTools] Migrate from AgentStateCallbacks to DevToolsAgentHostObserver. (Closed)
Patch Set: mac Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/process_manager.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/process_manager.cc
diff --git a/extensions/browser/process_manager.cc b/extensions/browser/process_manager.cc
index 0def1d2e6262cf775e5d3d7a0918a6787e267678..181fbd5f8ba4513e5a3157d9fd9d1c77ca220dbf 100644
--- a/extensions/browser/process_manager.cc
+++ b/extensions/browser/process_manager.cc
@@ -263,9 +263,7 @@ ProcessManager::ProcessManager(BrowserContext* context,
registrar_.Add(this,
extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
content::Source<BrowserContext>(context));
- devtools_callback_ = base::Bind(&ProcessManager::OnDevToolsStateChanged,
- weak_ptr_factory_.GetWeakPtr());
- content::DevToolsAgentHost::AddAgentStateCallback(devtools_callback_);
+ content::DevToolsAgentHost::AddObserver(this);
OnKeepaliveImpulseCheck();
}
@@ -274,7 +272,7 @@ ProcessManager::~ProcessManager() {
extension_registry_->RemoveObserver(this);
CloseBackgroundHosts();
DCHECK(background_hosts_.empty());
- content::DevToolsAgentHost::RemoveAgentStateCallback(devtools_callback_);
+ content::DevToolsAgentHost::RemoveObserver(this);
}
void ProcessManager::RegisterRenderFrameHost(
@@ -891,29 +889,32 @@ void ProcessManager::CloseLazyBackgroundPageNow(const std::string& extension_id,
}
}
-void ProcessManager::OnDevToolsStateChanged(
- content::DevToolsAgentHost* agent_host,
- bool attached) {
+const Extension* ProcessManager::GetExtensionForAgentHost(
+ content::DevToolsAgentHost* agent_host) {
content::WebContents* web_contents = agent_host->GetWebContents();
// Ignore unrelated notifications.
if (!web_contents || web_contents->GetBrowserContext() != browser_context_)
- return;
+ return nullptr;
if (GetViewType(web_contents) != VIEW_TYPE_EXTENSION_BACKGROUND_PAGE)
- return;
- const Extension* extension =
- extension_registry_->enabled_extensions().GetByID(
- GetExtensionIdForSiteInstance(web_contents->GetSiteInstance()));
- if (!extension)
- return;
- if (attached) {
+ return nullptr;
+ return GetExtensionForWebContents(web_contents);
+}
+
+void ProcessManager::DevToolsAgentHostAttached(
+ content::DevToolsAgentHost* agent_host) {
+ if (const Extension* extension = GetExtensionForAgentHost(agent_host)) {
// Keep the lazy background page alive while it's being inspected.
CancelSuspend(extension);
IncrementLazyKeepaliveCount(extension);
- } else {
- DecrementLazyKeepaliveCount(extension);
}
}
+void ProcessManager::DevToolsAgentHostDetached(
+ content::DevToolsAgentHost* agent_host) {
+ if (const Extension* extension = GetExtensionForAgentHost(agent_host))
+ DecrementLazyKeepaliveCount(extension);
+}
+
void ProcessManager::UnregisterExtension(const std::string& extension_id) {
// The lazy_keepalive_count may be greater than zero at this point because
// RenderFrameHosts are still alive. During extension reloading, they will
« no previous file with comments | « extensions/browser/process_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698