| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // the content size information manually. | 100 // the content size information manually. |
| 101 set_expected_content_size( | 101 set_expected_content_size( |
| 102 transaction_->GetResponseInfo()->expected_content_size); | 102 transaction_->GetResponseInfo()->expected_content_size); |
| 103 | 103 |
| 104 if (result == OK) { | 104 if (result == OK) { |
| 105 NotifyHeadersComplete(); | 105 NotifyHeadersComplete(); |
| 106 } else if (transaction_->GetResponseInfo()->needs_auth) { | 106 } else if (transaction_->GetResponseInfo()->needs_auth) { |
| 107 GURL origin = request_->url().GetOrigin(); | 107 GURL origin = request_->url().GetOrigin(); |
| 108 if (server_auth_ && server_auth_->state == AUTH_STATE_HAVE_AUTH) { | 108 if (server_auth_ && server_auth_->state == AUTH_STATE_HAVE_AUTH) { |
| 109 request_->context()->ftp_auth_cache()->Remove( | 109 request_->context()->ftp_auth_cache()->Remove( |
| 110 origin, | 110 origin, server_auth_->credentials); |
| 111 server_auth_->credentials.username, | |
| 112 server_auth_->credentials.password); | |
| 113 } else if (!server_auth_) { | 111 } else if (!server_auth_) { |
| 114 server_auth_ = new AuthData(); | 112 server_auth_ = new AuthData(); |
| 115 } | 113 } |
| 116 server_auth_->state = AUTH_STATE_NEED_AUTH; | 114 server_auth_->state = AUTH_STATE_NEED_AUTH; |
| 117 | 115 |
| 118 FtpAuthCache::Entry* cached_auth = | 116 FtpAuthCache::Entry* cached_auth = |
| 119 request_->context()->ftp_auth_cache()->Lookup(origin); | 117 request_->context()->ftp_auth_cache()->Lookup(origin); |
| 120 | 118 |
| 121 if (cached_auth) { | 119 if (cached_auth) { |
| 122 // Retry using cached auth data. | 120 // Retry using cached auth data. |
| 123 SetAuth(cached_auth->username, | 121 SetAuth(cached_auth->credentials); |
| 124 cached_auth->password); | |
| 125 } else { | 122 } else { |
| 126 // Prompt for a username/password. | 123 // Prompt for a username/password. |
| 127 NotifyHeadersComplete(); | 124 NotifyHeadersComplete(); |
| 128 } | 125 } |
| 129 } else { | 126 } else { |
| 130 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 127 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 131 } | 128 } |
| 132 } | 129 } |
| 133 | 130 |
| 134 void URLRequestFtpJob::OnReadCompleted(int result) { | 131 void URLRequestFtpJob::OnReadCompleted(int result) { |
| 135 read_in_progress_ = false; | 132 read_in_progress_ = false; |
| 136 if (result == 0) { | 133 if (result == 0) { |
| 137 NotifyDone(URLRequestStatus()); | 134 NotifyDone(URLRequestStatus()); |
| 138 } else if (result < 0) { | 135 } else if (result < 0) { |
| 139 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 136 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 140 } else { | 137 } else { |
| 141 // Clear the IO_PENDING status | 138 // Clear the IO_PENDING status |
| 142 SetStatus(URLRequestStatus()); | 139 SetStatus(URLRequestStatus()); |
| 143 } | 140 } |
| 144 NotifyReadComplete(result); | 141 NotifyReadComplete(result); |
| 145 } | 142 } |
| 146 | 143 |
| 147 void URLRequestFtpJob::RestartTransactionWithAuth() { | 144 void URLRequestFtpJob::RestartTransactionWithAuth() { |
| 148 DCHECK(server_auth_ && server_auth_->state == AUTH_STATE_HAVE_AUTH); | 145 DCHECK(server_auth_ && server_auth_->state == AUTH_STATE_HAVE_AUTH); |
| 149 | 146 |
| 150 // No matter what, we want to report our status as IO pending since we will | 147 // No matter what, we want to report our status as IO pending since we will |
| 151 // be notifying our consumer asynchronously via OnStartCompleted. | 148 // be notifying our consumer asynchronously via OnStartCompleted. |
| 152 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 149 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 153 | 150 |
| 154 int rv = transaction_->RestartWithAuth(server_auth_->credentials.username, | 151 int rv = transaction_->RestartWithAuth(server_auth_->credentials, |
| 155 server_auth_->credentials.password, | |
| 156 &start_callback_); | 152 &start_callback_); |
| 157 if (rv == ERR_IO_PENDING) | 153 if (rv == ERR_IO_PENDING) |
| 158 return; | 154 return; |
| 159 | 155 |
| 160 MessageLoop::current()->PostTask( | 156 MessageLoop::current()->PostTask( |
| 161 FROM_HERE, | 157 FROM_HERE, |
| 162 method_factory_.NewRunnableMethod( | 158 method_factory_.NewRunnableMethod( |
| 163 &URLRequestFtpJob::OnStartCompleted, rv)); | 159 &URLRequestFtpJob::OnStartCompleted, rv)); |
| 164 } | 160 } |
| 165 | 161 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 196 (server_auth_->state == AUTH_STATE_NEED_AUTH)); | 192 (server_auth_->state == AUTH_STATE_NEED_AUTH)); |
| 197 scoped_refptr<AuthChallengeInfo> auth_info(new AuthChallengeInfo); | 193 scoped_refptr<AuthChallengeInfo> auth_info(new AuthChallengeInfo); |
| 198 auth_info->is_proxy = false; | 194 auth_info->is_proxy = false; |
| 199 auth_info->challenger = HostPortPair::FromURL(request_->url()); | 195 auth_info->challenger = HostPortPair::FromURL(request_->url()); |
| 200 // scheme and realm are kept empty. | 196 // scheme and realm are kept empty. |
| 201 DCHECK(auth_info->scheme.empty()); | 197 DCHECK(auth_info->scheme.empty()); |
| 202 DCHECK(auth_info->realm.empty()); | 198 DCHECK(auth_info->realm.empty()); |
| 203 result->swap(auth_info); | 199 result->swap(auth_info); |
| 204 } | 200 } |
| 205 | 201 |
| 206 void URLRequestFtpJob::SetAuth(const string16& username, | 202 void URLRequestFtpJob::SetAuth(const AuthCredentials& credentials) { |
| 207 const string16& password) { | |
| 208 DCHECK(NeedsAuth()); | 203 DCHECK(NeedsAuth()); |
| 209 server_auth_->state = AUTH_STATE_HAVE_AUTH; | 204 server_auth_->state = AUTH_STATE_HAVE_AUTH; |
| 210 server_auth_->credentials.username = username; | 205 server_auth_->credentials = credentials; |
| 211 server_auth_->credentials.password = password; | |
| 212 | 206 |
| 213 request_->context()->ftp_auth_cache()->Add(request_->url().GetOrigin(), | 207 request_->context()->ftp_auth_cache()->Add(request_->url().GetOrigin(), |
| 214 username, password); | 208 server_auth_->credentials); |
| 215 | 209 |
| 216 RestartTransactionWithAuth(); | 210 RestartTransactionWithAuth(); |
| 217 } | 211 } |
| 218 | 212 |
| 219 void URLRequestFtpJob::CancelAuth() { | 213 void URLRequestFtpJob::CancelAuth() { |
| 220 DCHECK(NeedsAuth()); | 214 DCHECK(NeedsAuth()); |
| 221 server_auth_->state = AUTH_STATE_CANCELED; | 215 server_auth_->state = AUTH_STATE_CANCELED; |
| 222 | 216 |
| 223 // Once the auth is cancelled, we proceed with the request as though | 217 // Once the auth is cancelled, we proceed with the request as though |
| 224 // there were no auth. Schedule this for later so that we don't cause | 218 // there were no auth. Schedule this for later so that we don't cause |
| (...skipping 24 matching lines...) Expand all Loading... |
| 249 if (rv == ERR_IO_PENDING) { | 243 if (rv == ERR_IO_PENDING) { |
| 250 read_in_progress_ = true; | 244 read_in_progress_ = true; |
| 251 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 245 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 252 } else { | 246 } else { |
| 253 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 247 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 254 } | 248 } |
| 255 return false; | 249 return false; |
| 256 } | 250 } |
| 257 | 251 |
| 258 } // namespace net | 252 } // namespace net |
| OLD | NEW |