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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 245 |
246 void DevToolsHttpHandlerImpl::Stop() { | 246 void DevToolsHttpHandlerImpl::Stop() { |
247 if (!thread_) | 247 if (!thread_) |
248 return; | 248 return; |
249 BrowserThread::PostTaskAndReply( | 249 BrowserThread::PostTaskAndReply( |
250 BrowserThread::FILE, FROM_HERE, | 250 BrowserThread::FILE, FROM_HERE, |
251 base::Bind(&DevToolsHttpHandlerImpl::StopHandlerThread, this), | 251 base::Bind(&DevToolsHttpHandlerImpl::StopHandlerThread, this), |
252 base::Bind(&DevToolsHttpHandlerImpl::ResetHandlerThreadAndRelease, this)); | 252 base::Bind(&DevToolsHttpHandlerImpl::ResetHandlerThreadAndRelease, this)); |
253 } | 253 } |
254 | 254 |
| 255 void DevToolsHttpHandlerImpl::StopWithoutRelease() { |
| 256 if (!thread_) |
| 257 return; |
| 258 BrowserThread::PostTaskAndReply( |
| 259 BrowserThread::FILE, FROM_HERE, |
| 260 base::Bind(&DevToolsHttpHandlerImpl::StopHandlerThread, this), |
| 261 base::Bind(&DevToolsHttpHandlerImpl::ResetHandlerThread, this)); |
| 262 } |
| 263 |
255 GURL DevToolsHttpHandlerImpl::GetFrontendURL() { | 264 GURL DevToolsHttpHandlerImpl::GetFrontendURL() { |
256 net::IPEndPoint ip_address; | 265 net::IPEndPoint ip_address; |
257 if (server_->GetLocalAddress(&ip_address)) | 266 if (server_ && server_->GetLocalAddress(&ip_address)) |
258 return GURL(); | 267 return GURL(); |
259 return GURL(std::string("http://") + ip_address.ToString() + frontend_url_); | 268 return GURL(std::string("http://") + ip_address.ToString() + frontend_url_); |
260 } | 269 } |
261 | 270 |
262 static std::string PathWithoutParams(const std::string& path) { | 271 static std::string PathWithoutParams(const std::string& path) { |
263 size_t query_position = path.find("?"); | 272 size_t query_position = path.find("?"); |
264 if (query_position != std::string::npos) | 273 if (query_position != std::string::npos) |
265 return path.substr(0, query_position); | 274 return path.substr(0, query_position); |
266 return path; | 275 return path; |
267 } | 276 } |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 active_port_output_directory_(active_port_output_directory) { | 701 active_port_output_directory_(active_port_output_directory) { |
693 if (frontend_url_.empty()) | 702 if (frontend_url_.empty()) |
694 frontend_url_ = "/devtools/devtools.html"; | 703 frontend_url_ = "/devtools/devtools.html"; |
695 | 704 |
696 // Balanced in ResetHandlerThreadAndRelease(). | 705 // Balanced in ResetHandlerThreadAndRelease(). |
697 AddRef(); | 706 AddRef(); |
698 } | 707 } |
699 | 708 |
700 // Runs on the handler thread | 709 // Runs on the handler thread |
701 void DevToolsHttpHandlerImpl::Init() { | 710 void DevToolsHttpHandlerImpl::Init() { |
702 server_.reset(new net::HttpServer(server_socket_factory_->CreateAndListen(), | 711 scoped_ptr<net::ServerSocket> server_socket = |
703 this)); | 712 server_socket_factory_->CreateAndListen(); |
| 713 if (!server_socket) { |
| 714 LOG(ERROR) << "Cannot start http server for devtools. Stop devtools."; |
| 715 BrowserThread::PostTask( |
| 716 BrowserThread::UI, FROM_HERE, |
| 717 base::Bind(&DevToolsHttpHandlerImpl::StopWithoutRelease, this)); |
| 718 return; |
| 719 } |
| 720 |
| 721 server_.reset(new net::HttpServer(server_socket.Pass(), this)); |
704 if (!active_port_output_directory_.empty()) | 722 if (!active_port_output_directory_.empty()) |
705 WriteActivePortToUserProfile(); | 723 WriteActivePortToUserProfile(); |
706 } | 724 } |
707 | 725 |
708 // Runs on the handler thread | 726 // Runs on the handler thread |
709 void DevToolsHttpHandlerImpl::Teardown() { | 727 void DevToolsHttpHandlerImpl::Teardown() { |
710 server_.reset(NULL); | 728 server_.reset(NULL); |
711 } | 729 } |
712 | 730 |
713 // Runs on FILE thread to make sure that it is serialized against | 731 // Runs on FILE thread to make sure that it is serialized against |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 id.c_str(), | 880 id.c_str(), |
863 host); | 881 host); |
864 dictionary->SetString( | 882 dictionary->SetString( |
865 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 883 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
866 } | 884 } |
867 | 885 |
868 return dictionary; | 886 return dictionary; |
869 } | 887 } |
870 | 888 |
871 } // namespace content | 889 } // namespace content |
OLD | NEW |