Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / devtools_service / devtools_agent_host.cc
blob30b2287216c30d9fdce7e1f02efb2e90b5a59145
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
3 // found in the LICENSE file.
5 #include "components/devtools_service/devtools_agent_host.h"
7 namespace devtools_service {
9 DevToolsAgentHost::DevToolsAgentHost(const std::string& id,
10 DevToolsAgentPtr agent)
11 : id_(id), agent_(agent.Pass()), binding_(this), delegate_(nullptr) {}
13 DevToolsAgentHost::~DevToolsAgentHost() {
14 if (delegate_)
15 delegate_->OnAgentHostClosed(this);
18 void DevToolsAgentHost::SetDelegate(Delegate* delegate) {
19 delegate_ = delegate;
20 if (delegate_) {
21 if (binding_.is_bound())
22 return;
24 DevToolsAgentClientPtr client;
25 binding_.Bind(&client);
26 agent_->SetClient(client.Pass());
27 } else {
28 if (!binding_.is_bound())
29 return;
31 binding_.Close();
35 void DevToolsAgentHost::SendProtocolMessageToAgent(const std::string& message) {
36 agent_->DispatchProtocolMessage(message);
39 void DevToolsAgentHost::DispatchProtocolMessage(int32_t call_id,
40 const mojo::String& message,
41 const mojo::String& state) {
42 delegate_->DispatchProtocolMessage(this, message);
45 } // namespace devtools_service