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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 GURL DevToolsHttpHandlerImpl::GetFrontendURL() { | 255 GURL DevToolsHttpHandlerImpl::GetFrontendURL() { |
| 256 net::IPEndPoint ip_address; | 256 net::IPEndPoint ip_address; |
| 257 if (server_->GetLocalAddress(&ip_address)) | 257 if (server_->GetLocalAddress(&ip_address)) |
|
dgozman
2014/08/27 19:32:23
Please guard this, since you can have no |server_|
byungchul
2014/08/27 20:45:37
Done.
| |
| 258 return GURL(); | 258 return GURL(); |
| 259 return GURL(std::string("http://") + ip_address.ToString() + frontend_url_); | 259 return GURL(std::string("http://") + ip_address.ToString() + frontend_url_); |
| 260 } | 260 } |
| 261 | 261 |
| 262 static std::string PathWithoutParams(const std::string& path) { | 262 static std::string PathWithoutParams(const std::string& path) { |
| 263 size_t query_position = path.find("?"); | 263 size_t query_position = path.find("?"); |
| 264 if (query_position != std::string::npos) | 264 if (query_position != std::string::npos) |
| 265 return path.substr(0, query_position); | 265 return path.substr(0, query_position); |
| 266 return path; | 266 return path; |
| 267 } | 267 } |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 active_port_output_directory_(active_port_output_directory) { | 692 active_port_output_directory_(active_port_output_directory) { |
| 693 if (frontend_url_.empty()) | 693 if (frontend_url_.empty()) |
| 694 frontend_url_ = "/devtools/devtools.html"; | 694 frontend_url_ = "/devtools/devtools.html"; |
| 695 | 695 |
| 696 // Balanced in ResetHandlerThreadAndRelease(). | 696 // Balanced in ResetHandlerThreadAndRelease(). |
| 697 AddRef(); | 697 AddRef(); |
| 698 } | 698 } |
| 699 | 699 |
| 700 // Runs on the handler thread | 700 // Runs on the handler thread |
| 701 void DevToolsHttpHandlerImpl::Init() { | 701 void DevToolsHttpHandlerImpl::Init() { |
| 702 server_.reset(new net::HttpServer(server_socket_factory_->CreateAndListen(), | 702 scoped_ptr<net::ServerSocket> server_socket = |
| 703 this)); | 703 server_socket_factory_->CreateAndListen(); |
| 704 if (!server_socket) { | |
| 705 LOG(ERROR) << "Cannot start http server for devtools. Stop devtools."; | |
| 706 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 707 base::Bind(&DevToolsHttpHandlerImpl::Stop, this)); | |
|
dgozman
2014/08/27 19:32:24
This call will destroy this object, and later call
byungchul
2014/08/27 20:45:36
Done.
| |
| 708 return; | |
| 709 } | |
| 710 | |
| 711 server_.reset(new net::HttpServer(server_socket.Pass(), this)); | |
| 704 if (!active_port_output_directory_.empty()) | 712 if (!active_port_output_directory_.empty()) |
| 705 WriteActivePortToUserProfile(); | 713 WriteActivePortToUserProfile(); |
| 706 } | 714 } |
| 707 | 715 |
| 708 // Runs on the handler thread | 716 // Runs on the handler thread |
| 709 void DevToolsHttpHandlerImpl::Teardown() { | 717 void DevToolsHttpHandlerImpl::Teardown() { |
| 710 server_.reset(NULL); | 718 server_.reset(NULL); |
| 711 } | 719 } |
| 712 | 720 |
| 713 // Runs on FILE thread to make sure that it is serialized against | 721 // 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(), | 870 id.c_str(), |
| 863 host); | 871 host); |
| 864 dictionary->SetString( | 872 dictionary->SetString( |
| 865 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 873 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
| 866 } | 874 } |
| 867 | 875 |
| 868 return dictionary; | 876 return dictionary; |
| 869 } | 877 } |
| 870 | 878 |
| 871 } // namespace content | 879 } // namespace content |
| OLD | NEW |