OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ |
6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ | 6 #define CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 16 matching lines...) Expand all Loading... | |
27 class Value; | 27 class Value; |
28 } | 28 } |
29 | 29 |
30 namespace net { | 30 namespace net { |
31 class ServerSocketFactory; | 31 class ServerSocketFactory; |
32 class URLRequestContextGetter; | 32 class URLRequestContextGetter; |
33 } | 33 } |
34 | 34 |
35 namespace content { | 35 namespace content { |
36 | 36 |
37 class DevToolsHttpHandlerImpl | 37 class DevToolsHttpHandlerImpl : public DevToolsHttpHandler { |
38 : public DevToolsHttpHandler, | |
39 public base::RefCountedThreadSafe<DevToolsHttpHandlerImpl>, | |
40 public net::HttpServer::Delegate { | |
41 private: | 38 private: |
42 friend class base::RefCountedThreadSafe<DevToolsHttpHandlerImpl>; | |
43 friend class DevToolsHttpHandler; | 39 friend class DevToolsHttpHandler; |
44 | 40 |
45 class BrowserTarget; | 41 class BrowserTarget; |
42 class ServerWrapper; | |
43 class AgentHostClientImpl; | |
46 | 44 |
47 DevToolsHttpHandlerImpl(scoped_ptr<ServerSocketFactory> server_socket_factory, | 45 DevToolsHttpHandlerImpl(scoped_ptr<ServerSocketFactory> server_socket_factory, |
48 const std::string& frontend_url, | 46 const std::string& frontend_url, |
49 DevToolsHttpHandlerDelegate* delegate, | 47 DevToolsHttpHandlerDelegate* delegate, |
50 const base::FilePath& active_port_output_directory); | 48 const base::FilePath& output_directory); |
51 ~DevToolsHttpHandlerImpl() override; | 49 ~DevToolsHttpHandlerImpl() override; |
52 void Start(); | |
53 | 50 |
54 // DevToolsHttpHandler implementation. | 51 // DevToolsHttpHandler implementation. |
55 void Stop() override; | 52 void Stop() override; |
56 GURL GetFrontendURL() override; | 53 GURL GetFrontendURL() override; |
57 | 54 |
58 // net::HttpServer::Delegate implementation. | 55 void OnJsonRequest(int connection_id, |
dgozman
2014/11/07 13:03:55
Can we extract meaningful methods to a separate "d
vkuzkokov
2014/11/10 09:04:34
Extracted to static methods.
| |
59 void OnConnect(int connection_id) override {} | 56 const net::HttpServerRequestInfo& info); |
60 void OnHttpRequest(int connection_id, | 57 void OnThumbnailRequest(int connection_id, const std::string& target_id); |
61 const net::HttpServerRequestInfo& info) override; | 58 void OnDiscoveryPageRequest(int connection_id); |
59 | |
62 void OnWebSocketRequest(int connection_id, | 60 void OnWebSocketRequest(int connection_id, |
63 const net::HttpServerRequestInfo& info) override; | 61 const net::HttpServerRequestInfo& info); |
64 void OnWebSocketMessage(int connection_id, const std::string& data) override; | 62 void OnWebSocketMessage(int connection_id, const std::string& data); |
65 void OnClose(int connection_id) override; | 63 void OnClose(int connection_id); |
66 | 64 |
67 void OnJsonRequestUI(int connection_id, | 65 static void OnTargetListReceivedWeak( |
dgozman
2014/11/07 13:03:56
Let's comment on the purpose of this method.
vkuzkokov
2014/11/10 09:04:34
File removed.
| |
68 const net::HttpServerRequestInfo& info); | 66 base::WeakPtr<DevToolsHttpHandlerImpl> handler, |
69 void OnThumbnailRequestUI(int connection_id, const GURL& page_url); | 67 int connection_id, |
70 void OnDiscoveryPageRequestUI(int connection_id); | 68 const std::string& host, |
71 | 69 const DevToolsManagerDelegate::TargetList& targets); |
72 void OnWebSocketRequestUI(int connection_id, | |
73 const net::HttpServerRequestInfo& info); | |
74 void OnWebSocketMessageUI(int connection_id, const std::string& data); | |
75 void OnCloseUI(int connection_id); | |
76 | |
77 void ResetHandlerThread(); | |
78 void ResetHandlerThreadAndRelease(); | |
79 | 70 |
80 void OnTargetListReceived( | 71 void OnTargetListReceived( |
81 int connection_id, | 72 int connection_id, |
82 const std::string& host, | 73 const std::string& host, |
83 const DevToolsManagerDelegate::TargetList& targets); | 74 const DevToolsManagerDelegate::TargetList& targets); |
84 | 75 |
85 void OnHttpServerInitialized(const net::IPEndPoint& ip_address); | |
86 | |
87 DevToolsTarget* GetTarget(const std::string& id); | 76 DevToolsTarget* GetTarget(const std::string& id); |
88 | 77 |
89 void Init(); | 78 void ThreadStarted(scoped_ptr<ServerSocketFactory> server_socket_factory, |
90 void Teardown(); | 79 const base::FilePath& output_directory, |
80 scoped_ptr<base::Thread> thread); | |
81 void ServerStarted(scoped_ptr<ServerWrapper> server, | |
82 scoped_ptr<net::IPEndPoint> ip_address); | |
91 | 83 |
92 void StartHandlerThread(); | |
93 void StopHandlerThread(); | 84 void StopHandlerThread(); |
94 void StopWithoutRelease(); | |
95 | |
96 void WriteActivePortToUserProfile(); | |
97 | 85 |
98 void SendJson(int connection_id, | 86 void SendJson(int connection_id, |
99 net::HttpStatusCode status_code, | 87 net::HttpStatusCode status_code, |
100 base::Value* value, | 88 base::Value* value, |
101 const std::string& message); | 89 const std::string& message); |
102 void Send200(int connection_id, | 90 void Send200(int connection_id, |
103 const std::string& data, | 91 const std::string& data, |
104 const std::string& mime_type); | 92 const std::string& mime_type); |
105 void Send404(int connection_id); | 93 void Send404(int connection_id); |
106 void Send500(int connection_id, | 94 void Send500(int connection_id, |
107 const std::string& message); | 95 const std::string& message); |
108 void AcceptWebSocket(int connection_id, | 96 void AcceptWebSocket(int connection_id, |
109 const net::HttpServerRequestInfo& request); | 97 const net::HttpServerRequestInfo& request); |
110 | 98 |
111 // Returns the front end url without the host at the beginning. | 99 // Returns the front end url without the host at the beginning. |
112 std::string GetFrontendURLInternal(const std::string target_id, | 100 std::string GetFrontendURLInternal(const std::string target_id, |
113 const std::string& host); | 101 const std::string& host); |
114 | 102 |
115 base::DictionaryValue* SerializeTarget(const DevToolsTarget& target, | 103 base::DictionaryValue* SerializeTarget(const DevToolsTarget& target, |
116 const std::string& host); | 104 const std::string& host); |
117 | 105 |
118 // The thread used by the devtools handler to run server socket. | 106 // The thread used by the devtools handler to run server socket. |
119 scoped_ptr<base::Thread> thread_; | 107 scoped_ptr<base::Thread> thread_; |
120 | 108 |
121 std::string frontend_url_; | 109 std::string frontend_url_; |
122 const scoped_ptr<ServerSocketFactory> server_socket_factory_; | 110 scoped_ptr<ServerWrapper> server_; |
dgozman
2014/11/07 13:03:55
Let's call this |server_wrapper_|.
vkuzkokov
2014/11/10 09:04:34
Done.
| |
123 scoped_ptr<net::HttpServer> server_; | |
124 scoped_ptr<net::IPEndPoint> server_ip_address_; | 111 scoped_ptr<net::IPEndPoint> server_ip_address_; |
125 typedef std::map<int, DevToolsAgentHostClient*> ConnectionToClientMap; | 112 typedef std::map<int, AgentHostClientImpl*> ConnectionToClientMap; |
126 ConnectionToClientMap connection_to_client_ui_; | 113 ConnectionToClientMap connection_to_client_; |
127 const scoped_ptr<DevToolsHttpHandlerDelegate> delegate_; | 114 const scoped_ptr<DevToolsHttpHandlerDelegate> delegate_; |
128 const base::FilePath active_port_output_directory_; | |
129 typedef std::map<std::string, DevToolsTarget*> TargetMap; | 115 typedef std::map<std::string, DevToolsTarget*> TargetMap; |
130 TargetMap target_map_; | 116 TargetMap target_map_; |
131 typedef std::map<int, BrowserTarget*> BrowserTargets; | 117 typedef std::map<int, BrowserTarget*> BrowserTargets; |
132 BrowserTargets browser_targets_; | 118 BrowserTargets browser_targets_; |
119 base::WeakPtrFactory<DevToolsHttpHandlerImpl> weak_factory_; | |
120 | |
133 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandlerImpl); | 121 DISALLOW_COPY_AND_ASSIGN(DevToolsHttpHandlerImpl); |
134 }; | 122 }; |
135 | 123 |
136 } // namespace content | 124 } // namespace content |
137 | 125 |
138 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ | 126 #endif // CONTENT_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_HANDLER_IMPL_H_ |
OLD | NEW |