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/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 OnStartCompletedAsync(ERR_NO_SUPPORTED_PROXIES); | 153 OnStartCompletedAsync(ERR_NO_SUPPORTED_PROXIES); |
154 } | 154 } |
155 | 155 |
156 void URLRequestFtpJob::StartFtpTransaction() { | 156 void URLRequestFtpJob::StartFtpTransaction() { |
157 // Create a transaction. | 157 // Create a transaction. |
158 DCHECK(!ftp_transaction_); | 158 DCHECK(!ftp_transaction_); |
159 | 159 |
160 ftp_request_info_.url = request_->url(); | 160 ftp_request_info_.url = request_->url(); |
161 ftp_transaction_ = ftp_transaction_factory_->CreateTransaction(); | 161 ftp_transaction_ = ftp_transaction_factory_->CreateTransaction(); |
162 | 162 |
163 // No matter what, we want to report our status as IO pending since we will | |
164 // be notifying our consumer asynchronously via OnStartCompleted. | |
165 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | |
166 int rv; | 163 int rv; |
167 if (ftp_transaction_) { | 164 if (ftp_transaction_) { |
168 rv = ftp_transaction_->Start( | 165 rv = ftp_transaction_->Start( |
169 &ftp_request_info_, | 166 &ftp_request_info_, |
170 base::Bind(&URLRequestFtpJob::OnStartCompleted, | 167 base::Bind(&URLRequestFtpJob::OnStartCompleted, |
171 base::Unretained(this)), | 168 base::Unretained(this)), |
172 request_->net_log()); | 169 request_->net_log()); |
173 if (rv == ERR_IO_PENDING) | 170 if (rv == ERR_IO_PENDING) |
174 return; | 171 return; |
175 } else { | 172 } else { |
(...skipping 28 matching lines...) Expand all Loading... |
204 request_->net_log()); | 201 request_->net_log()); |
205 if (rv == ERR_IO_PENDING) | 202 if (rv == ERR_IO_PENDING) |
206 return; | 203 return; |
207 } | 204 } |
208 // The transaction started synchronously, but we need to notify the | 205 // The transaction started synchronously, but we need to notify the |
209 // URLRequest delegate via the message loop. | 206 // URLRequest delegate via the message loop. |
210 OnStartCompletedAsync(rv); | 207 OnStartCompletedAsync(rv); |
211 } | 208 } |
212 | 209 |
213 void URLRequestFtpJob::OnStartCompleted(int result) { | 210 void URLRequestFtpJob::OnStartCompleted(int result) { |
214 // Clear the IO_PENDING status | |
215 SetStatus(URLRequestStatus()); | |
216 | |
217 // Note that ftp_transaction_ may be NULL due to a creation failure. | 211 // Note that ftp_transaction_ may be NULL due to a creation failure. |
218 if (ftp_transaction_) { | 212 if (ftp_transaction_) { |
219 // FTP obviously doesn't have HTTP Content-Length header. We have to pass | 213 // FTP obviously doesn't have HTTP Content-Length header. We have to pass |
220 // the content size information manually. | 214 // the content size information manually. |
221 set_expected_content_size( | 215 set_expected_content_size( |
222 ftp_transaction_->GetResponseInfo()->expected_content_size); | 216 ftp_transaction_->GetResponseInfo()->expected_content_size); |
223 } | 217 } |
224 | 218 |
225 if (result == OK) { | 219 if (result == OK) { |
226 if (http_transaction_) { | 220 if (http_transaction_) { |
(...skipping 23 matching lines...) Expand all Loading... |
250 } | 244 } |
251 | 245 |
252 void URLRequestFtpJob::OnReadCompleted(int result) { | 246 void URLRequestFtpJob::OnReadCompleted(int result) { |
253 read_in_progress_ = false; | 247 read_in_progress_ = false; |
254 ReadRawDataComplete(result); | 248 ReadRawDataComplete(result); |
255 } | 249 } |
256 | 250 |
257 void URLRequestFtpJob::RestartTransactionWithAuth() { | 251 void URLRequestFtpJob::RestartTransactionWithAuth() { |
258 DCHECK(auth_data_.get() && auth_data_->state == AUTH_STATE_HAVE_AUTH); | 252 DCHECK(auth_data_.get() && auth_data_->state == AUTH_STATE_HAVE_AUTH); |
259 | 253 |
260 // No matter what, we want to report our status as IO pending since we will | |
261 // be notifying our consumer asynchronously via OnStartCompleted. | |
262 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | |
263 | |
264 int rv; | 254 int rv; |
265 if (proxy_info_.is_direct()) { | 255 if (proxy_info_.is_direct()) { |
266 rv = ftp_transaction_->RestartWithAuth( | 256 rv = ftp_transaction_->RestartWithAuth( |
267 auth_data_->credentials, | 257 auth_data_->credentials, |
268 base::Bind(&URLRequestFtpJob::OnStartCompleted, | 258 base::Bind(&URLRequestFtpJob::OnStartCompleted, |
269 base::Unretained(this))); | 259 base::Unretained(this))); |
270 } else { | 260 } else { |
271 rv = http_transaction_->RestartWithAuth( | 261 rv = http_transaction_->RestartWithAuth( |
272 auth_data_->credentials, | 262 auth_data_->credentials, |
273 base::Bind(&URLRequestFtpJob::OnStartCompleted, | 263 base::Bind(&URLRequestFtpJob::OnStartCompleted, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 if (cached_auth) { | 377 if (cached_auth) { |
388 // Retry using cached auth data. | 378 // Retry using cached auth data. |
389 SetAuth(cached_auth->credentials); | 379 SetAuth(cached_auth->credentials); |
390 } else { | 380 } else { |
391 // Prompt for a username/password. | 381 // Prompt for a username/password. |
392 NotifyHeadersComplete(); | 382 NotifyHeadersComplete(); |
393 } | 383 } |
394 } | 384 } |
395 | 385 |
396 } // namespace net | 386 } // namespace net |
OLD | NEW |