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