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

Unified Diff: net/url_request/url_request_new_ftp_job.cc

Issue 201083: Cache login identity for NewFTP transactions. (Closed)
Patch Set: better Created 11 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: net/url_request/url_request_new_ftp_job.cc
diff --git a/net/url_request/url_request_new_ftp_job.cc b/net/url_request/url_request_new_ftp_job.cc
index 7755503228b224310823dc559e06b16c9317d74b..92abe77aca6374bd8772e2f05ed6683e7e5fa11c 100644
--- a/net/url_request/url_request_new_ftp_job.cc
+++ b/net/url_request/url_request_new_ftp_job.cc
@@ -136,6 +136,9 @@ void URLRequestNewFtpJob::SetAuth(const std::wstring& username,
server_auth_->username = username;
server_auth_->password = password;
+ request_->context()->ftp_auth_cache()->Add(request_->url().GetOrigin(),
+ username, password);
+
RestartTransactionWithAuth();
}
@@ -352,18 +355,43 @@ void URLRequestNewFtpJob::OnStartCompleted(int result) {
// If the request was destroyed, then there is no more work to do.
if (!request_ || !request_->delegate())
return;
+
// If the transaction was destroyed, then the job was cancelled, and
// we can just ignore this notification.
if (!transaction_.get())
return;
+
// Clear the IO_PENDING status
SetStatus(URLRequestStatus());
+
+ GURL origin = request_->url().GetOrigin();
if (result == net::OK) {
+ if (!server_auth_ && request_->url().has_username()) {
+ std::wstring username, password;
+ net::GetIdentityFromURL(request_->url(), &username, &password);
+ 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
+ }
NotifyHeadersComplete();
} else if (transaction_->GetResponseInfo()->needs_auth) {
- server_auth_ = new net::AuthData();
+ if (server_auth_ && server_auth_->state == net::AUTH_STATE_HAVE_AUTH) {
+ request_->context()->ftp_auth_cache()->Remove(origin,
+ server_auth_->username,
+ server_auth_->password);
+ } else if (!server_auth_) {
+ server_auth_ = new net::AuthData();
+ }
server_auth_->state = net::AUTH_STATE_NEED_AUTH;
- NotifyHeadersComplete();
+
+ net::FtpAuthCache::Entry* cached_auth =
+ request_->context()->ftp_auth_cache()->Lookup(origin);
+
+ if (cached_auth) {
+ // Retry using cached auth data.
+ 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
+ } else {
+ // Prompt for a username/password.
+ NotifyHeadersComplete();
+ }
} else {
NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result));
}
@@ -412,8 +440,10 @@ void URLRequestNewFtpJob::StartTransaction() {
DCHECK(request_->context());
DCHECK(request_->context()->ftp_transaction_factory());
+ DCHECK(!server_auth_);
+
transaction_.reset(
- request_->context()->ftp_transaction_factory()->CreateTransaction());
+ request_->context()->ftp_transaction_factory()->CreateTransaction());
// No matter what, we want to report our status as IO pending since we will
// be notifying our consumer asynchronously via OnStartCompleted.

Powered by Google App Engine
This is Rietveld 408576698