| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_ | 5 #ifndef COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_ |
| 6 #define COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_ | 6 #define COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "components/ui_devtools/DOM.h" | 11 #include "components/ui_devtools/DOM.h" |
| 12 #include "components/ui_devtools/Forward.h" | 12 #include "components/ui_devtools/Forward.h" |
| 13 #include "components/ui_devtools/Protocol.h" | 13 #include "components/ui_devtools/Protocol.h" |
| 14 #include "components/ui_devtools/devtools_client.h" | 14 #include "components/ui_devtools/devtools_client.h" |
| 15 #include "components/ui_devtools/string_util.h" | 15 #include "components/ui_devtools/string_util.h" |
| 16 #include "net/server/http_server.h" | 16 #include "net/server/http_server.h" |
| 17 | 17 |
| 18 namespace ui { | 18 namespace ui { |
| 19 namespace devtools { | 19 namespace devtools { |
| 20 | 20 |
| 21 class UiDevToolsServer : public net::HttpServer::Delegate { | 21 class UiDevToolsServer : public net::HttpServer::Delegate { |
| 22 public: | 22 public: |
| 23 UiDevToolsServer(); | |
| 24 ~UiDevToolsServer() override; | 23 ~UiDevToolsServer() override; |
| 25 | 24 |
| 26 // Returns an empty unique_ptr if ui devtools flag isn't enabled. | 25 // Returns an empty unique_ptr if ui devtools flag isn't enabled. |
| 27 static std::unique_ptr<UiDevToolsServer> Create(); | 26 static std::unique_ptr<UiDevToolsServer> Create( |
| 27 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 28 | 28 |
| 29 void AttachClient(std::unique_ptr<UiDevToolsClient> client); | 29 void AttachClient(std::unique_ptr<UiDevToolsClient> client); |
| 30 void SendOverWebSocket(int connection_id, const String& message); | 30 void SendOverWebSocket(int connection_id, const String& message); |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 explicit UiDevToolsServer( |
| 34 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 35 |
| 33 void Start(const std::string& address_string, uint16_t port); | 36 void Start(const std::string& address_string, uint16_t port); |
| 34 void StartServer(const std::string& address_string, uint16_t port); | 37 void StartServer(const std::string& address_string, uint16_t port); |
| 35 | 38 |
| 36 // HttpServer::Delegate | 39 // HttpServer::Delegate |
| 37 void OnConnect(int connection_id) override; | 40 void OnConnect(int connection_id) override; |
| 38 void OnHttpRequest(int connection_id, | 41 void OnHttpRequest(int connection_id, |
| 39 const net::HttpServerRequestInfo& info) override; | 42 const net::HttpServerRequestInfo& info) override; |
| 40 void OnWebSocketRequest(int connection_id, | 43 void OnWebSocketRequest(int connection_id, |
| 41 const net::HttpServerRequestInfo& info) override; | 44 const net::HttpServerRequestInfo& info) override; |
| 42 void OnWebSocketMessage(int connection_id, const std::string& data) override; | 45 void OnWebSocketMessage(int connection_id, const std::string& data) override; |
| 43 void OnClose(int connection_id) override; | 46 void OnClose(int connection_id) override; |
| 44 | 47 |
| 45 using ClientsList = std::vector<std::unique_ptr<UiDevToolsClient>>; | 48 using ClientsList = std::vector<std::unique_ptr<UiDevToolsClient>>; |
| 46 using ConnectionsMap = std::map<uint32_t, UiDevToolsClient*>; | 49 using ConnectionsMap = std::map<uint32_t, UiDevToolsClient*>; |
| 47 ClientsList clients_; | 50 ClientsList clients_; |
| 48 ConnectionsMap connections_; | 51 ConnectionsMap connections_; |
| 49 | 52 |
| 50 // TODO(mhashmi): Inject IO thread task runner instead of creating/owning | |
| 51 // thread | |
| 52 std::unique_ptr<base::Thread> thread_; | 53 std::unique_ptr<base::Thread> thread_; |
| 53 std::unique_ptr<net::HttpServer> server_; | 54 std::unique_ptr<net::HttpServer> server_; |
| 55 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 54 | 56 |
| 55 DISALLOW_COPY_AND_ASSIGN(UiDevToolsServer); | 57 DISALLOW_COPY_AND_ASSIGN(UiDevToolsServer); |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 } // namespace devtools | 60 } // namespace devtools |
| 59 } // namespace ui | 61 } // namespace ui |
| 60 | 62 |
| 61 #endif // COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_ | 63 #endif // COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_ |
| OLD | NEW |