| Index: chrome/browser/devtools/device/devtools_android_bridge.cc
|
| diff --git a/chrome/browser/devtools/device/devtools_android_bridge.cc b/chrome/browser/devtools/device/devtools_android_bridge.cc
|
| index e58a8572e8a499ce1d075ba2dec3f1b1fa08b46e..c25c4699d204fccaff523286fac09269557dcca8 100644
|
| --- a/chrome/browser/devtools/device/devtools_android_bridge.cc
|
| +++ b/chrome/browser/devtools/device/devtools_android_bridge.cc
|
| @@ -186,12 +186,11 @@
|
| private:
|
| virtual void OnSocketOpened() OVERRIDE;
|
| virtual void OnFrameRead(const std::string& message) OVERRIDE;
|
| - virtual void OnSocketClosed() OVERRIDE;
|
| - virtual ~ProtocolCommand();
|
| + virtual void OnSocketClosed(bool closed_by_device) OVERRIDE;
|
|
|
| const std::string command_;
|
| const base::Closure callback_;
|
| - scoped_ptr<DevToolsAndroidBridge::AndroidWebSocket> web_socket_;
|
| + scoped_refptr<DevToolsAndroidBridge::AndroidWebSocket> web_socket_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ProtocolCommand);
|
| };
|
| @@ -202,8 +201,9 @@
|
| const std::string& command,
|
| const base::Closure callback)
|
| : command_(command),
|
| - callback_(callback),
|
| - web_socket_(browser->CreateWebSocket(debug_url, this)) {
|
| + callback_(callback){
|
| + web_socket_ = browser->CreateWebSocket(debug_url, this);
|
| + web_socket_->Connect();
|
| }
|
|
|
| void ProtocolCommand::OnSocketOpened() {
|
| @@ -211,16 +211,14 @@
|
| }
|
|
|
| void ProtocolCommand::OnFrameRead(const std::string& message) {
|
| + web_socket_->Disconnect();
|
| +}
|
| +
|
| +void ProtocolCommand::OnSocketClosed(bool closed_by_device) {
|
| + if (!callback_.is_null()) {
|
| + callback_.Run();
|
| + }
|
| delete this;
|
| -}
|
| -
|
| -void ProtocolCommand::OnSocketClosed() {
|
| - delete this;
|
| -}
|
| -
|
| -ProtocolCommand::~ProtocolCommand() {
|
| - if (!callback_.is_null())
|
| - callback_.Run();
|
| }
|
|
|
| } // namespace
|
| @@ -293,15 +291,14 @@
|
| const std::string& message) OVERRIDE;
|
| virtual void OnSocketOpened() OVERRIDE;
|
| virtual void OnFrameRead(const std::string& message) OVERRIDE;
|
| - virtual void OnSocketClosed() OVERRIDE;
|
| + virtual void OnSocketClosed(bool closed_by_device) OVERRIDE;
|
|
|
| const std::string id_;
|
| - scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser_;
|
| - const std::string debug_url_;
|
| bool socket_opened_;
|
| + bool detached_;
|
| bool is_web_view_;
|
| std::vector<std::string> pending_messages_;
|
| - scoped_ptr<DevToolsAndroidBridge::AndroidWebSocket> web_socket_;
|
| + scoped_refptr<DevToolsAndroidBridge::AndroidWebSocket> web_socket_;
|
| content::DevToolsAgentHost* agent_host_;
|
| content::DevToolsExternalAgentProxy* proxy_;
|
| DISALLOW_COPY_AND_ASSIGN(AgentHostDelegate);
|
| @@ -330,10 +327,10 @@
|
| scoped_refptr<DevToolsAndroidBridge::RemoteBrowser> browser,
|
| const std::string& debug_url)
|
| : id_(id),
|
| - browser_(browser),
|
| - debug_url_(debug_url),
|
| socket_opened_(false),
|
| + detached_(false),
|
| is_web_view_(browser->IsWebView()),
|
| + web_socket_(browser->CreateWebSocket(debug_url, this)),
|
| agent_host_(NULL),
|
| proxy_(NULL) {
|
| g_host_delegates.Get()[id] = this;
|
| @@ -341,17 +338,20 @@
|
|
|
| AgentHostDelegate::~AgentHostDelegate() {
|
| g_host_delegates.Get().erase(id_);
|
| + web_socket_->ClearDelegate();
|
| }
|
|
|
| void AgentHostDelegate::Attach(content::DevToolsExternalAgentProxy* proxy) {
|
| proxy_ = proxy;
|
| content::RecordAction(base::UserMetricsAction(is_web_view_ ?
|
| "DevTools_InspectAndroidWebView" : "DevTools_InspectAndroidPage"));
|
| - web_socket_.reset(browser_->CreateWebSocket(debug_url_, this));
|
| + web_socket_->Connect();
|
| }
|
|
|
| void AgentHostDelegate::Detach() {
|
| - web_socket_.reset();
|
| + detached_ = true;
|
| + if (socket_opened_)
|
| + web_socket_->Disconnect();
|
| }
|
|
|
| void AgentHostDelegate::SendMessageToBackend(const std::string& message) {
|
| @@ -362,6 +362,11 @@
|
| }
|
|
|
| void AgentHostDelegate::OnSocketOpened() {
|
| + if (detached_) {
|
| + web_socket_->Disconnect();
|
| + return;
|
| + }
|
| +
|
| socket_opened_ = true;
|
| for (std::vector<std::string>::iterator it = pending_messages_.begin();
|
| it != pending_messages_.end(); ++it) {
|
| @@ -375,8 +380,8 @@
|
| proxy_->DispatchOnClientHost(message);
|
| }
|
|
|
| -void AgentHostDelegate::OnSocketClosed() {
|
| - if (proxy_)
|
| +void AgentHostDelegate::OnSocketClosed(bool closed_by_device) {
|
| + if (proxy_ && closed_by_device)
|
| proxy_->ConnectionClosed();
|
| }
|
|
|
| @@ -609,7 +614,7 @@
|
| "adb:" + device_->serial() + ":" + socket_, this, kBrowserTargetSocket);
|
| }
|
|
|
| -DevToolsAndroidBridge::AndroidWebSocket*
|
| +scoped_refptr<DevToolsAndroidBridge::AndroidWebSocket>
|
| DevToolsAndroidBridge::RemoteBrowser::CreateWebSocket(
|
| const std::string& url,
|
| DevToolsAndroidBridge::AndroidWebSocket::Delegate* delegate) {
|
|
|