Chromium Code Reviews| Index: chrome/browser/extensions/api/debugger/debugger_api.cc |
| diff --git a/chrome/browser/extensions/api/debugger/debugger_api.cc b/chrome/browser/extensions/api/debugger/debugger_api.cc |
| index 4e02a8df1abef9189b07cc9c3cf734022a081537..2db200ea6328e3c698eb0f382977cc778ca4563d 100644 |
| --- a/chrome/browser/extensions/api/debugger/debugger_api.cc |
| +++ b/chrome/browser/extensions/api/debugger/debugger_api.cc |
| @@ -31,9 +31,7 @@ |
| #include "components/infobars/core/confirm_infobar_delegate.h" |
| #include "components/infobars/core/infobar.h" |
| #include "content/public/browser/devtools_agent_host.h" |
| -#include "content/public/browser/devtools_client_host.h" |
| #include "content/public/browser/devtools_http_handler.h" |
| -#include "content/public/browser/devtools_manager.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/notification_source.h" |
| #include "content/public/browser/render_process_host.h" |
| @@ -57,9 +55,7 @@ |
| #include "ui/base/l10n/l10n_util.h" |
| using content::DevToolsAgentHost; |
| -using content::DevToolsClientHost; |
| using content::DevToolsHttpHandler; |
| -using content::DevToolsManager; |
| using content::RenderProcessHost; |
| using content::RenderViewHost; |
| using content::RenderWidgetHost; |
| @@ -77,7 +73,7 @@ class ExtensionRegistry; |
| // ExtensionDevToolsClientHost ------------------------------------------------ |
| -class ExtensionDevToolsClientHost : public DevToolsClientHost, |
| +class ExtensionDevToolsClientHost : public DevToolsAgentHost::Client, |
| public content::NotificationObserver, |
| public ExtensionRegistryObserver { |
| public: |
| @@ -91,6 +87,7 @@ class ExtensionDevToolsClientHost : public DevToolsClientHost, |
| virtual ~ExtensionDevToolsClientHost(); |
| const std::string& extension_id() { return extension_id_; } |
| + DevToolsAgentHost* agent_host() { return agent_host_.get(); } |
| void Close(); |
| void SendMessageToBackend(DebuggerSendCommandFunction* function, |
| const std::string& method, |
| @@ -99,10 +96,13 @@ class ExtensionDevToolsClientHost : public DevToolsClientHost, |
| // Marks connection as to-be-terminated by the user. |
| void MarkAsDismissed(); |
| - // DevToolsClientHost interface |
| - virtual void InspectedContentsClosing() OVERRIDE; |
| - virtual void DispatchOnInspectorFrontend(const std::string& message) OVERRIDE; |
| - virtual void ReplacedWithAnotherClient() OVERRIDE; |
| + // DevToolsAgentHost::Client interface. |
| + virtual void AgentHostDetached( |
| + DevToolsAgentHost* agent_host, |
| + DevToolsAgentHost::DetachReason reason) OVERRIDE; |
| + virtual void SendMessageFromAgentHost( |
| + DevToolsAgentHost* agent_host, |
| + const std::string& message) OVERRIDE; |
| private: |
| void SendDetachedEvent(); |
| @@ -293,11 +293,10 @@ void AttachedClientHosts::Remove(ExtensionDevToolsClientHost* client_host) { |
| ExtensionDevToolsClientHost* AttachedClientHosts::Lookup( |
| DevToolsAgentHost* agent_host, |
| const std::string& extension_id) { |
| - DevToolsManager* manager = DevToolsManager::GetInstance(); |
| for (ClientHosts::iterator it = client_hosts_.begin(); |
| it != client_hosts_.end(); ++it) { |
| ExtensionDevToolsClientHost* client_host = *it; |
| - if (manager->GetDevToolsAgentHostFor(client_host) == agent_host && |
| + if (client_host->agent_host() == agent_host && |
| client_host->extension_id() == extension_id) |
| return client_host; |
| } |
| @@ -338,8 +337,7 @@ ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( |
| content::NotificationService::AllSources()); |
| // Attach to debugger and tell it we are ready. |
| - DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( |
| - agent_host_.get(), this); |
| + agent_host_->AttachClient(this); |
| if (infobar_) { |
| static_cast<ExtensionDevToolsInfoBarDelegate*>( |
| @@ -367,18 +365,21 @@ ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { |
| AttachedClientHosts::GetInstance()->Remove(this); |
| } |
| -// DevToolsClientHost interface |
| -void ExtensionDevToolsClientHost::InspectedContentsClosing() { |
| - SendDetachedEvent(); |
| +// DevToolsAgentHost::Client implementation. |
| +void ExtensionDevToolsClientHost::AgentHostDetached( |
| + DevToolsAgentHost* agent_host, DevToolsAgentHost::DetachReason reason) { |
| + DCHECK(agent_host == agent_host_.get()); |
| + if (reason != DevToolsAgentHost::DETACHED_BY_CLIENT) { |
| + if (reason == DevToolsAgentHost::REPLACED_WITH_ANOTHER_CLIENT) |
| + detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS; |
| + SendDetachedEvent(); |
| + } |
| + agent_host_ = NULL; |
| delete this; |
|
pfeldman
2014/08/07 15:40:30
Are you now deleting things twice?
dgozman
2014/08/07 16:51:52
Yes, fixed.
|
| } |
| -void ExtensionDevToolsClientHost::ReplacedWithAnotherClient() { |
| - detach_reason_ = OnDetach::REASON_REPLACED_WITH_DEVTOOLS; |
| -} |
| - |
| void ExtensionDevToolsClientHost::Close() { |
| - DevToolsManager::GetInstance()->ClientHostClosing(this); |
| + agent_host_->DetachClient(); |
| delete this; |
| } |
| @@ -398,7 +399,7 @@ void ExtensionDevToolsClientHost::SendMessageToBackend( |
| std::string json_args; |
| base::JSONWriter::Write(&protocol_request, &json_args); |
| - DevToolsManager::GetInstance()->DispatchOnInspectorBackend(this, json_args); |
| + agent_host_->DispatchOnInspectorBackend(json_args); |
| } |
| void ExtensionDevToolsClientHost::MarkAsDismissed() { |
| @@ -446,8 +447,9 @@ void ExtensionDevToolsClientHost::Observe( |
| } |
| } |
| -void ExtensionDevToolsClientHost::DispatchOnInspectorFrontend( |
| - const std::string& message) { |
| +void ExtensionDevToolsClientHost::SendMessageFromAgentHost( |
| + DevToolsAgentHost* agent_host, const std::string& message) { |
| + DCHECK(agent_host == agent_host_.get()); |
| if (!EventRouter::Get(profile_)) |
| return; |