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_SERVICE_H_
6 #define COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_SERVICE_H_
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/devtools_service/public/interfaces/devtools_service.mojom.h"
13 #include "mojo/common/weak_binding_set.h"
14 #include "mojo/services/network/public/interfaces/http_connection.mojom.h"
15 #include "mojo/services/network/public/interfaces/http_server.mojom.h"
18 class ApplicationImpl
;
21 namespace devtools_service
{
23 // DevToolsService is the central control. It manages the communication with
24 // DevTools agents (e.g., Web page renderers). It also starts an HTTP server to
25 // speak the Chrome remote debugging protocol.
26 class DevToolsService
: public DevToolsRegistry
,
27 public DevToolsCoordinator
,
28 public mojo::HttpServerDelegate
{
30 // Doesn't take ownership of |application|, which must outlive this object.
31 explicit DevToolsService(mojo::ApplicationImpl
* application
);
32 ~DevToolsService() override
;
34 void BindToRegistryRequest(mojo::InterfaceRequest
<DevToolsRegistry
> request
);
35 void BindToCoordinatorRequest(
36 mojo::InterfaceRequest
<DevToolsCoordinator
> request
);
39 class HttpConnectionDelegateImpl
;
41 // DevToolsCoordinator implementation.
42 void Initialize(uint16_t remote_debugging_port
) override
;
44 // DevToolsRegistry implementation.
45 void RegisterAgent(DevToolsAgentPtr agent
) override
;
47 // mojo::HttpServerDelegate implementation.
49 mojo::HttpConnectionPtr connection
,
50 mojo::InterfaceRequest
<mojo::HttpConnectionDelegate
> delegate
) override
;
52 bool IsInitialized() const { return !!http_server_delegate_binding_
; }
54 // The following methods are called by HttpConnectionDelegateImpl.
55 using OnReceivedRequestCallback
=
56 mojo::HttpConnectionDelegate::OnReceivedRequestCallback
;
57 void OnReceivedRequest(HttpConnectionDelegateImpl
* connection
,
58 mojo::HttpRequestPtr request
,
59 const OnReceivedRequestCallback
& callback
);
61 using OnReceivedWebSocketRequestCallback
=
62 mojo::HttpConnectionDelegate::OnReceivedWebSocketRequestCallback
;
63 void OnReceivedWebSocketRequest(
64 HttpConnectionDelegateImpl
* connection
,
65 mojo::HttpRequestPtr request
,
66 const OnReceivedWebSocketRequestCallback
& callback
);
68 void OnConnectionClosed(HttpConnectionDelegateImpl
* connection
);
70 // Not owned by this object.
71 mojo::ApplicationImpl
* const application_
;
73 mojo::WeakBindingSet
<DevToolsCoordinator
> coordinator_bindings_
;
75 scoped_ptr
<mojo::Binding
<mojo::HttpServerDelegate
>>
76 http_server_delegate_binding_
;
79 std::set
<HttpConnectionDelegateImpl
*> connections_
;
81 DISALLOW_COPY_AND_ASSIGN(DevToolsService
);
84 } // namespace devtools_service
86 #endif // COMPONENTS_DEVTOOLS_SERVICE_DEVTOOLS_SERVICE_H_