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 "net/url_request/url_request_ftp_job.h" | 5 #include "net/url_request/url_request_ftp_job.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "net/base/auth.h" | 10 #include "net/base/auth.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 } else if (result < 0) { | 250 } else if (result < 0) { |
251 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 251 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
252 } else { | 252 } else { |
253 // Clear the IO_PENDING status | 253 // Clear the IO_PENDING status |
254 SetStatus(URLRequestStatus()); | 254 SetStatus(URLRequestStatus()); |
255 } | 255 } |
256 NotifyReadComplete(result); | 256 NotifyReadComplete(result); |
257 } | 257 } |
258 | 258 |
259 void URLRequestFtpJob::RestartTransactionWithAuth() { | 259 void URLRequestFtpJob::RestartTransactionWithAuth() { |
260 DCHECK(auth_data_ && auth_data_->state == AUTH_STATE_HAVE_AUTH); | 260 DCHECK(auth_data_.get() && auth_data_->state == AUTH_STATE_HAVE_AUTH); |
261 | 261 |
262 // No matter what, we want to report our status as IO pending since we will | 262 // No matter what, we want to report our status as IO pending since we will |
263 // be notifying our consumer asynchronously via OnStartCompleted. | 263 // be notifying our consumer asynchronously via OnStartCompleted. |
264 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 264 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
265 | 265 |
266 int rv; | 266 int rv; |
267 if (proxy_info_.is_direct()) { | 267 if (proxy_info_.is_direct()) { |
268 rv = ftp_transaction_->RestartWithAuth( | 268 rv = ftp_transaction_->RestartWithAuth( |
269 auth_data_->credentials, | 269 auth_data_->credentials, |
270 base::Bind(&URLRequestFtpJob::OnStartCompleted, | 270 base::Bind(&URLRequestFtpJob::OnStartCompleted, |
(...skipping 14 matching lines...) Expand all Loading... |
285 if (proxy_info_.is_direct()) { | 285 if (proxy_info_.is_direct()) { |
286 return ftp_transaction_ ? | 286 return ftp_transaction_ ? |
287 ftp_transaction_->GetLoadState() : LOAD_STATE_IDLE; | 287 ftp_transaction_->GetLoadState() : LOAD_STATE_IDLE; |
288 } else { | 288 } else { |
289 return http_transaction_ ? | 289 return http_transaction_ ? |
290 http_transaction_->GetLoadState() : LOAD_STATE_IDLE; | 290 http_transaction_->GetLoadState() : LOAD_STATE_IDLE; |
291 } | 291 } |
292 } | 292 } |
293 | 293 |
294 bool URLRequestFtpJob::NeedsAuth() { | 294 bool URLRequestFtpJob::NeedsAuth() { |
295 return auth_data_ && auth_data_->state == AUTH_STATE_NEED_AUTH; | 295 return auth_data_.get() && auth_data_->state == AUTH_STATE_NEED_AUTH; |
296 } | 296 } |
297 | 297 |
298 void URLRequestFtpJob::GetAuthChallengeInfo( | 298 void URLRequestFtpJob::GetAuthChallengeInfo( |
299 scoped_refptr<AuthChallengeInfo>* result) { | 299 scoped_refptr<AuthChallengeInfo>* result) { |
300 DCHECK(NeedsAuth()); | 300 DCHECK(NeedsAuth()); |
301 | 301 |
302 if (http_response_info_) { | 302 if (http_response_info_) { |
303 *result = http_response_info_->auth_challenge; | 303 *result = http_response_info_->auth_challenge; |
304 return; | 304 return; |
305 } | 305 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 372 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
373 } else { | 373 } else { |
374 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 374 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
375 } | 375 } |
376 return false; | 376 return false; |
377 } | 377 } |
378 | 378 |
379 void URLRequestFtpJob::HandleAuthNeededResponse() { | 379 void URLRequestFtpJob::HandleAuthNeededResponse() { |
380 GURL origin = request_->url().GetOrigin(); | 380 GURL origin = request_->url().GetOrigin(); |
381 | 381 |
382 if (auth_data_) { | 382 if (auth_data_.get()) { |
383 if (auth_data_->state == AUTH_STATE_CANCELED) { | 383 if (auth_data_->state == AUTH_STATE_CANCELED) { |
384 NotifyHeadersComplete(); | 384 NotifyHeadersComplete(); |
385 return; | 385 return; |
386 } | 386 } |
387 | 387 |
388 if (ftp_transaction_ && auth_data_->state == AUTH_STATE_HAVE_AUTH) | 388 if (ftp_transaction_ && auth_data_->state == AUTH_STATE_HAVE_AUTH) |
389 ftp_auth_cache_->Remove(origin, auth_data_->credentials); | 389 ftp_auth_cache_->Remove(origin, auth_data_->credentials); |
390 } else { | 390 } else { |
391 auth_data_ = new AuthData; | 391 auth_data_ = new AuthData; |
392 } | 392 } |
393 auth_data_->state = AUTH_STATE_NEED_AUTH; | 393 auth_data_->state = AUTH_STATE_NEED_AUTH; |
394 | 394 |
395 FtpAuthCache::Entry* cached_auth = NULL; | 395 FtpAuthCache::Entry* cached_auth = NULL; |
396 if (ftp_transaction_ && ftp_transaction_->GetResponseInfo()->needs_auth) | 396 if (ftp_transaction_ && ftp_transaction_->GetResponseInfo()->needs_auth) |
397 cached_auth = ftp_auth_cache_->Lookup(origin); | 397 cached_auth = ftp_auth_cache_->Lookup(origin); |
398 if (cached_auth) { | 398 if (cached_auth) { |
399 // Retry using cached auth data. | 399 // Retry using cached auth data. |
400 SetAuth(cached_auth->credentials); | 400 SetAuth(cached_auth->credentials); |
401 } else { | 401 } else { |
402 // Prompt for a username/password. | 402 // Prompt for a username/password. |
403 NotifyHeadersComplete(); | 403 NotifyHeadersComplete(); |
404 } | 404 } |
405 } | 405 } |
406 | 406 |
407 } // namespace net | 407 } // namespace net |
OLD | NEW |