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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 HandleAuthNeededResponse(); | 232 HandleAuthNeededResponse(); |
233 return; | 233 return; |
234 } | 234 } |
235 } | 235 } |
236 NotifyHeadersComplete(); | 236 NotifyHeadersComplete(); |
237 } else if (ftp_transaction_ && | 237 } else if (ftp_transaction_ && |
238 ftp_transaction_->GetResponseInfo()->needs_auth) { | 238 ftp_transaction_->GetResponseInfo()->needs_auth) { |
239 HandleAuthNeededResponse(); | 239 HandleAuthNeededResponse(); |
240 return; | 240 return; |
241 } else { | 241 } else { |
242 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); | 242 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
243 } | 243 } |
244 } | 244 } |
245 | 245 |
246 void URLRequestFtpJob::OnStartCompletedAsync(int result) { | 246 void URLRequestFtpJob::OnStartCompletedAsync(int result) { |
247 base::ThreadTaskRunnerHandle::Get()->PostTask( | 247 base::ThreadTaskRunnerHandle::Get()->PostTask( |
248 FROM_HERE, base::Bind(&URLRequestFtpJob::OnStartCompleted, | 248 FROM_HERE, base::Bind(&URLRequestFtpJob::OnStartCompleted, |
249 weak_factory_.GetWeakPtr(), result)); | 249 weak_factory_.GetWeakPtr(), result)); |
250 } | 250 } |
251 | 251 |
252 void URLRequestFtpJob::OnReadCompleted(int result) { | 252 void URLRequestFtpJob::OnReadCompleted(int result) { |
253 read_in_progress_ = false; | 253 read_in_progress_ = false; |
254 ReadRawDataComplete(result); | 254 if (result == 0) { |
| 255 NotifyDone(URLRequestStatus()); |
| 256 } else if (result < 0) { |
| 257 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 258 } else { |
| 259 // Clear the IO_PENDING status |
| 260 SetStatus(URLRequestStatus()); |
| 261 } |
| 262 NotifyReadComplete(result); |
255 } | 263 } |
256 | 264 |
257 void URLRequestFtpJob::RestartTransactionWithAuth() { | 265 void URLRequestFtpJob::RestartTransactionWithAuth() { |
258 DCHECK(auth_data_.get() && auth_data_->state == AUTH_STATE_HAVE_AUTH); | 266 DCHECK(auth_data_.get() && auth_data_->state == AUTH_STATE_HAVE_AUTH); |
259 | 267 |
260 // No matter what, we want to report our status as IO pending since we will | 268 // No matter what, we want to report our status as IO pending since we will |
261 // be notifying our consumer asynchronously via OnStartCompleted. | 269 // be notifying our consumer asynchronously via OnStartCompleted. |
262 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 270 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
263 | 271 |
264 int rv; | 272 int rv; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // Once the auth is cancelled, we proceed with the request as though | 345 // Once the auth is cancelled, we proceed with the request as though |
338 // there were no auth. Schedule this for later so that we don't cause | 346 // there were no auth. Schedule this for later so that we don't cause |
339 // any recursing into the caller as a result of this call. | 347 // any recursing into the caller as a result of this call. |
340 OnStartCompletedAsync(OK); | 348 OnStartCompletedAsync(OK); |
341 } | 349 } |
342 | 350 |
343 UploadProgress URLRequestFtpJob::GetUploadProgress() const { | 351 UploadProgress URLRequestFtpJob::GetUploadProgress() const { |
344 return UploadProgress(); | 352 return UploadProgress(); |
345 } | 353 } |
346 | 354 |
347 int URLRequestFtpJob::ReadRawData(IOBuffer* buf, int buf_size) { | 355 bool URLRequestFtpJob::ReadRawData(IOBuffer* buf, |
| 356 int buf_size, |
| 357 int* bytes_read) { |
348 DCHECK_NE(buf_size, 0); | 358 DCHECK_NE(buf_size, 0); |
| 359 DCHECK(bytes_read); |
349 DCHECK(!read_in_progress_); | 360 DCHECK(!read_in_progress_); |
350 | 361 |
351 int rv; | 362 int rv; |
352 | |
353 if (proxy_info_.is_direct()) { | 363 if (proxy_info_.is_direct()) { |
354 rv = ftp_transaction_->Read(buf, buf_size, | 364 rv = ftp_transaction_->Read(buf, buf_size, |
355 base::Bind(&URLRequestFtpJob::OnReadCompleted, | 365 base::Bind(&URLRequestFtpJob::OnReadCompleted, |
356 base::Unretained(this))); | 366 base::Unretained(this))); |
357 } else { | 367 } else { |
358 rv = http_transaction_->Read(buf, buf_size, | 368 rv = http_transaction_->Read(buf, buf_size, |
359 base::Bind(&URLRequestFtpJob::OnReadCompleted, | 369 base::Bind(&URLRequestFtpJob::OnReadCompleted, |
360 base::Unretained(this))); | 370 base::Unretained(this))); |
361 } | 371 } |
362 | 372 |
363 if (rv == ERR_IO_PENDING) | 373 if (rv >= 0) { |
| 374 *bytes_read = rv; |
| 375 return true; |
| 376 } |
| 377 |
| 378 if (rv == ERR_IO_PENDING) { |
364 read_in_progress_ = true; | 379 read_in_progress_ = true; |
365 return rv; | 380 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 381 } else { |
| 382 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 383 } |
| 384 return false; |
366 } | 385 } |
367 | 386 |
368 void URLRequestFtpJob::HandleAuthNeededResponse() { | 387 void URLRequestFtpJob::HandleAuthNeededResponse() { |
369 GURL origin = request_->url().GetOrigin(); | 388 GURL origin = request_->url().GetOrigin(); |
370 | 389 |
371 if (auth_data_.get()) { | 390 if (auth_data_.get()) { |
372 if (auth_data_->state == AUTH_STATE_CANCELED) { | 391 if (auth_data_->state == AUTH_STATE_CANCELED) { |
373 NotifyHeadersComplete(); | 392 NotifyHeadersComplete(); |
374 return; | 393 return; |
375 } | 394 } |
(...skipping 11 matching lines...) Expand all Loading... |
387 if (cached_auth) { | 406 if (cached_auth) { |
388 // Retry using cached auth data. | 407 // Retry using cached auth data. |
389 SetAuth(cached_auth->credentials); | 408 SetAuth(cached_auth->credentials); |
390 } else { | 409 } else { |
391 // Prompt for a username/password. | 410 // Prompt for a username/password. |
392 NotifyHeadersComplete(); | 411 NotifyHeadersComplete(); |
393 } | 412 } |
394 } | 413 } |
395 | 414 |
396 } // namespace net | 415 } // namespace net |
OLD | NEW |