Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: components/ui_devtools/devtools_server.h

Issue 2455833002: Pass task_runner_ to server and send 404 when incorrect url (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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(); 23 UiDevToolsServer(scoped_refptr<base::SingleThreadTaskRunner> task_runner);
sadrul 2016/10/28 02:32:27 explicit
Sarmad Hashmi 2016/10/28 17:02:46 Done.
24 ~UiDevToolsServer() override; 24 ~UiDevToolsServer() override;
25 25
26 // Returns an empty unique_ptr if ui devtools flag isn't enabled. 26 // Returns an empty unique_ptr if ui devtools flag isn't enabled.
27 static std::unique_ptr<UiDevToolsServer> Create(); 27 static std::unique_ptr<UiDevToolsServer> Create(
28 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
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:
33 void Start(const std::string& address_string, uint16_t port); 34 void Start(const std::string& address_string, uint16_t port);
34 void StartServer(const std::string& address_string, uint16_t port); 35 void StartServer(const std::string& address_string, uint16_t port);
35 36
36 // HttpServer::Delegate 37 // HttpServer::Delegate
37 void OnConnect(int connection_id) override; 38 void OnConnect(int connection_id) override;
38 void OnHttpRequest(int connection_id, 39 void OnHttpRequest(int connection_id,
39 const net::HttpServerRequestInfo& info) override; 40 const net::HttpServerRequestInfo& info) override;
40 void OnWebSocketRequest(int connection_id, 41 void OnWebSocketRequest(int connection_id,
41 const net::HttpServerRequestInfo& info) override; 42 const net::HttpServerRequestInfo& info) override;
42 void OnWebSocketMessage(int connection_id, const std::string& data) override; 43 void OnWebSocketMessage(int connection_id, const std::string& data) override;
43 void OnClose(int connection_id) override; 44 void OnClose(int connection_id) override;
44 45
45 using ClientsList = std::vector<std::unique_ptr<UiDevToolsClient>>; 46 using ClientsList = std::vector<std::unique_ptr<UiDevToolsClient>>;
46 using ConnectionsMap = std::map<uint32_t, UiDevToolsClient*>; 47 using ConnectionsMap = std::map<uint32_t, UiDevToolsClient*>;
47 ClientsList clients_; 48 ClientsList clients_;
48 ConnectionsMap connections_; 49 ConnectionsMap connections_;
49 50
50 // TODO(mhashmi): Inject IO thread task runner instead of creating/owning 51 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
51 // thread
52 std::unique_ptr<base::Thread> thread_;
53 std::unique_ptr<net::HttpServer> server_; 52 std::unique_ptr<net::HttpServer> server_;
54 53
55 DISALLOW_COPY_AND_ASSIGN(UiDevToolsServer); 54 DISALLOW_COPY_AND_ASSIGN(UiDevToolsServer);
56 }; 55 };
57 56
58 } // namespace devtools 57 } // namespace devtools
59 } // namespace ui 58 } // namespace ui
60 59
61 #endif // COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_ 60 #endif // COMPONENTS_UI_DEVTOOLS_DEVTOOLS_SERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698