| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chromeos/network/dhcp_proxy_script_fetcher_chromeos.h" | 5 #include "chromeos/network/dhcp_proxy_script_fetcher_chromeos.h" |
| 6 | 6 |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/task_runner_util.h" | 8 #include "base/task_runner_util.h" |
| 9 #include "chromeos/network/network_event_log.h" | 9 #include "chromeos/network/network_event_log.h" |
| 10 #include "chromeos/network/network_handler.h" | 10 #include "chromeos/network/network_handler.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); | 26 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); |
| 27 if (default_network) | 27 if (default_network) |
| 28 return default_network->web_proxy_auto_discovery_url().spec(); | 28 return default_network->web_proxy_auto_discovery_url().spec(); |
| 29 return std::string(); | 29 return std::string(); |
| 30 } | 30 } |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 DhcpProxyScriptFetcherChromeos::DhcpProxyScriptFetcherChromeos( | 34 DhcpProxyScriptFetcherChromeos::DhcpProxyScriptFetcherChromeos( |
| 35 net::URLRequestContext* url_request_context) | 35 net::URLRequestContext* url_request_context) |
| 36 : url_request_context_(url_request_context), | 36 : weak_ptr_factory_(this) { |
| 37 weak_ptr_factory_(this) { | |
| 38 DCHECK(url_request_context_); | 37 DCHECK(url_request_context_); |
| 39 proxy_script_fetcher_.reset( | 38 proxy_script_fetcher_.reset( |
| 40 new net::ProxyScriptFetcherImpl(url_request_context_)); | 39 new net::ProxyScriptFetcherImpl(url_request_context)); |
| 41 if (NetworkHandler::IsInitialized()) | 40 if (NetworkHandler::IsInitialized()) |
| 42 network_handler_task_runner_ = NetworkHandler::Get()->task_runner(); | 41 network_handler_task_runner_ = NetworkHandler::Get()->task_runner(); |
| 43 } | 42 } |
| 44 | 43 |
| 45 DhcpProxyScriptFetcherChromeos::~DhcpProxyScriptFetcherChromeos() { | 44 DhcpProxyScriptFetcherChromeos::~DhcpProxyScriptFetcherChromeos() { |
| 46 } | 45 } |
| 47 | 46 |
| 48 int DhcpProxyScriptFetcherChromeos::Fetch( | 47 int DhcpProxyScriptFetcherChromeos::Fetch( |
| 49 base::string16* utf16_text, | 48 base::string16* utf16_text, |
| 50 const net::CompletionCallback& callback) { | 49 const net::CompletionCallback& callback) { |
| 51 if (!network_handler_task_runner_.get()) | 50 if (!network_handler_task_runner_.get()) |
| 52 return net::ERR_PAC_NOT_IN_DHCP; | 51 return net::ERR_PAC_NOT_IN_DHCP; |
| 53 CHECK(!callback.is_null()); | 52 CHECK(!callback.is_null()); |
| 54 base::PostTaskAndReplyWithResult( | 53 base::PostTaskAndReplyWithResult( |
| 55 network_handler_task_runner_.get(), FROM_HERE, | 54 network_handler_task_runner_.get(), FROM_HERE, |
| 56 base::Bind(&GetPacUrlFromDefaultNetwork), | 55 base::Bind(&GetPacUrlFromDefaultNetwork), |
| 57 base::Bind(&DhcpProxyScriptFetcherChromeos::ContinueFetch, | 56 base::Bind(&DhcpProxyScriptFetcherChromeos::ContinueFetch, |
| 58 weak_ptr_factory_.GetWeakPtr(), utf16_text, callback)); | 57 weak_ptr_factory_.GetWeakPtr(), utf16_text, callback)); |
| 59 return net::ERR_IO_PENDING; | 58 return net::ERR_IO_PENDING; |
| 60 } | 59 } |
| 61 | 60 |
| 62 void DhcpProxyScriptFetcherChromeos::Cancel() { | 61 void DhcpProxyScriptFetcherChromeos::Cancel() { |
| 63 proxy_script_fetcher_->Cancel(); | 62 proxy_script_fetcher_->Cancel(); |
| 64 // Invalidate any pending callbacks (i.e. calls to ContinueFetch). | 63 // Invalidate any pending callbacks (i.e. calls to ContinueFetch). |
| 65 weak_ptr_factory_.InvalidateWeakPtrs(); | 64 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 66 } | 65 } |
| 67 | 66 |
| 67 void DhcpProxyScriptFetcherChromeos::OnShutdown() { |
| 68 proxy_script_fetcher_.OnShutdown(); |
| 69 } |
| 70 |
| 68 const GURL& DhcpProxyScriptFetcherChromeos::GetPacURL() const { | 71 const GURL& DhcpProxyScriptFetcherChromeos::GetPacURL() const { |
| 69 return pac_url_; | 72 return pac_url_; |
| 70 } | 73 } |
| 71 | 74 |
| 72 std::string DhcpProxyScriptFetcherChromeos::GetFetcherName() const { | 75 std::string DhcpProxyScriptFetcherChromeos::GetFetcherName() const { |
| 73 return "chromeos"; | 76 return "chromeos"; |
| 74 } | 77 } |
| 75 | 78 |
| 76 void DhcpProxyScriptFetcherChromeos::ContinueFetch( | 79 void DhcpProxyScriptFetcherChromeos::ContinueFetch( |
| 77 base::string16* utf16_text, | 80 base::string16* utf16_text, |
| 78 net::CompletionCallback callback, | 81 net::CompletionCallback callback, |
| 79 std::string pac_url) { | 82 std::string pac_url) { |
| 80 NET_LOG_EVENT("DhcpProxyScriptFetcher", pac_url); | 83 NET_LOG_EVENT("DhcpProxyScriptFetcher", pac_url); |
| 81 pac_url_ = GURL(pac_url); | 84 pac_url_ = GURL(pac_url); |
| 82 if (pac_url_.is_empty()) { | 85 if (pac_url_.is_empty()) { |
| 83 callback.Run(net::ERR_PAC_NOT_IN_DHCP); | 86 callback.Run(net::ERR_PAC_NOT_IN_DHCP); |
| 84 return; | 87 return; |
| 85 } | 88 } |
| 86 int res = proxy_script_fetcher_->Fetch(pac_url_, utf16_text, callback); | 89 int res = proxy_script_fetcher_->Fetch(pac_url_, utf16_text, callback); |
| 87 if (res != net::ERR_IO_PENDING) | 90 if (res != net::ERR_IO_PENDING) |
| 88 callback.Run(res); | 91 callback.Run(res); |
| 89 } | 92 } |
| 90 | 93 |
| 91 } // namespace chromeos | 94 } // namespace chromeos |
| OLD | NEW |