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 #include <algorithm> | 5 #include <algorithm> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 246 |
247 void ServerWrapper::Close(int connection_id) { | 247 void ServerWrapper::Close(int connection_id) { |
248 server_->Close(connection_id); | 248 server_->Close(connection_id); |
249 } | 249 } |
250 | 250 |
251 // Thread and ServerWrapper lifetime management ------------------------------ | 251 // Thread and ServerWrapper lifetime management ------------------------------ |
252 | 252 |
253 void TerminateOnUI(base::Thread* thread, | 253 void TerminateOnUI(base::Thread* thread, |
254 ServerWrapper* server_wrapper, | 254 ServerWrapper* server_wrapper, |
255 DevToolsHttpHandler::ServerSocketFactory* socket_factory) { | 255 DevToolsHttpHandler::ServerSocketFactory* socket_factory) { |
256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 256 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
257 if (server_wrapper) { | 257 if (server_wrapper) { |
258 DCHECK(thread); | 258 DCHECK(thread); |
259 thread->message_loop()->DeleteSoon(FROM_HERE, server_wrapper); | 259 thread->message_loop()->DeleteSoon(FROM_HERE, server_wrapper); |
260 } | 260 } |
261 if (socket_factory) { | 261 if (socket_factory) { |
262 DCHECK(thread); | 262 DCHECK(thread); |
263 thread->message_loop()->DeleteSoon(FROM_HERE, socket_factory); | 263 thread->message_loop()->DeleteSoon(FROM_HERE, socket_factory); |
264 } | 264 } |
265 if (thread) { | 265 if (thread) { |
266 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, thread); | 266 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, thread); |
267 } | 267 } |
268 } | 268 } |
269 | 269 |
270 void ServerStartedOnUI( | 270 void ServerStartedOnUI( |
271 base::WeakPtr<DevToolsHttpHandlerImpl> handler, | 271 base::WeakPtr<DevToolsHttpHandlerImpl> handler, |
272 base::Thread* thread, | 272 base::Thread* thread, |
273 ServerWrapper* server_wrapper, | 273 ServerWrapper* server_wrapper, |
274 DevToolsHttpHandler::ServerSocketFactory* socket_factory, | 274 DevToolsHttpHandler::ServerSocketFactory* socket_factory, |
275 scoped_ptr<net::IPEndPoint> ip_address) { | 275 scoped_ptr<net::IPEndPoint> ip_address) { |
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 276 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
277 if (handler && thread && server_wrapper) { | 277 if (handler && thread && server_wrapper) { |
278 handler->ServerStarted(thread, server_wrapper, socket_factory, | 278 handler->ServerStarted(thread, server_wrapper, socket_factory, |
279 ip_address.Pass()); | 279 ip_address.Pass()); |
280 } else { | 280 } else { |
281 TerminateOnUI(thread, server_wrapper, socket_factory); | 281 TerminateOnUI(thread, server_wrapper, socket_factory); |
282 } | 282 } |
283 } | 283 } |
284 | 284 |
285 void StartServerOnHandlerThread( | 285 void StartServerOnHandlerThread( |
286 base::WeakPtr<DevToolsHttpHandlerImpl> handler, | 286 base::WeakPtr<DevToolsHttpHandlerImpl> handler, |
(...skipping 27 matching lines...) Expand all Loading... |
314 server_socket_factory, | 314 server_socket_factory, |
315 base::Passed(&ip_address))); | 315 base::Passed(&ip_address))); |
316 } | 316 } |
317 | 317 |
318 void StartServerOnFile( | 318 void StartServerOnFile( |
319 base::WeakPtr<DevToolsHttpHandlerImpl> handler, | 319 base::WeakPtr<DevToolsHttpHandlerImpl> handler, |
320 DevToolsHttpHandler::ServerSocketFactory* server_socket_factory, | 320 DevToolsHttpHandler::ServerSocketFactory* server_socket_factory, |
321 const base::FilePath& output_directory, | 321 const base::FilePath& output_directory, |
322 const base::FilePath& frontend_dir, | 322 const base::FilePath& frontend_dir, |
323 bool bundles_resources) { | 323 bool bundles_resources) { |
324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 324 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
325 scoped_ptr<base::Thread> thread(new base::Thread(kDevToolsHandlerThreadName)); | 325 scoped_ptr<base::Thread> thread(new base::Thread(kDevToolsHandlerThreadName)); |
326 base::Thread::Options options; | 326 base::Thread::Options options; |
327 options.message_loop_type = base::MessageLoop::TYPE_IO; | 327 options.message_loop_type = base::MessageLoop::TYPE_IO; |
328 if (thread->StartWithOptions(options)) { | 328 if (thread->StartWithOptions(options)) { |
329 base::MessageLoop* message_loop = thread->message_loop(); | 329 base::MessageLoop* message_loop = thread->message_loop(); |
330 message_loop->PostTask(FROM_HERE, | 330 message_loop->PostTask(FROM_HERE, |
331 base::Bind(&StartServerOnHandlerThread, | 331 base::Bind(&StartServerOnHandlerThread, |
332 handler, | 332 handler, |
333 base::Unretained(thread.release()), | 333 base::Unretained(thread.release()), |
334 server_socket_factory, | 334 server_socket_factory, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 devtools::tracing::TracingHandler::Browser)), | 425 devtools::tracing::TracingHandler::Browser)), |
426 protocol_handler_(new DevToolsProtocolHandler( | 426 protocol_handler_(new DevToolsProtocolHandler( |
427 base::Bind(&BrowserTarget::Respond, base::Unretained(this)))) { | 427 base::Bind(&BrowserTarget::Respond, base::Unretained(this)))) { |
428 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); | 428 DevToolsProtocolDispatcher* dispatcher = protocol_handler_->dispatcher(); |
429 dispatcher->SetSystemInfoHandler(system_info_handler_.get()); | 429 dispatcher->SetSystemInfoHandler(system_info_handler_.get()); |
430 dispatcher->SetTetheringHandler(tethering_handler_.get()); | 430 dispatcher->SetTetheringHandler(tethering_handler_.get()); |
431 dispatcher->SetTracingHandler(tracing_handler_.get()); | 431 dispatcher->SetTracingHandler(tracing_handler_.get()); |
432 } | 432 } |
433 | 433 |
434 void HandleMessage(const std::string& message) { | 434 void HandleMessage(const std::string& message) { |
435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 435 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
436 std::string error_response; | 436 std::string error_response; |
437 scoped_ptr<base::DictionaryValue> command = | 437 scoped_ptr<base::DictionaryValue> command = |
438 protocol_handler_->ParseCommand(message); | 438 protocol_handler_->ParseCommand(message); |
439 if (command) | 439 if (command) |
440 protocol_handler_->HandleCommand(command.Pass()); | 440 protocol_handler_->HandleCommand(command.Pass()); |
441 } | 441 } |
442 | 442 |
443 void Respond(const std::string& message) { | 443 void Respond(const std::string& message) { |
444 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 444 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
445 message_loop_->PostTask( | 445 message_loop_->PostTask( |
446 FROM_HERE, | 446 FROM_HERE, |
447 base::Bind(&ServerWrapper::SendOverWebSocket, | 447 base::Bind(&ServerWrapper::SendOverWebSocket, |
448 base::Unretained(server_wrapper_), | 448 base::Unretained(server_wrapper_), |
449 connection_id_, | 449 connection_id_, |
450 message)); | 450 message)); |
451 } | 451 } |
452 | 452 |
453 private: | 453 private: |
454 base::MessageLoop* const message_loop_; | 454 base::MessageLoop* const message_loop_; |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 id.c_str(), | 1119 id.c_str(), |
1120 host); | 1120 host); |
1121 dictionary->SetString( | 1121 dictionary->SetString( |
1122 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 1122 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
1123 } | 1123 } |
1124 | 1124 |
1125 return dictionary; | 1125 return dictionary; |
1126 } | 1126 } |
1127 | 1127 |
1128 } // namespace content | 1128 } // namespace content |
OLD | NEW |