Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / components / devtools_service / devtools_agent_host.cc
blobd344a5991d99e068c3723e9819f166da18146569
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 #include "base/guid.h"
8 #include "base/logging.h"
10 namespace devtools_service {
12 DevToolsAgentHost::DevToolsAgentHost(DevToolsAgentPtr agent)
13 : id_(base::GenerateGUID()),
14 agent_(agent.Pass()),
15 binding_(this),
16 delegate_(nullptr) {
19 DevToolsAgentHost::~DevToolsAgentHost() {
20 if (delegate_)
21 delegate_->OnAgentHostClosed(this);
24 void DevToolsAgentHost::SetDelegate(Delegate* delegate) {
25 delegate_ = delegate;
26 if (delegate_) {
27 if (binding_.is_bound())
28 return;
30 DevToolsAgentClientPtr client;
31 binding_.Bind(&client);
32 agent_->SetClient(client.Pass(), id_);
33 } else {
34 if (!binding_.is_bound())
35 return;
37 binding_.Close();
41 void DevToolsAgentHost::SendProtocolMessageToAgent(const std::string& message) {
42 agent_->DispatchProtocolMessage(message);
45 void DevToolsAgentHost::DispatchProtocolMessage(const mojo::String& message) {
46 delegate_->DispatchProtocolMessage(this, message);
49 } // namespace devtools_service