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 #ifndef COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_AGENT_HOST_H_
6 #define COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_AGENT_HOST_H_
10 #include "base/macros.h"
11 #include "components/devtools_service/public/interfaces/devtools_service.mojom.h"
12 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
13 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h"
15 namespace devtools_service
{
17 // DevToolsAgentHost represents a DevTools agent at the service side.
18 class DevToolsAgentHost
: public DevToolsAgentClient
{
22 virtual ~Delegate() {}
24 virtual void DispatchProtocolMessage(DevToolsAgentHost
* agent_host
,
25 const std::string
& message
) = 0;
27 // Notifies the delegate that |agent_host| is going away.
28 virtual void OnAgentHostClosed(DevToolsAgentHost
* agent_host
) = 0;
31 DevToolsAgentHost(const std::string
& id
, DevToolsAgentPtr agent
);
33 ~DevToolsAgentHost() override
;
35 void set_agent_connection_error_handler(const mojo::Closure
& handler
) {
36 agent_
.set_connection_error_handler(handler
);
39 std::string
id() const { return id_
; }
41 // Doesn't take ownership of |delegate|. If |delegate| dies before this
42 // object, a new delegate or nullptr must be set so that this object doesn't
43 // hold an invalid pointer.
44 void SetDelegate(Delegate
* delegate
);
46 bool IsAttached() const { return !!delegate_
; }
48 void SendProtocolMessageToAgent(const std::string
& message
);
51 // DevToolsAgentClient implementation.
52 void DispatchProtocolMessage(int32_t call_id
,
53 const mojo::String
& message
,
54 const mojo::String
& state
) override
;
56 const std::string id_
;
58 DevToolsAgentPtr agent_
;
60 mojo::Binding
<DevToolsAgentClient
> binding_
;
64 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentHost
);
67 } // namespace devtools_service
69 #endif // COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_AGENT_HOST_H_