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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
325 void DevToolsHttpHandlerImpl::StopWithoutRelease() { | 325 void DevToolsHttpHandlerImpl::StopWithoutRelease() { |
326 if (!thread_) | 326 if (!thread_) |
327 return; | 327 return; |
328 BrowserThread::PostTaskAndReply( | 328 BrowserThread::PostTaskAndReply( |
329 BrowserThread::FILE, FROM_HERE, | 329 BrowserThread::FILE, FROM_HERE, |
330 base::Bind(&DevToolsHttpHandlerImpl::StopHandlerThread, this), | 330 base::Bind(&DevToolsHttpHandlerImpl::StopHandlerThread, this), |
331 base::Bind(&DevToolsHttpHandlerImpl::ResetHandlerThread, this)); | 331 base::Bind(&DevToolsHttpHandlerImpl::ResetHandlerThread, this)); |
332 } | 332 } |
333 | 333 |
334 GURL DevToolsHttpHandlerImpl::GetFrontendURL() { | 334 GURL DevToolsHttpHandlerImpl::GetFrontendURL() { |
335 net::IPEndPoint ip_address; | 335 base::AutoLock locked(server_ip_address_lock_); |
336 if (server_ && server_->GetLocalAddress(&ip_address)) | 336 if (!server_ip_address_) |
337 return GURL(); | 337 return GURL(); |
338 return GURL(std::string("http://") + ip_address.ToString() + frontend_url_); | 338 return GURL(std::string("http://") + server_ip_address_->ToString() + frontend _url_); |
339 } | 339 } |
340 | 340 |
341 static std::string PathWithoutParams(const std::string& path) { | 341 static std::string PathWithoutParams(const std::string& path) { |
342 size_t query_position = path.find("?"); | 342 size_t query_position = path.find("?"); |
343 if (query_position != std::string::npos) | 343 if (query_position != std::string::npos) |
344 return path.substr(0, query_position); | 344 return path.substr(0, query_position); |
345 return path; | 345 return path; |
346 } | 346 } |
347 | 347 |
348 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... | |
788 server_socket_factory_->CreateAndListen(); | 788 server_socket_factory_->CreateAndListen(); |
789 if (!server_socket) { | 789 if (!server_socket) { |
790 LOG(ERROR) << "Cannot start http server for devtools. Stop devtools."; | 790 LOG(ERROR) << "Cannot start http server for devtools. Stop devtools."; |
791 BrowserThread::PostTask( | 791 BrowserThread::PostTask( |
792 BrowserThread::UI, FROM_HERE, | 792 BrowserThread::UI, FROM_HERE, |
793 base::Bind(&DevToolsHttpHandlerImpl::StopWithoutRelease, this)); | 793 base::Bind(&DevToolsHttpHandlerImpl::StopWithoutRelease, this)); |
794 return; | 794 return; |
795 } | 795 } |
796 | 796 |
797 server_.reset(new net::HttpServer(server_socket.Pass(), this)); | 797 server_.reset(new net::HttpServer(server_socket.Pass(), this)); |
798 { | |
799 base::AutoLock locked(server_ip_address_lock_); | |
vkuzkokov
2014/10/22 13:20:03
Use of locks is very limited in chromium, especial
byungwoo
2014/10/23 02:10:20
Thank you for the review and suggestion.
I'll appl
| |
800 server_ip_address_.reset(new net::IPEndPoint()); | |
801 server_->GetLocalAddress(server_ip_address_.get()); | |
802 } | |
798 if (!active_port_output_directory_.empty()) | 803 if (!active_port_output_directory_.empty()) |
799 WriteActivePortToUserProfile(); | 804 WriteActivePortToUserProfile(); |
800 } | 805 } |
801 | 806 |
802 // Runs on the handler thread | 807 // Runs on the handler thread |
803 void DevToolsHttpHandlerImpl::Teardown() { | 808 void DevToolsHttpHandlerImpl::Teardown() { |
809 { | |
810 base::AutoLock locked(server_ip_address_lock_); | |
811 server_ip_address_.reset(NULL); | |
812 } | |
804 server_.reset(NULL); | 813 server_.reset(NULL); |
805 } | 814 } |
806 | 815 |
807 // Runs on FILE thread to make sure that it is serialized against | 816 // Runs on FILE thread to make sure that it is serialized against |
808 // {Start|Stop}HandlerThread and to allow calling pthread_join. | 817 // {Start|Stop}HandlerThread and to allow calling pthread_join. |
809 void DevToolsHttpHandlerImpl::StopHandlerThread() { | 818 void DevToolsHttpHandlerImpl::StopHandlerThread() { |
810 if (!thread_->message_loop()) | 819 if (!thread_->message_loop()) |
811 return; | 820 return; |
812 thread_->message_loop()->PostTask( | 821 thread_->message_loop()->PostTask( |
813 FROM_HERE, | 822 FROM_HERE, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
959 id.c_str(), | 968 id.c_str(), |
960 host); | 969 host); |
961 dictionary->SetString( | 970 dictionary->SetString( |
962 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 971 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
963 } | 972 } |
964 | 973 |
965 return dictionary; | 974 return dictionary; |
966 } | 975 } |
967 | 976 |
968 } // namespace content | 977 } // namespace content |
OLD | NEW |