OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_AGENT_HOST_H_ |
| 6 #define COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_AGENT_HOST_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 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" |
| 15 |
| 16 namespace devtools_service { |
| 17 |
| 18 // DevToolsAgentHost represents a DevTools agent at the service side. |
| 19 class DevToolsAgentHost : public DevToolsAgentClient, |
| 20 public mojo::ErrorHandler { |
| 21 public: |
| 22 class Delegate { |
| 23 public: |
| 24 virtual ~Delegate() {} |
| 25 |
| 26 virtual void DispatchProtocolMessage(DevToolsAgentHost* agent_host, |
| 27 const std::string& message) = 0; |
| 28 |
| 29 // Notifies the delegate that |agent_host| is going away. |
| 30 virtual void OnAgentHostClosed(DevToolsAgentHost* agent_host) = 0; |
| 31 }; |
| 32 |
| 33 explicit DevToolsAgentHost(DevToolsAgentPtr agent); |
| 34 |
| 35 ~DevToolsAgentHost() override; |
| 36 |
| 37 void set_agent_connection_error_handler(const mojo::Closure& handler) { |
| 38 agent_connection_error_handler_ = handler; |
| 39 } |
| 40 |
| 41 std::string id() const { return id_; } |
| 42 |
| 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); |
| 47 |
| 48 bool IsAttached() const { return !!delegate_; } |
| 49 |
| 50 void SendProtocolMessageToAgent(const std::string& message); |
| 51 |
| 52 private: |
| 53 // DevToolsAgentClient implementation. |
| 54 void DispatchProtocolMessage(const mojo::String& message) override; |
| 55 |
| 56 // mojo::ErrorHandler implementation. |
| 57 void OnConnectionError() override; |
| 58 |
| 59 const std::string id_; |
| 60 |
| 61 DevToolsAgentPtr agent_; |
| 62 mojo::Closure agent_connection_error_handler_; |
| 63 |
| 64 mojo::Binding<DevToolsAgentClient> binding_; |
| 65 |
| 66 Delegate* delegate_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentHost); |
| 69 }; |
| 70 |
| 71 } // namespace devtools_service |
| 72 |
| 73 #endif // COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_AGENT_HOST_H_ |
OLD | NEW |