| 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/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "net/base/auth.h" | 13 #include "net/base/auth.h" |
| 13 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
| 14 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 16 #include "net/ftp/ftp_auth_cache.h" | 17 #include "net/ftp/ftp_auth_cache.h" |
| 17 #include "net/ftp/ftp_response_info.h" | 18 #include "net/ftp/ftp_response_info.h" |
| 18 #include "net/ftp/ftp_transaction_factory.h" | 19 #include "net/ftp/ftp_transaction_factory.h" |
| 19 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
| 20 #include "net/http/http_transaction_factory.h" | 21 #include "net/http/http_transaction_factory.h" |
| 21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 22 #include "net/url_request/url_request_context.h" | 23 #include "net/url_request/url_request_context.h" |
| 23 #include "net/url_request/url_request_error_job.h" | 24 #include "net/url_request/url_request_error_job.h" |
| 24 | 25 |
| 25 namespace net { | 26 namespace net { |
| 26 | 27 |
| 28 class URLRequestFtpJob::AuthData { |
| 29 public: |
| 30 AuthState state; // Whether we need, have, or gave up on authentication. |
| 31 AuthCredentials credentials; // The credentials to use for auth. |
| 32 |
| 33 AuthData(); |
| 34 ~AuthData(); |
| 35 }; |
| 36 |
| 37 URLRequestFtpJob::AuthData::AuthData() : state(AUTH_STATE_NEED_AUTH) {} |
| 38 |
| 39 URLRequestFtpJob::AuthData::~AuthData() {} |
| 40 |
| 27 URLRequestFtpJob::URLRequestFtpJob( | 41 URLRequestFtpJob::URLRequestFtpJob( |
| 28 URLRequest* request, | 42 URLRequest* request, |
| 29 NetworkDelegate* network_delegate, | 43 NetworkDelegate* network_delegate, |
| 30 FtpTransactionFactory* ftp_transaction_factory, | 44 FtpTransactionFactory* ftp_transaction_factory, |
| 31 FtpAuthCache* ftp_auth_cache) | 45 FtpAuthCache* ftp_auth_cache) |
| 32 : URLRequestJob(request, network_delegate), | 46 : URLRequestJob(request, network_delegate), |
| 33 priority_(DEFAULT_PRIORITY), | 47 priority_(DEFAULT_PRIORITY), |
| 34 proxy_service_(request_->context()->proxy_service()), | 48 proxy_service_(request_->context()->proxy_service()), |
| 35 pac_request_(NULL), | 49 pac_request_(NULL), |
| 36 http_response_info_(NULL), | 50 http_response_info_(NULL), |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 365 |
| 352 if (auth_data_.get()) { | 366 if (auth_data_.get()) { |
| 353 if (auth_data_->state == AUTH_STATE_CANCELED) { | 367 if (auth_data_->state == AUTH_STATE_CANCELED) { |
| 354 NotifyHeadersComplete(); | 368 NotifyHeadersComplete(); |
| 355 return; | 369 return; |
| 356 } | 370 } |
| 357 | 371 |
| 358 if (ftp_transaction_ && auth_data_->state == AUTH_STATE_HAVE_AUTH) | 372 if (ftp_transaction_ && auth_data_->state == AUTH_STATE_HAVE_AUTH) |
| 359 ftp_auth_cache_->Remove(origin, auth_data_->credentials); | 373 ftp_auth_cache_->Remove(origin, auth_data_->credentials); |
| 360 } else { | 374 } else { |
| 361 auth_data_ = new AuthData; | 375 auth_data_ = base::MakeUnique<AuthData>(); |
| 362 } | 376 } |
| 363 auth_data_->state = AUTH_STATE_NEED_AUTH; | 377 auth_data_->state = AUTH_STATE_NEED_AUTH; |
| 364 | 378 |
| 365 FtpAuthCache::Entry* cached_auth = NULL; | 379 FtpAuthCache::Entry* cached_auth = NULL; |
| 366 if (ftp_transaction_ && ftp_transaction_->GetResponseInfo()->needs_auth) | 380 if (ftp_transaction_ && ftp_transaction_->GetResponseInfo()->needs_auth) |
| 367 cached_auth = ftp_auth_cache_->Lookup(origin); | 381 cached_auth = ftp_auth_cache_->Lookup(origin); |
| 368 if (cached_auth) { | 382 if (cached_auth) { |
| 369 // Retry using cached auth data. | 383 // Retry using cached auth data. |
| 370 SetAuth(cached_auth->credentials); | 384 SetAuth(cached_auth->credentials); |
| 371 } else { | 385 } else { |
| 372 // Prompt for a username/password. | 386 // Prompt for a username/password. |
| 373 NotifyHeadersComplete(); | 387 NotifyHeadersComplete(); |
| 374 } | 388 } |
| 375 } | 389 } |
| 376 | 390 |
| 377 } // namespace net | 391 } // namespace net |
| OLD | NEW |