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