Chromium Code Reviews| 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 "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" |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 void DevToolsHttpHandlerImpl::StopWithoutRelease() { | 326 void DevToolsHttpHandlerImpl::StopWithoutRelease() { |
| 327 if (!thread_) | 327 if (!thread_) |
| 328 return; | 328 return; |
| 329 BrowserThread::PostTaskAndReply( | 329 BrowserThread::PostTaskAndReply( |
| 330 BrowserThread::FILE, FROM_HERE, | 330 BrowserThread::FILE, FROM_HERE, |
| 331 base::Bind(&DevToolsHttpHandlerImpl::StopHandlerThread, this), | 331 base::Bind(&DevToolsHttpHandlerImpl::StopHandlerThread, this), |
| 332 base::Bind(&DevToolsHttpHandlerImpl::ResetHandlerThread, this)); | 332 base::Bind(&DevToolsHttpHandlerImpl::ResetHandlerThread, this)); |
| 333 } | 333 } |
| 334 | 334 |
| 335 GURL DevToolsHttpHandlerImpl::GetFrontendURL() { | 335 GURL DevToolsHttpHandlerImpl::GetFrontendURL() { |
| 336 net::IPEndPoint ip_address; | 336 if (!server_ip_address_) |
|
pfeldman
2014/10/21 11:32:47
This is called on the UI thread.
| |
| 337 if (server_ && server_->GetLocalAddress(&ip_address)) | |
| 338 return GURL(); | 337 return GURL(); |
| 339 return GURL(std::string("http://") + ip_address.ToString() + frontend_url_); | 338 return GURL(std::string("http://") + server_ip_address_->ToString() + frontend _url_); |
| 340 } | 339 } |
| 341 | 340 |
| 342 static std::string PathWithoutParams(const std::string& path) { | 341 static std::string PathWithoutParams(const std::string& path) { |
| 343 size_t query_position = path.find("?"); | 342 size_t query_position = path.find("?"); |
| 344 if (query_position != std::string::npos) | 343 if (query_position != std::string::npos) |
| 345 return path.substr(0, query_position); | 344 return path.substr(0, query_position); |
| 346 return path; | 345 return path; |
| 347 } | 346 } |
| 348 | 347 |
| 349 static std::string GetMimeType(const std::string& filename) { | 348 static std::string GetMimeType(const std::string& filename) { |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 789 server_socket_factory_->CreateAndListen(); | 788 server_socket_factory_->CreateAndListen(); |
| 790 if (!server_socket) { | 789 if (!server_socket) { |
| 791 LOG(ERROR) << "Cannot start http server for devtools. Stop devtools."; | 790 LOG(ERROR) << "Cannot start http server for devtools. Stop devtools."; |
| 792 BrowserThread::PostTask( | 791 BrowserThread::PostTask( |
| 793 BrowserThread::UI, FROM_HERE, | 792 BrowserThread::UI, FROM_HERE, |
| 794 base::Bind(&DevToolsHttpHandlerImpl::StopWithoutRelease, this)); | 793 base::Bind(&DevToolsHttpHandlerImpl::StopWithoutRelease, this)); |
| 795 return; | 794 return; |
| 796 } | 795 } |
| 797 | 796 |
| 798 server_.reset(new net::HttpServer(server_socket.Pass(), this)); | 797 server_.reset(new net::HttpServer(server_socket.Pass(), this)); |
| 798 net::IPEndPoint ip_address; | |
| 799 server_->GetLocalAddress(&ip_address); | |
| 800 server_ip_address_.reset(new net::IPEndPoint(ip_address)); | |
|
pfeldman
2014/10/21 11:32:47
This is called on the handler thread.
| |
| 799 if (!active_port_output_directory_.empty()) | 801 if (!active_port_output_directory_.empty()) |
| 800 WriteActivePortToUserProfile(); | 802 WriteActivePortToUserProfile(); |
| 801 } | 803 } |
| 802 | 804 |
| 803 // Runs on the handler thread | 805 // Runs on the handler thread |
| 804 void DevToolsHttpHandlerImpl::Teardown() { | 806 void DevToolsHttpHandlerImpl::Teardown() { |
| 807 server_ip_address_.reset(NULL); | |
| 805 server_.reset(NULL); | 808 server_.reset(NULL); |
| 806 } | 809 } |
| 807 | 810 |
| 808 // Runs on FILE thread to make sure that it is serialized against | 811 // Runs on FILE thread to make sure that it is serialized against |
| 809 // {Start|Stop}HandlerThread and to allow calling pthread_join. | 812 // {Start|Stop}HandlerThread and to allow calling pthread_join. |
| 810 void DevToolsHttpHandlerImpl::StopHandlerThread() { | 813 void DevToolsHttpHandlerImpl::StopHandlerThread() { |
| 811 if (!thread_->message_loop()) | 814 if (!thread_->message_loop()) |
| 812 return; | 815 return; |
| 813 thread_->message_loop()->PostTask( | 816 thread_->message_loop()->PostTask( |
| 814 FROM_HERE, | 817 FROM_HERE, |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 960 id.c_str(), | 963 id.c_str(), |
| 961 host); | 964 host); |
| 962 dictionary->SetString( | 965 dictionary->SetString( |
| 963 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 966 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
| 964 } | 967 } |
| 965 | 968 |
| 966 return dictionary; | 969 return dictionary; |
| 967 } | 970 } |
| 968 | 971 |
| 969 } // namespace content | 972 } // namespace content |
| OLD | NEW |