Chromium Code Reviews| 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 static std::unique_ptr<UiDevToolsServer> Create( | |
| 28 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
|
sadrul
2016/10/29 05:39:51
I would remove the default version (i.e. without p
Sarmad Hashmi
2016/10/29 16:26:19
Done.
| |
| 28 | 29 |
| 29 void AttachClient(std::unique_ptr<UiDevToolsClient> client); | 30 void AttachClient(std::unique_ptr<UiDevToolsClient> client); |
| 30 void SendOverWebSocket(int connection_id, const String& message); | 31 void SendOverWebSocket(int connection_id, const String& message); |
| 31 | 32 |
| 32 private: | 33 private: |
| 34 UiDevToolsServer(); | |
| 35 explicit UiDevToolsServer( | |
| 36 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | |
| 37 | |
| 33 void Start(const std::string& address_string, uint16_t port); | 38 void Start(const std::string& address_string, uint16_t port); |
| 34 void StartServer(const std::string& address_string, uint16_t port); | 39 void StartServer(const std::string& address_string, uint16_t port); |
| 35 | 40 |
| 36 // HttpServer::Delegate | 41 // HttpServer::Delegate |
| 37 void OnConnect(int connection_id) override; | 42 void OnConnect(int connection_id) override; |
| 38 void OnHttpRequest(int connection_id, | 43 void OnHttpRequest(int connection_id, |
| 39 const net::HttpServerRequestInfo& info) override; | 44 const net::HttpServerRequestInfo& info) override; |
| 40 void OnWebSocketRequest(int connection_id, | 45 void OnWebSocketRequest(int connection_id, |
| 41 const net::HttpServerRequestInfo& info) override; | 46 const net::HttpServerRequestInfo& info) override; |
| 42 void OnWebSocketMessage(int connection_id, const std::string& data) override; | 47 void OnWebSocketMessage(int connection_id, const std::string& data) override; |
| 43 void OnClose(int connection_id) override; | 48 void OnClose(int connection_id) override; |
| 44 | 49 |
| 45 using ClientsList = std::vector<std::unique_ptr<UiDevToolsClient>>; | 50 using ClientsList = std::vector<std::unique_ptr<UiDevToolsClient>>; |
| 46 using ConnectionsMap = std::map<uint32_t, UiDevToolsClient*>; | 51 using ConnectionsMap = std::map<uint32_t, UiDevToolsClient*>; |
| 47 ClientsList clients_; | 52 ClientsList clients_; |
| 48 ConnectionsMap connections_; | 53 ConnectionsMap connections_; |
| 49 | 54 |
| 50 // TODO(mhashmi): Inject IO thread task runner instead of creating/owning | |
| 51 // thread | |
| 52 std::unique_ptr<base::Thread> thread_; | 55 std::unique_ptr<base::Thread> thread_; |
| 53 std::unique_ptr<net::HttpServer> server_; | 56 std::unique_ptr<net::HttpServer> server_; |
| 57 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 54 | 58 |
| 55 DISALLOW_COPY_AND_ASSIGN(UiDevToolsServer); | 59 DISALLOW_COPY_AND_ASSIGN(UiDevToolsServer); |
| 56 }; | 60 }; |
| 57 | 61 |
| 58 } // namespace devtools | 62 } // namespace devtools |
| 59 } // namespace ui | 63 } // namespace ui |
| 60 | 64 |
| 61 #endif // COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_ | 65 #endif // COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_ |
| OLD | NEW |