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

Side by Side Diff: content/browser/devtools/devtools_http_handler_impl.cc

Issue 635733003: [DevTools] Migrate DevToolsTracingHandler to generated handler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 2 months 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 (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 #include "content/browser/devtools/devtools_http_handler_impl.h" 5 #include "content/browser/devtools/devtools_http_handler_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "content/browser/devtools/devtools_manager.h" 20 #include "content/browser/devtools/devtools_manager.h"
21 #include "content/browser/devtools/devtools_protocol.h" 21 #include "content/browser/devtools/devtools_protocol.h"
22 #include "content/browser/devtools/devtools_protocol_constants.h" 22 #include "content/browser/devtools/devtools_protocol_constants.h"
23 #include "content/browser/devtools/devtools_system_info_handler.h" 23 #include "content/browser/devtools/devtools_system_info_handler.h"
24 #include "content/browser/devtools/devtools_tracing_handler.h" 24 #include "content/browser/devtools/protocol/devtools_protocol_handler_impl.h"
25 #include "content/browser/devtools/protocol/tracing_handler.h"
25 #include "content/browser/devtools/tethering_handler.h" 26 #include "content/browser/devtools/tethering_handler.h"
26 #include "content/common/devtools_messages.h" 27 #include "content/common/devtools_messages.h"
27 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/devtools_agent_host.h" 29 #include "content/public/browser/devtools_agent_host.h"
29 #include "content/public/browser/devtools_http_handler_delegate.h" 30 #include "content/public/browser/devtools_http_handler_delegate.h"
30 #include "content/public/browser/devtools_target.h" 31 #include "content/public/browser/devtools_target.h"
31 #include "content/public/common/content_client.h" 32 #include "content/public/common/content_client.h"
32 #include "content/public/common/url_constants.h" 33 #include "content/public/common/url_constants.h"
33 #include "content/public/common/user_agent.h" 34 #include "content/public/common/user_agent.h"
34 #include "grit/devtools_resources_map.h" 35 #include "grit/devtools_resources_map.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 153
153 // DevToolsHttpHandlerImpl::BrowserTarget ------------------------------------ 154 // DevToolsHttpHandlerImpl::BrowserTarget ------------------------------------
154 155
155 class DevToolsHttpHandlerImpl::BrowserTarget { 156 class DevToolsHttpHandlerImpl::BrowserTarget {
156 public: 157 public:
157 BrowserTarget(base::MessageLoop* message_loop, 158 BrowserTarget(base::MessageLoop* message_loop,
158 net::HttpServer* server, 159 net::HttpServer* server,
159 int connection_id) 160 int connection_id)
160 : message_loop_(message_loop), 161 : message_loop_(message_loop),
161 server_(server), 162 server_(server),
162 connection_id_(connection_id) { 163 connection_id_(connection_id),
164 tracing_handler_(new devtools::tracing::TracingHandler(
165 devtools::tracing::TracingHandler::Browser)),
166 protocol_handler_(new DevToolsProtocolHandlerImpl()) {
167 protocol_handler_->SetNotifier(
168 base::Bind(&BrowserTarget::Respond, base::Unretained(this)));
169 protocol_handler_->SetTracingHandler(tracing_handler_.get());
163 } 170 }
164 171
165 ~BrowserTarget() { 172 ~BrowserTarget() {
166 STLDeleteElements(&handlers_); 173 STLDeleteElements(&handlers_);
167 } 174 }
168 175
169 // Takes ownership. 176 // Takes ownership.
170 void RegisterHandler(DevToolsProtocol::Handler* handler) { 177 void RegisterHandler(DevToolsProtocol::Handler* handler) {
171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
172 handler->SetNotifier( 179 handler->SetNotifier(
173 base::Bind(&BrowserTarget::Respond, base::Unretained(this))); 180 base::Bind(&BrowserTarget::Respond, base::Unretained(this)));
174 handlers_.push_back(handler); 181 handlers_.push_back(handler);
175 } 182 }
176 183
177 void HandleMessage(const std::string& message) { 184 void HandleMessage(const std::string& message) {
178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
179 std::string error_response; 186 std::string error_response;
180 scoped_refptr<DevToolsProtocol::Command> command = 187 scoped_refptr<DevToolsProtocol::Command> command =
181 DevToolsProtocol::ParseCommand(message, &error_response); 188 DevToolsProtocol::ParseCommand(message, &error_response);
182 if (!command.get()) { 189 if (!command.get()) {
183 Respond(error_response); 190 Respond(error_response);
184 return; 191 return;
185 } 192 }
186 193
194 scoped_refptr<DevToolsProtocol::Response> response =
195 protocol_handler_->HandleCommand(command);
187 for (const auto& handler : handlers_) { 196 for (const auto& handler : handlers_) {
188 scoped_refptr<DevToolsProtocol::Response> response = 197 if (response.get())
189 handler->HandleCommand(command); 198 break;
190 if (response.get()) { 199 response = handler->HandleCommand(command);
191 if (!response->is_async_promise())
192 Respond(response->Serialize());
193 return;
194 }
195 } 200 }
196 201
197 Respond(command->NoSuchMethodErrorResponse()->Serialize()); 202 if (response.get()) {
203 if (!response->is_async_promise())
204 Respond(response->Serialize());
205 } else {
206 Respond(command->NoSuchMethodErrorResponse()->Serialize());
207 }
198 } 208 }
199 209
200 void Respond(const std::string& message) { 210 void Respond(const std::string& message) {
201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
202 message_loop_->PostTask( 212 message_loop_->PostTask(
203 FROM_HERE, 213 FROM_HERE,
204 base::Bind(&net::HttpServer::SendOverWebSocket, 214 base::Bind(&net::HttpServer::SendOverWebSocket,
205 base::Unretained(server_), 215 base::Unretained(server_),
206 connection_id_, 216 connection_id_,
207 message)); 217 message));
208 } 218 }
209 219
210 private: 220 private:
211 base::MessageLoop* const message_loop_; 221 base::MessageLoop* const message_loop_;
212 net::HttpServer* const server_; 222 net::HttpServer* const server_;
213 const int connection_id_; 223 const int connection_id_;
224 scoped_ptr<devtools::tracing::TracingHandler> tracing_handler_;
225 scoped_ptr<DevToolsProtocolHandlerImpl> protocol_handler_;
214 std::vector<DevToolsProtocol::Handler*> handlers_; 226 std::vector<DevToolsProtocol::Handler*> handlers_;
215 }; 227 };
216 228
217 // DevToolsHttpHandler ------------------------------------------------------- 229 // DevToolsHttpHandler -------------------------------------------------------
218 230
219 // static 231 // static
220 bool DevToolsHttpHandler::IsSupportedProtocolVersion( 232 bool DevToolsHttpHandler::IsSupportedProtocolVersion(
221 const std::string& version) { 233 const std::string& version) {
222 return devtools::IsSupportedProtocolVersion(version); 234 return devtools::IsSupportedProtocolVersion(version);
223 } 235 }
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 const net::HttpServerRequestInfo& request) { 697 const net::HttpServerRequestInfo& request) {
686 if (!thread_) 698 if (!thread_)
687 return; 699 return;
688 700
689 std::string browser_prefix = "/devtools/browser"; 701 std::string browser_prefix = "/devtools/browser";
690 size_t browser_pos = request.path.find(browser_prefix); 702 size_t browser_pos = request.path.find(browser_prefix);
691 if (browser_pos == 0) { 703 if (browser_pos == 0) {
692 BrowserTarget* browser_target = new BrowserTarget( 704 BrowserTarget* browser_target = new BrowserTarget(
693 thread_->message_loop(), server_.get(), connection_id); 705 thread_->message_loop(), server_.get(), connection_id);
694 browser_target->RegisterHandler( 706 browser_target->RegisterHandler(
695 new DevToolsTracingHandler(DevToolsTracingHandler::Browser));
696 browser_target->RegisterHandler(
697 new TetheringHandler(delegate_.get(), thread_->message_loop_proxy())); 707 new TetheringHandler(delegate_.get(), thread_->message_loop_proxy()));
698 browser_target->RegisterHandler( 708 browser_target->RegisterHandler(
699 new DevToolsSystemInfoHandler()); 709 new DevToolsSystemInfoHandler());
700 browser_targets_[connection_id] = browser_target; 710 browser_targets_[connection_id] = browser_target;
701 AcceptWebSocket(connection_id, request); 711 AcceptWebSocket(connection_id, request);
702 return; 712 return;
703 } 713 }
704 714
705 size_t pos = request.path.find(kPageUrlPrefix); 715 size_t pos = request.path.find(kPageUrlPrefix);
706 if (pos != 0) { 716 if (pos != 0) {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 id.c_str(), 970 id.c_str(),
961 host); 971 host);
962 dictionary->SetString( 972 dictionary->SetString(
963 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); 973 kTargetDevtoolsFrontendUrlField, devtools_frontend_url);
964 } 974 }
965 975
966 return dictionary; 976 return dictionary;
967 } 977 }
968 978
969 } // namespace content 979 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698