| 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/compiler_specific.h" |
| 10 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 11 #include "components/ui_devtools/DOM.h" | 12 #include "components/ui_devtools/DOM.h" |
| 12 #include "components/ui_devtools/Forward.h" | 13 #include "components/ui_devtools/Forward.h" |
| 13 #include "components/ui_devtools/Protocol.h" | 14 #include "components/ui_devtools/Protocol.h" |
| 14 #include "components/ui_devtools/devtools_client.h" | 15 #include "components/ui_devtools/devtools_client.h" |
| 16 #include "components/ui_devtools/devtools_export.h" |
| 15 #include "components/ui_devtools/string_util.h" | 17 #include "components/ui_devtools/string_util.h" |
| 16 #include "net/server/http_server.h" | 18 #include "net/server/http_server.h" |
| 17 | 19 |
| 18 namespace ui { | 20 namespace ui { |
| 19 namespace devtools { | 21 namespace devtools { |
| 20 | 22 |
| 21 class UiDevToolsServer : public net::HttpServer::Delegate { | 23 class UI_DEVTOOLS_EXPORT UiDevToolsServer |
| 24 : public NON_EXPORTED_BASE(net::HttpServer::Delegate) { |
| 22 public: | 25 public: |
| 23 ~UiDevToolsServer() override; | 26 ~UiDevToolsServer() override; |
| 24 | 27 |
| 25 // Returns an empty unique_ptr if ui devtools flag isn't enabled. | 28 // Returns an empty unique_ptr if ui devtools flag isn't enabled or if a |
| 29 // server instance has already been created. |
| 26 static std::unique_ptr<UiDevToolsServer> Create( | 30 static std::unique_ptr<UiDevToolsServer> Create( |
| 27 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 31 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 28 | 32 |
| 33 // Returns a list of attached UiDevToolsClient name + URL |
| 34 using NameUrlPair = std::pair<std::string, std::string>; |
| 35 static std::vector<NameUrlPair> GetClientNamesAndUrls(); |
| 36 |
| 29 void AttachClient(std::unique_ptr<UiDevToolsClient> client); | 37 void AttachClient(std::unique_ptr<UiDevToolsClient> client); |
| 30 void SendOverWebSocket(int connection_id, const String& message); | 38 void SendOverWebSocket(int connection_id, const String& message); |
| 31 | 39 |
| 32 private: | 40 private: |
| 33 explicit UiDevToolsServer( | 41 explicit UiDevToolsServer( |
| 34 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 42 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 35 | 43 |
| 36 void Start(const std::string& address_string, uint16_t port); | 44 void Start(const std::string& address_string, uint16_t port); |
| 37 void StartServer(const std::string& address_string, uint16_t port); | 45 void StartServer(const std::string& address_string, uint16_t port); |
| 38 | 46 |
| 39 // HttpServer::Delegate | 47 // HttpServer::Delegate |
| 40 void OnConnect(int connection_id) override; | 48 void OnConnect(int connection_id) override; |
| 41 void OnHttpRequest(int connection_id, | 49 void OnHttpRequest(int connection_id, |
| 42 const net::HttpServerRequestInfo& info) override; | 50 const net::HttpServerRequestInfo& info) override; |
| 43 void OnWebSocketRequest(int connection_id, | 51 void OnWebSocketRequest(int connection_id, |
| 44 const net::HttpServerRequestInfo& info) override; | 52 const net::HttpServerRequestInfo& info) override; |
| 45 void OnWebSocketMessage(int connection_id, const std::string& data) override; | 53 void OnWebSocketMessage(int connection_id, const std::string& data) override; |
| 46 void OnClose(int connection_id) override; | 54 void OnClose(int connection_id) override; |
| 47 | 55 |
| 48 using ClientsList = std::vector<std::unique_ptr<UiDevToolsClient>>; | 56 using ClientsList = std::vector<std::unique_ptr<UiDevToolsClient>>; |
| 49 using ConnectionsMap = std::map<uint32_t, UiDevToolsClient*>; | 57 using ConnectionsMap = std::map<uint32_t, UiDevToolsClient*>; |
| 50 ClientsList clients_; | 58 ClientsList clients_; |
| 51 ConnectionsMap connections_; | 59 ConnectionsMap connections_; |
| 52 | 60 |
| 53 std::unique_ptr<base::Thread> thread_; | 61 std::unique_ptr<base::Thread> thread_; |
| 54 std::unique_ptr<net::HttpServer> server_; | 62 std::unique_ptr<net::HttpServer> server_; |
| 55 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 63 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 56 | 64 |
| 65 // The server (owned by ash for now) |
| 66 static UiDevToolsServer* devtools_server_; |
| 67 |
| 57 DISALLOW_COPY_AND_ASSIGN(UiDevToolsServer); | 68 DISALLOW_COPY_AND_ASSIGN(UiDevToolsServer); |
| 58 }; | 69 }; |
| 59 | 70 |
| 60 } // namespace devtools | 71 } // namespace devtools |
| 61 } // namespace ui | 72 } // namespace ui |
| 62 | 73 |
| 63 #endif // COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_ | 74 #endif // COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_ |
| OLD | NEW |