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/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "net/base/auth.h" | 10 #include "net/base/auth.h" |
11 #include "net/base/host_port_pair.h" | 11 #include "net/base/host_port_pair.h" |
12 #include "net/base/load_flags.h" | 12 #include "net/base/load_flags.h" |
13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
14 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
15 #include "net/ftp/ftp_auth_cache.h" | 15 #include "net/ftp/ftp_auth_cache.h" |
16 #include "net/ftp/ftp_response_info.h" | 16 #include "net/ftp/ftp_response_info.h" |
17 #include "net/ftp/ftp_transaction_factory.h" | 17 #include "net/ftp/ftp_transaction_factory.h" |
18 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
19 #include "net/http/http_transaction_factory.h" | 19 #include "net/http/http_transaction_factory.h" |
20 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
21 #include "net/url_request/url_request_context.h" | 21 #include "net/url_request/url_request_context.h" |
22 #include "net/url_request/url_request_error_job.h" | 22 #include "net/url_request/url_request_error_job.h" |
| 23 #include "url/origin.h" |
23 | 24 |
24 namespace net { | 25 namespace net { |
25 | 26 |
26 URLRequestFtpJob::URLRequestFtpJob( | 27 URLRequestFtpJob::URLRequestFtpJob( |
27 URLRequest* request, | 28 URLRequest* request, |
28 NetworkDelegate* network_delegate, | 29 NetworkDelegate* network_delegate, |
29 FtpTransactionFactory* ftp_transaction_factory, | 30 FtpTransactionFactory* ftp_transaction_factory, |
30 FtpAuthCache* ftp_auth_cache) | 31 FtpAuthCache* ftp_auth_cache) |
31 : URLRequestJob(request, network_delegate), | 32 : URLRequestJob(request, network_delegate), |
32 priority_(DEFAULT_PRIORITY), | 33 priority_(DEFAULT_PRIORITY), |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 } | 317 } |
317 | 318 |
318 void URLRequestFtpJob::SetAuth(const AuthCredentials& credentials) { | 319 void URLRequestFtpJob::SetAuth(const AuthCredentials& credentials) { |
319 DCHECK(ftp_transaction_ || http_transaction_); | 320 DCHECK(ftp_transaction_ || http_transaction_); |
320 DCHECK(NeedsAuth()); | 321 DCHECK(NeedsAuth()); |
321 | 322 |
322 auth_data_->state = AUTH_STATE_HAVE_AUTH; | 323 auth_data_->state = AUTH_STATE_HAVE_AUTH; |
323 auth_data_->credentials = credentials; | 324 auth_data_->credentials = credentials; |
324 | 325 |
325 if (ftp_transaction_) { | 326 if (ftp_transaction_) { |
326 ftp_auth_cache_->Add(request_->url().GetOrigin(), | 327 ftp_auth_cache_->Add(url::Origin(request_->url()), auth_data_->credentials); |
327 auth_data_->credentials); | |
328 } | 328 } |
329 | 329 |
330 RestartTransactionWithAuth(); | 330 RestartTransactionWithAuth(); |
331 } | 331 } |
332 | 332 |
333 void URLRequestFtpJob::CancelAuth() { | 333 void URLRequestFtpJob::CancelAuth() { |
334 DCHECK(ftp_transaction_ || http_transaction_); | 334 DCHECK(ftp_transaction_ || http_transaction_); |
335 DCHECK(NeedsAuth()); | 335 DCHECK(NeedsAuth()); |
336 | 336 |
337 auth_data_->state = AUTH_STATE_CANCELED; | 337 auth_data_->state = AUTH_STATE_CANCELED; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 if (rv == ERR_IO_PENDING) { | 372 if (rv == ERR_IO_PENDING) { |
373 read_in_progress_ = true; | 373 read_in_progress_ = true; |
374 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 374 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
375 } else { | 375 } else { |
376 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 376 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
377 } | 377 } |
378 return false; | 378 return false; |
379 } | 379 } |
380 | 380 |
381 void URLRequestFtpJob::HandleAuthNeededResponse() { | 381 void URLRequestFtpJob::HandleAuthNeededResponse() { |
382 GURL origin = request_->url().GetOrigin(); | 382 url::Origin origin = url::Origin(request_->url()); |
383 | 383 |
384 if (auth_data_.get()) { | 384 if (auth_data_.get()) { |
385 if (auth_data_->state == AUTH_STATE_CANCELED) { | 385 if (auth_data_->state == AUTH_STATE_CANCELED) { |
386 NotifyHeadersComplete(); | 386 NotifyHeadersComplete(); |
387 return; | 387 return; |
388 } | 388 } |
389 | 389 |
390 if (ftp_transaction_ && auth_data_->state == AUTH_STATE_HAVE_AUTH) | 390 if (ftp_transaction_ && auth_data_->state == AUTH_STATE_HAVE_AUTH) |
391 ftp_auth_cache_->Remove(origin, auth_data_->credentials); | 391 ftp_auth_cache_->Remove(origin, auth_data_->credentials); |
392 } else { | 392 } else { |
393 auth_data_ = new AuthData; | 393 auth_data_ = new AuthData; |
394 } | 394 } |
395 auth_data_->state = AUTH_STATE_NEED_AUTH; | 395 auth_data_->state = AUTH_STATE_NEED_AUTH; |
396 | 396 |
397 FtpAuthCache::Entry* cached_auth = NULL; | 397 FtpAuthCache::Entry* cached_auth = NULL; |
398 if (ftp_transaction_ && ftp_transaction_->GetResponseInfo()->needs_auth) | 398 if (ftp_transaction_ && ftp_transaction_->GetResponseInfo()->needs_auth) |
399 cached_auth = ftp_auth_cache_->Lookup(origin); | 399 cached_auth = ftp_auth_cache_->Lookup(origin); |
400 if (cached_auth) { | 400 if (cached_auth) { |
401 // Retry using cached auth data. | 401 // Retry using cached auth data. |
402 SetAuth(cached_auth->credentials); | 402 SetAuth(cached_auth->credentials); |
403 } else { | 403 } else { |
404 // Prompt for a username/password. | 404 // Prompt for a username/password. |
405 NotifyHeadersComplete(); | 405 NotifyHeadersComplete(); |
406 } | 406 } |
407 } | 407 } |
408 | 408 |
409 } // namespace net | 409 } // namespace net |
OLD | NEW |