Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_new_ftp_job.h" | 5 #include "net/url_request/url_request_new_ftp_job.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/file_version_info.h" | 8 #include "base/file_version_info.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 result->swap(auth_info); | 129 result->swap(auth_info); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void URLRequestNewFtpJob::SetAuth(const std::wstring& username, | 132 void URLRequestNewFtpJob::SetAuth(const std::wstring& username, |
| 133 const std::wstring& password) { | 133 const std::wstring& password) { |
| 134 DCHECK(NeedsAuth()); | 134 DCHECK(NeedsAuth()); |
| 135 server_auth_->state = net::AUTH_STATE_HAVE_AUTH; | 135 server_auth_->state = net::AUTH_STATE_HAVE_AUTH; |
| 136 server_auth_->username = username; | 136 server_auth_->username = username; |
| 137 server_auth_->password = password; | 137 server_auth_->password = password; |
| 138 | 138 |
| 139 request_->context()->ftp_auth_cache()->Add(request_->url().GetOrigin(), | |
| 140 username, password); | |
| 141 | |
| 139 RestartTransactionWithAuth(); | 142 RestartTransactionWithAuth(); |
| 140 } | 143 } |
| 141 | 144 |
| 142 void URLRequestNewFtpJob::CancelAuth() { | 145 void URLRequestNewFtpJob::CancelAuth() { |
| 143 DCHECK(NeedsAuth()); | 146 DCHECK(NeedsAuth()); |
| 144 server_auth_->state = net::AUTH_STATE_CANCELED; | 147 server_auth_->state = net::AUTH_STATE_CANCELED; |
| 145 | 148 |
| 146 // Once the auth is cancelled, we proceed with the request as though | 149 // Once the auth is cancelled, we proceed with the request as though |
| 147 // there were no auth. Schedule this for later so that we don't cause | 150 // there were no auth. Schedule this for later so that we don't cause |
| 148 // any recursing into the caller as a result of this call. | 151 // any recursing into the caller as a result of this call. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 default: | 348 default: |
| 346 net::UpdateFtpServerTypeHistograms(net::SERVER_UNKNOWN); | 349 net::UpdateFtpServerTypeHistograms(net::SERVER_UNKNOWN); |
| 347 break; | 350 break; |
| 348 } | 351 } |
| 349 } | 352 } |
| 350 | 353 |
| 351 void URLRequestNewFtpJob::OnStartCompleted(int result) { | 354 void URLRequestNewFtpJob::OnStartCompleted(int result) { |
| 352 // If the request was destroyed, then there is no more work to do. | 355 // If the request was destroyed, then there is no more work to do. |
| 353 if (!request_ || !request_->delegate()) | 356 if (!request_ || !request_->delegate()) |
| 354 return; | 357 return; |
| 358 | |
| 355 // If the transaction was destroyed, then the job was cancelled, and | 359 // If the transaction was destroyed, then the job was cancelled, and |
| 356 // we can just ignore this notification. | 360 // we can just ignore this notification. |
| 357 if (!transaction_.get()) | 361 if (!transaction_.get()) |
| 358 return; | 362 return; |
| 363 | |
| 359 // Clear the IO_PENDING status | 364 // Clear the IO_PENDING status |
| 360 SetStatus(URLRequestStatus()); | 365 SetStatus(URLRequestStatus()); |
| 366 | |
| 367 GURL origin = request_->url().GetOrigin(); | |
| 361 if (result == net::OK) { | 368 if (result == net::OK) { |
| 369 if (!server_auth_ && request_->url().has_username()) { | |
| 370 std::wstring username, password; | |
| 371 net::GetIdentityFromURL(request_->url(), &username, &password); | |
| 372 request_->context()->ftp_auth_cache()->Add(origin, username, password); | |
|
eroman
2009/09/22 07:42:24
Ok. Note that for HTTP we only save it to the cach
| |
| 373 } | |
| 362 NotifyHeadersComplete(); | 374 NotifyHeadersComplete(); |
| 363 } else if (transaction_->GetResponseInfo()->needs_auth) { | 375 } else if (transaction_->GetResponseInfo()->needs_auth) { |
| 364 server_auth_ = new net::AuthData(); | 376 if (server_auth_ && server_auth_->state == net::AUTH_STATE_HAVE_AUTH) { |
| 377 request_->context()->ftp_auth_cache()->Remove(origin, | |
| 378 server_auth_->username, | |
| 379 server_auth_->password); | |
| 380 } else if (!server_auth_) { | |
| 381 server_auth_ = new net::AuthData(); | |
| 382 } | |
| 365 server_auth_->state = net::AUTH_STATE_NEED_AUTH; | 383 server_auth_->state = net::AUTH_STATE_NEED_AUTH; |
| 366 NotifyHeadersComplete(); | 384 |
| 385 net::FtpAuthCache::Entry* cached_auth = | |
| 386 request_->context()->ftp_auth_cache()->Lookup(origin); | |
| 387 | |
| 388 if (cached_auth) { | |
| 389 // Retry using cached auth data. | |
| 390 SetAuth(cached_auth->username, cached_auth->password); | |
|
eroman
2009/09/22 07:42:24
This is kind of awkward that we set it in the cach
| |
| 391 } else { | |
| 392 // Prompt for a username/password. | |
| 393 NotifyHeadersComplete(); | |
| 394 } | |
| 367 } else { | 395 } else { |
| 368 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 396 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 369 } | 397 } |
| 370 } | 398 } |
| 371 | 399 |
| 372 void URLRequestNewFtpJob::OnReadCompleted(int result) { | 400 void URLRequestNewFtpJob::OnReadCompleted(int result) { |
| 373 read_in_progress_ = false; | 401 read_in_progress_ = false; |
| 374 if (result == 0) { | 402 if (result == 0) { |
| 375 NotifyDone(URLRequestStatus()); | 403 NotifyDone(URLRequestStatus()); |
| 376 } else if (result < 0) { | 404 } else if (result < 0) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 405 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 433 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 406 this, &URLRequestNewFtpJob::OnStartCompleted, rv)); | 434 this, &URLRequestNewFtpJob::OnStartCompleted, rv)); |
| 407 } | 435 } |
| 408 | 436 |
| 409 void URLRequestNewFtpJob::StartTransaction() { | 437 void URLRequestNewFtpJob::StartTransaction() { |
| 410 // Create a transaction. | 438 // Create a transaction. |
| 411 DCHECK(!transaction_.get()); | 439 DCHECK(!transaction_.get()); |
| 412 DCHECK(request_->context()); | 440 DCHECK(request_->context()); |
| 413 DCHECK(request_->context()->ftp_transaction_factory()); | 441 DCHECK(request_->context()->ftp_transaction_factory()); |
| 414 | 442 |
| 443 DCHECK(!server_auth_); | |
| 444 | |
| 415 transaction_.reset( | 445 transaction_.reset( |
| 416 request_->context()->ftp_transaction_factory()->CreateTransaction()); | 446 request_->context()->ftp_transaction_factory()->CreateTransaction()); |
| 417 | 447 |
| 418 // No matter what, we want to report our status as IO pending since we will | 448 // No matter what, we want to report our status as IO pending since we will |
| 419 // be notifying our consumer asynchronously via OnStartCompleted. | 449 // be notifying our consumer asynchronously via OnStartCompleted. |
| 420 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 450 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 421 int rv; | 451 int rv; |
| 422 if (transaction_.get()) { | 452 if (transaction_.get()) { |
| 423 rv = transaction_->Start( | 453 rv = transaction_->Start( |
| 424 &request_info_, &start_callback_, request_->load_log()); | 454 &request_info_, &start_callback_, request_->load_log()); |
| 425 if (rv == net::ERR_IO_PENDING) | 455 if (rv == net::ERR_IO_PENDING) |
| 426 return; | 456 return; |
| 427 } else { | 457 } else { |
| 428 rv = net::ERR_FAILED; | 458 rv = net::ERR_FAILED; |
| 429 } | 459 } |
| 430 // The transaction started synchronously, but we need to notify the | 460 // The transaction started synchronously, but we need to notify the |
| 431 // URLRequest delegate via the message loop. | 461 // URLRequest delegate via the message loop. |
| 432 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 462 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 433 this, &URLRequestNewFtpJob::OnStartCompleted, rv)); | 463 this, &URLRequestNewFtpJob::OnStartCompleted, rv)); |
| 434 } | 464 } |
| 435 | 465 |
| 436 void URLRequestNewFtpJob::DestroyTransaction() { | 466 void URLRequestNewFtpJob::DestroyTransaction() { |
| 437 DCHECK(transaction_.get()); | 467 DCHECK(transaction_.get()); |
| 438 | 468 |
| 439 transaction_.reset(); | 469 transaction_.reset(); |
| 440 response_info_ = NULL; | 470 response_info_ = NULL; |
| 441 } | 471 } |
| OLD | NEW |