Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(329)

Side by Side Diff: net/proxy/proxy_script_fetcher_impl.cc

Issue 6831025: Adds support for the DHCP portion of the WPAD (proxy auto-discovery) protocol. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add timeout on Win32 DHCP API. Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/proxy/proxy_script_fetcher_impl.h" 5 #include "net/proxy/proxy_script_fetcher_impl.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/i18n/icu_string_conversions.h" 8 #include "base/i18n/icu_string_conversions.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 DCHECK_EQ(request, cur_request_.get()); 108 DCHECK_EQ(request, cur_request_.get());
109 109
110 // Use |result_code_| as the request's error if we have already set it to 110 // Use |result_code_| as the request's error if we have already set it to
111 // something specific. 111 // something specific.
112 if (result_code_ == OK && !request->status().is_success()) 112 if (result_code_ == OK && !request->status().is_success())
113 result_code_ = request->status().os_error(); 113 result_code_ = request->status().os_error();
114 114
115 FetchCompleted(); 115 FetchCompleted();
116 } 116 }
117 117
118 int ProxyScriptFetcherImpl::Fetch(const GURL& url, 118 int ProxyScriptFetcherImpl::Fetch(string16* text,
119 string16* text,
120 CompletionCallback* callback) { 119 CompletionCallback* callback) {
121 // It is invalid to call Fetch() while a request is already in progress. 120 // It is invalid to call Fetch() while a request is already in progress.
122 DCHECK(!cur_request_.get()); 121 DCHECK(!cur_request_.get());
123 122
124 DCHECK(callback); 123 DCHECK(callback);
125 DCHECK(text); 124 DCHECK(text);
125 DCHECK(url_.is_valid());
126 126
127 // Handle base-64 encoded data-urls that contain custom PAC scripts. 127 // Handle base-64 encoded data-urls that contain custom PAC scripts.
128 if (url.SchemeIs("data")) { 128 if (url_.SchemeIs("data")) {
129 std::string mime_type; 129 std::string mime_type;
130 std::string charset; 130 std::string charset;
131 std::string data; 131 std::string data;
132 if (!DataURL::Parse(url, &mime_type, &charset, &data)) 132 if (!DataURL::Parse(url_, &mime_type, &charset, &data))
133 return ERR_FAILED; 133 return ERR_FAILED;
134 134
135 ConvertResponseToUTF16(charset, data, text); 135 ConvertResponseToUTF16(charset, data, text);
136 return OK; 136 return OK;
137 } 137 }
138 138
139 cur_request_.reset(new URLRequest(url, this)); 139 cur_request_.reset(new URLRequest(url_, this));
140 cur_request_->set_context(url_request_context_); 140 cur_request_->set_context(url_request_context_);
141 cur_request_->set_method("GET"); 141 cur_request_->set_method("GET");
142 142
143 // Make sure that the PAC script is downloaded using a direct connection, 143 // Make sure that the PAC script is downloaded using a direct connection,
144 // to avoid circular dependencies (fetching is a part of proxy resolution). 144 // to avoid circular dependencies (fetching is a part of proxy resolution).
145 // Also disable the use of the disk cache. The cache is disabled so that if 145 // Also disable the use of the disk cache. The cache is disabled so that if
146 // the user switches networks we don't potentially use the cached response 146 // the user switches networks we don't potentially use the cached response
147 // from old network when we should in fact be re-fetching on the new network. 147 // from old network when we should in fact be re-fetching on the new network.
148 cur_request_->set_load_flags(LOAD_BYPASS_PROXY | LOAD_DISABLE_CACHE); 148 cur_request_->set_load_flags(LOAD_BYPASS_PROXY | LOAD_DISABLE_CACHE);
149 149
(...skipping 14 matching lines...) Expand all
164 cur_request_->Start(); 164 cur_request_->Start();
165 return ERR_IO_PENDING; 165 return ERR_IO_PENDING;
166 } 166 }
167 167
168 void ProxyScriptFetcherImpl::Cancel() { 168 void ProxyScriptFetcherImpl::Cancel() {
169 // ResetCurRequestState will free the URLRequest, which will cause 169 // ResetCurRequestState will free the URLRequest, which will cause
170 // cancellation. 170 // cancellation.
171 ResetCurRequestState(); 171 ResetCurRequestState();
172 } 172 }
173 173
174 URLRequestContext* ProxyScriptFetcherImpl::GetRequestContext() { 174 URLRequestContext* ProxyScriptFetcherImpl::GetRequestContext() const {
175 return url_request_context_; 175 return url_request_context_;
176 } 176 }
177 177
178 void ProxyScriptFetcherImpl::SetURL(const GURL& url) {
179 url_ = url;
180 }
181
178 void ProxyScriptFetcherImpl::OnAuthRequired(URLRequest* request, 182 void ProxyScriptFetcherImpl::OnAuthRequired(URLRequest* request,
179 AuthChallengeInfo* auth_info) { 183 AuthChallengeInfo* auth_info) {
180 DCHECK_EQ(request, cur_request_.get()); 184 DCHECK_EQ(request, cur_request_.get());
181 // TODO(eroman): http://crbug.com/77366 185 // TODO(eroman): http://crbug.com/77366
182 LOG(WARNING) << "Auth required to fetch PAC script, aborting."; 186 LOG(WARNING) << "Auth required to fetch PAC script, aborting.";
183 result_code_ = ERR_NOT_IMPLEMENTED; 187 result_code_ = ERR_NOT_IMPLEMENTED;
184 request->CancelAuth(); 188 request->CancelAuth();
185 } 189 }
186 190
187 void ProxyScriptFetcherImpl::OnSSLCertificateError(URLRequest* request, 191 void ProxyScriptFetcherImpl::OnSSLCertificateError(URLRequest* request,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 // is still applicable. 311 // is still applicable.
308 if (cur_request_id_ != id) 312 if (cur_request_id_ != id)
309 return; 313 return;
310 314
311 DCHECK(cur_request_.get()); 315 DCHECK(cur_request_.get());
312 result_code_ = ERR_TIMED_OUT; 316 result_code_ = ERR_TIMED_OUT;
313 cur_request_->Cancel(); 317 cur_request_->Cancel();
314 } 318 }
315 319
316 } // namespace net 320 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698