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"
14 #include "third_party/mojo/src/mojo/public/cpp/bindings/error_handler.h"
16 namespace devtools_service
{
18 // DevToolsAgentHost represents a DevTools agent at the service side.
19 class DevToolsAgentHost
: public DevToolsAgentClient
,
20 public mojo::ErrorHandler
{
24 virtual ~Delegate() {}
26 virtual void DispatchProtocolMessage(DevToolsAgentHost
* agent_host
,
27 const std::string
& message
) = 0;
29 // Notifies the delegate that |agent_host| is going away.
30 virtual void OnAgentHostClosed(DevToolsAgentHost
* agent_host
) = 0;
33 explicit DevToolsAgentHost(DevToolsAgentPtr agent
);
35 ~DevToolsAgentHost() override
;
37 void set_agent_connection_error_handler(const mojo::Closure
& handler
) {
38 agent_connection_error_handler_
= handler
;
41 std::string
id() const { return id_
; }
43 // Doesn't take ownership of |delegate|. If |delegate| dies before this
44 // object, a new delegate or nullptr must be set so that this object doesn't
45 // hold an invalid pointer.
46 void SetDelegate(Delegate
* delegate
);
48 bool IsAttached() const { return !!delegate_
; }
50 void SendProtocolMessageToAgent(const std::string
& message
);
53 // DevToolsAgentClient implementation.
54 void DispatchProtocolMessage(const mojo::String
& message
) override
;
56 // mojo::ErrorHandler implementation.
57 void OnConnectionError() override
;
59 const std::string id_
;
61 DevToolsAgentPtr agent_
;
62 mojo::Closure agent_connection_error_handler_
;
64 mojo::Binding
<DevToolsAgentClient
> binding_
;
68 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentHost
);
71 } // namespace devtools_service
73 #endif // COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_AGENT_HOST_H_