| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/devtools_service/devtools_agent_host.h" | 5 #include "components/devtools_service/devtools_agent_host.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 namespace devtools_service { | 9 namespace devtools_service { |
| 10 | 10 |
| 11 DevToolsAgentHost::DevToolsAgentHost(const std::string& id, | 11 DevToolsAgentHost::DevToolsAgentHost(const std::string& id, |
| 12 DevToolsAgentPtr agent) | 12 DevToolsAgentPtr agent) |
| 13 : id_(id), agent_(std::move(agent)), binding_(this), delegate_(nullptr) {} | 13 : id_(id), agent_(std::move(agent)), binding_(this), delegate_(nullptr) {} |
| 14 | 14 |
| 15 DevToolsAgentHost::~DevToolsAgentHost() { | 15 DevToolsAgentHost::~DevToolsAgentHost() { |
| 16 if (delegate_) | 16 if (delegate_) |
| 17 delegate_->OnAgentHostClosed(this); | 17 delegate_->OnAgentHostClosed(this); |
| 18 } | 18 } |
| 19 | 19 |
| 20 void DevToolsAgentHost::SetDelegate(Delegate* delegate) { | 20 void DevToolsAgentHost::SetDelegate(Delegate* delegate) { |
| 21 delegate_ = delegate; | 21 delegate_ = delegate; |
| 22 if (delegate_) { | 22 if (delegate_) { |
| 23 if (binding_.is_bound()) | 23 if (binding_.is_bound()) |
| 24 return; | 24 return; |
| 25 | 25 |
| 26 DevToolsAgentClientPtr client; | 26 agent_->SetClient(binding_.CreateInterfacePtrAndBind()); |
| 27 binding_.Bind(&client); | |
| 28 agent_->SetClient(std::move(client)); | |
| 29 } else { | 27 } else { |
| 30 if (!binding_.is_bound()) | 28 if (!binding_.is_bound()) |
| 31 return; | 29 return; |
| 32 | 30 |
| 33 binding_.Close(); | 31 binding_.Close(); |
| 34 } | 32 } |
| 35 } | 33 } |
| 36 | 34 |
| 37 void DevToolsAgentHost::SendProtocolMessageToAgent(const std::string& message) { | 35 void DevToolsAgentHost::SendProtocolMessageToAgent(const std::string& message) { |
| 38 agent_->DispatchProtocolMessage(message); | 36 agent_->DispatchProtocolMessage(message); |
| 39 } | 37 } |
| 40 | 38 |
| 41 void DevToolsAgentHost::DispatchProtocolMessage(int32_t call_id, | 39 void DevToolsAgentHost::DispatchProtocolMessage(int32_t call_id, |
| 42 const mojo::String& message, | 40 const mojo::String& message, |
| 43 const mojo::String& state) { | 41 const mojo::String& state) { |
| 44 delegate_->DispatchProtocolMessage(this, message); | 42 delegate_->DispatchProtocolMessage(this, message); |
| 45 } | 43 } |
| 46 | 44 |
| 47 } // namespace devtools_service | 45 } // namespace devtools_service |
| OLD | NEW |