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/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. |
|
sadrul
2016/11/17 18:40:57
Document that this can return null if an instance
Sarmad Hashmi
2016/11/21 17:18:24
Done.
| |
| 26 static std::unique_ptr<UiDevToolsServer> Create( | 29 static std::unique_ptr<UiDevToolsServer> Create( |
| 27 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 30 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 28 | 31 |
| 32 // Returns a list of attached UiDevToolsClient name + URL | |
| 33 using NameUrlPair = std::pair<std::string, std::string>; | |
| 34 static std::vector<NameUrlPair> GetClientNamesAndUrls(); | |
| 35 | |
| 29 void AttachClient(std::unique_ptr<UiDevToolsClient> client); | 36 void AttachClient(std::unique_ptr<UiDevToolsClient> client); |
| 30 void SendOverWebSocket(int connection_id, const String& message); | 37 void SendOverWebSocket(int connection_id, const String& message); |
| 31 | 38 |
| 32 private: | 39 private: |
| 33 explicit UiDevToolsServer( | 40 explicit UiDevToolsServer( |
| 34 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 41 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 35 | 42 |
| 36 void Start(const std::string& address_string, uint16_t port); | 43 void Start(const std::string& address_string, uint16_t port); |
| 37 void StartServer(const std::string& address_string, uint16_t port); | 44 void StartServer(const std::string& address_string, uint16_t port); |
| 38 | 45 |
| 39 // HttpServer::Delegate | 46 // HttpServer::Delegate |
| 40 void OnConnect(int connection_id) override; | 47 void OnConnect(int connection_id) override; |
| 41 void OnHttpRequest(int connection_id, | 48 void OnHttpRequest(int connection_id, |
| 42 const net::HttpServerRequestInfo& info) override; | 49 const net::HttpServerRequestInfo& info) override; |
| 43 void OnWebSocketRequest(int connection_id, | 50 void OnWebSocketRequest(int connection_id, |
| 44 const net::HttpServerRequestInfo& info) override; | 51 const net::HttpServerRequestInfo& info) override; |
| 45 void OnWebSocketMessage(int connection_id, const std::string& data) override; | 52 void OnWebSocketMessage(int connection_id, const std::string& data) override; |
| 46 void OnClose(int connection_id) override; | 53 void OnClose(int connection_id) override; |
| 47 | 54 |
| 48 using ClientsList = std::vector<std::unique_ptr<UiDevToolsClient>>; | 55 using ClientsList = std::vector<std::unique_ptr<UiDevToolsClient>>; |
| 49 using ConnectionsMap = std::map<uint32_t, UiDevToolsClient*>; | 56 using ConnectionsMap = std::map<uint32_t, UiDevToolsClient*>; |
| 50 ClientsList clients_; | 57 ClientsList clients_; |
| 51 ConnectionsMap connections_; | 58 ConnectionsMap connections_; |
| 52 | 59 |
| 53 std::unique_ptr<base::Thread> thread_; | 60 std::unique_ptr<base::Thread> thread_; |
| 54 std::unique_ptr<net::HttpServer> server_; | 61 std::unique_ptr<net::HttpServer> server_; |
| 55 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 62 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 56 | 63 |
| 64 // The server (owned by ash for now) | |
| 65 static UiDevToolsServer* devtools_server_; | |
| 66 | |
| 57 DISALLOW_COPY_AND_ASSIGN(UiDevToolsServer); | 67 DISALLOW_COPY_AND_ASSIGN(UiDevToolsServer); |
| 58 }; | 68 }; |
| 59 | 69 |
| 60 } // namespace devtools | 70 } // namespace devtools |
| 61 } // namespace ui | 71 } // namespace ui |
| 62 | 72 |
| 63 #endif // COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_ | 73 #endif // COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_ |
| OLD | NEW |