OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 UI_DEVTOOLS_DEVTOOLS_SERVER_H_ | |
6 #define UI_DEVTOOLS_DEVTOOLS_SERVER_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/threading/thread.h" | |
11 #include "net/server/http_server.h" | |
12 #include "ui/devtools/DOM.h" | |
13 #include "ui/devtools/Forward.h" | |
14 #include "ui/devtools/Protocol.h" | |
15 #include "ui/devtools/devtools_client.h" | |
16 #include "ui/devtools/string_util.h" | |
17 | |
18 namespace ui { | |
19 namespace devtools { | |
20 | |
21 class UiDevToolsServer : public net::HttpServer::Delegate { | |
22 public: | |
23 UiDevToolsServer(); | |
24 ~UiDevToolsServer() override; | |
25 | |
26 static std::unique_ptr<UiDevToolsServer> Create(); | |
sadrul
2016/10/18 01:09:15
Document that this can return null.
Sarmad Hashmi
2016/10/18 02:40:49
Done.
| |
27 | |
28 void AttachClient(std::unique_ptr<UiDevToolsClient> client); | |
29 void SendOverWebSocket(int connection_id, const String& message); | |
30 | |
31 private: | |
32 void Start(const std::string& address_string, uint16_t port); | |
33 void StartServer(const std::string& address_string, uint16_t port); | |
34 | |
35 // HttpServer::Delegate | |
36 void OnConnect(int connection_id) override; | |
37 void OnHttpRequest(int connection_id, | |
38 const net::HttpServerRequestInfo& info) override; | |
39 void OnWebSocketRequest(int connection_id, | |
40 const net::HttpServerRequestInfo& info) override; | |
41 void OnWebSocketMessage(int connection_id, const std::string& data) override; | |
42 void OnClose(int connection_id) override; | |
43 | |
44 using ClientsList = std::vector<std::unique_ptr<UiDevToolsClient>>; | |
45 using ConnectionsMap = std::map<uint32_t, UiDevToolsClient*>; | |
46 ClientsList clients_; | |
47 ConnectionsMap connections_; | |
48 | |
49 // TODO(mhashmi): Inject IO thread task runner instead of creating/owning | |
50 // thread | |
51 std::unique_ptr<base::Thread> thread_; | |
52 std::unique_ptr<net::HttpServer> server_; | |
53 | |
54 DISALLOW_COPY_AND_ASSIGN(UiDevToolsServer); | |
55 }; | |
56 | |
57 } // namespace devtools | |
58 } // namespace ui | |
59 | |
60 #endif // UI_DEVTOOLS_DEVTOOLS_SERVER_H_ | |
OLD | NEW |