Index: content/browser/devtools/devtools_http_handler_impl.cc |
diff --git a/content/browser/devtools/devtools_http_handler_impl.cc b/content/browser/devtools/devtools_http_handler_impl.cc |
index d1b5b1e67245588bb2cf4c35cc6e0ccf5523d50e..ae5845b4c31a27027a1c0149aa50f2cb62a12704 100644 |
--- a/content/browser/devtools/devtools_http_handler_impl.cc |
+++ b/content/browser/devtools/devtools_http_handler_impl.cc |
@@ -26,9 +26,7 @@ |
#include "content/common/devtools_messages.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/devtools_agent_host.h" |
-#include "content/public/browser/devtools_client_host.h" |
#include "content/public/browser/devtools_http_handler_delegate.h" |
-#include "content/public/browser/devtools_manager.h" |
#include "content/public/browser/devtools_target.h" |
#include "content/public/common/content_client.h" |
#include "content/public/common/url_constants.h" |
@@ -69,30 +67,39 @@ const char kTargetFaviconUrlField[] = "faviconUrl"; |
const char kTargetWebSocketDebuggerUrlField[] = "webSocketDebuggerUrl"; |
const char kTargetDevtoolsFrontendUrlField[] = "devtoolsFrontendUrl"; |
-// An internal implementation of DevToolsClientHost that delegates |
-// messages sent for DevToolsClient to a DebuggerShell instance. |
-class DevToolsClientHostImpl : public DevToolsClientHost { |
+// An internal implementation of DevToolsAgentHost::Client that delegates |
+// messages sent to a DebuggerShell instance. |
+class DevToolsAgentHostClientImpl : public DevToolsAgentHost::Client { |
public: |
- DevToolsClientHostImpl(base::MessageLoop* message_loop, |
- net::HttpServer* server, |
- int connection_id) |
+ DevToolsAgentHostClientImpl(base::MessageLoop* message_loop, |
+ net::HttpServer* server, |
+ int connection_id, |
+ DevToolsAgentHost* agent_host) |
: message_loop_(message_loop), |
server_(server), |
connection_id_(connection_id), |
- is_closed_(false), |
- detach_reason_("target_closed") {} |
+ agent_host_(agent_host) { |
+ agent_host_->AttachClient(this); |
+ } |
- virtual ~DevToolsClientHostImpl() {} |
+ virtual ~DevToolsAgentHostClientImpl() { |
+ if (agent_host_) |
+ agent_host_->DetachClient(); |
+ } |
- // DevToolsClientHost interface |
- virtual void InspectedContentsClosing() OVERRIDE { |
- if (is_closed_) |
+ virtual void AgentHostDetached( |
+ DevToolsAgentHost* agent_host, |
+ DevToolsAgentHost::DetachReason reason) OVERRIDE { |
+ DCHECK(agent_host == agent_host_.get()); |
+ agent_host_ = NULL; |
+ if (reason == content::DevToolsAgentHost::DETACHED_BY_CLIENT) |
pfeldman
2014/08/07 15:40:30
Lets not make this change as a part of the large o
dgozman
2014/08/07 16:51:52
Done.
|
return; |
- is_closed_ = true; |
base::DictionaryValue notification; |
notification.SetString( |
- devtools::Inspector::detached::kParamReason, detach_reason_); |
+ devtools::Inspector::detached::kParamReason, |
+ reason == content::DevToolsAgentHost::REPLACED_WITH_ANOTHER_CLIENT ? |
+ "replaced_with_devtools" : "target_closed"); |
std::string response = DevToolsProtocol::CreateNotification( |
devtools::Inspector::detached::kName, |
notification.DeepCopy())->Serialize(); |
@@ -108,25 +115,27 @@ class DevToolsClientHostImpl : public DevToolsClientHost { |
base::Bind(&net::HttpServer::Close, server_, connection_id_)); |
} |
- virtual void DispatchOnInspectorFrontend(const std::string& data) OVERRIDE { |
+ virtual void SendMessageFromAgentHost( |
+ DevToolsAgentHost* agent_host, const std::string& message) OVERRIDE { |
+ DCHECK(agent_host == agent_host_.get()); |
message_loop_->PostTask( |
FROM_HERE, |
base::Bind(&net::HttpServer::SendOverWebSocket, |
server_, |
connection_id_, |
- data)); |
+ message)); |
} |
- virtual void ReplacedWithAnotherClient() OVERRIDE { |
- detach_reason_ = "replaced_with_devtools"; |
+ void OnMessage(const std::string& message) { |
+ if (agent_host_) |
+ agent_host_->DispatchOnInspectorBackend(message); |
} |
private: |
base::MessageLoop* message_loop_; |
net::HttpServer* server_; |
int connection_id_; |
- bool is_closed_; |
- std::string detach_reason_; |
+ scoped_refptr<DevToolsAgentHost> agent_host_; |
}; |
static bool TimeComparator(const DevToolsTarget* target1, |
@@ -612,12 +621,9 @@ void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( |
return; |
} |
- DevToolsClientHostImpl* client_host = new DevToolsClientHostImpl( |
- thread_->message_loop(), server_.get(), connection_id); |
- connection_to_client_host_ui_[connection_id] = client_host; |
- |
- DevToolsManager::GetInstance()-> |
- RegisterDevToolsClientHostFor(agent, client_host); |
+ DevToolsAgentHostClientImpl * client_host = new DevToolsAgentHostClientImpl( |
+ thread_->message_loop(), server_.get(), connection_id, agent); |
+ connection_to_client_ui_[connection_id] = client_host; |
AcceptWebSocket(connection_id, request); |
} |
@@ -625,24 +631,24 @@ void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( |
void DevToolsHttpHandlerImpl::OnWebSocketMessageUI( |
int connection_id, |
const std::string& data) { |
- ConnectionToClientHostMap::iterator it = |
- connection_to_client_host_ui_.find(connection_id); |
- if (it == connection_to_client_host_ui_.end()) |
+ ConnectionToClientMap::iterator it = |
+ connection_to_client_ui_.find(connection_id); |
+ if (it == connection_to_client_ui_.end()) |
return; |
- DevToolsManager* manager = DevToolsManager::GetInstance(); |
- manager->DispatchOnInspectorBackend(it->second, data); |
+ DevToolsAgentHostClientImpl* client = |
+ static_cast<DevToolsAgentHostClientImpl*>(it->second); |
+ client->OnMessage(data); |
} |
void DevToolsHttpHandlerImpl::OnCloseUI(int connection_id) { |
- ConnectionToClientHostMap::iterator it = |
- connection_to_client_host_ui_.find(connection_id); |
- if (it != connection_to_client_host_ui_.end()) { |
- DevToolsClientHostImpl* client_host = |
- static_cast<DevToolsClientHostImpl*>(it->second); |
- DevToolsManager::GetInstance()->ClientHostClosing(client_host); |
- delete client_host; |
- connection_to_client_host_ui_.erase(connection_id); |
+ ConnectionToClientMap::iterator it = |
+ connection_to_client_ui_.find(connection_id); |
+ if (it != connection_to_client_ui_.end()) { |
+ DevToolsAgentHostClientImpl* client = |
+ static_cast<DevToolsAgentHostClientImpl*>(it->second); |
+ delete client; |
+ connection_to_client_ui_.erase(connection_id); |
} |
} |