OLD | NEW |
1 // Copyright (c) 20010 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 "webkit/blob/blob_url_request_job.h" | 5 #include "webkit/blob/blob_url_request_job.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/file_util_proxy.h" | 10 #include "base/file_util_proxy.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 } | 330 } |
331 } | 331 } |
332 | 332 |
333 // Start the asynchronous reading. | 333 // Start the asynchronous reading. |
334 int rv = stream_.Read(read_buf_->data() + read_buf_offset_, | 334 int rv = stream_.Read(read_buf_->data() + read_buf_offset_, |
335 bytes_to_read, | 335 bytes_to_read, |
336 &io_callback_); | 336 &io_callback_); |
337 | 337 |
338 // If I/O pending error is returned, we just need to wait. | 338 // If I/O pending error is returned, we just need to wait. |
339 if (rv == net::ERR_IO_PENDING) { | 339 if (rv == net::ERR_IO_PENDING) { |
340 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 340 SetStatus(net::URLRequestStatus(net::URLRequestStatus::IO_PENDING, 0)); |
341 return false; | 341 return false; |
342 } | 342 } |
343 | 343 |
344 // For all other errors, bail out. | 344 // For all other errors, bail out. |
345 if (rv < 0) { | 345 if (rv < 0) { |
346 NotifyFailure(net::ERR_FAILED); | 346 NotifyFailure(net::ERR_FAILED); |
347 return false; | 347 return false; |
348 } | 348 } |
349 | 349 |
350 // Otherwise, data is immediately available. | 350 // Otherwise, data is immediately available. |
351 AdvanceBytesRead(rv); | 351 AdvanceBytesRead(rv); |
352 return true; | 352 return true; |
353 } | 353 } |
354 | 354 |
355 void BlobURLRequestJob::DidRead(int result) { | 355 void BlobURLRequestJob::DidRead(int result) { |
356 if (result < 0) { | 356 if (result < 0) { |
357 NotifyFailure(net::ERR_FAILED); | 357 NotifyFailure(net::ERR_FAILED); |
358 return; | 358 return; |
359 } | 359 } |
360 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status | 360 SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status |
361 | 361 |
362 AdvanceBytesRead(result); | 362 AdvanceBytesRead(result); |
363 | 363 |
364 // If the read buffer is completely filled, we're done. | 364 // If the read buffer is completely filled, we're done. |
365 if (!read_buf_remaining_bytes_) { | 365 if (!read_buf_remaining_bytes_) { |
366 int bytes_read = ReadCompleted(); | 366 int bytes_read = ReadCompleted(); |
367 NotifyReadComplete(bytes_read); | 367 NotifyReadComplete(bytes_read); |
368 return; | 368 return; |
369 } | 369 } |
370 | 370 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 } | 459 } |
460 HeadersCompleted(status_code, status_text); | 460 HeadersCompleted(status_code, status_text); |
461 } | 461 } |
462 | 462 |
463 void BlobURLRequestJob::NotifyFailure(int error_code) { | 463 void BlobURLRequestJob::NotifyFailure(int error_code) { |
464 error_ = true; | 464 error_ = true; |
465 | 465 |
466 // If we already return the headers on success, we can't change the headers | 466 // If we already return the headers on success, we can't change the headers |
467 // now. Instead, we just error out. | 467 // now. Instead, we just error out. |
468 if (headers_set_) { | 468 if (headers_set_) { |
469 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, error_code)); | 469 NotifyDone(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
| 470 error_code)); |
470 return; | 471 return; |
471 } | 472 } |
472 | 473 |
473 int status_code = 0; | 474 int status_code = 0; |
474 std::string status_txt; | 475 std::string status_txt; |
475 switch (error_code) { | 476 switch (error_code) { |
476 case net::ERR_ACCESS_DENIED: | 477 case net::ERR_ACCESS_DENIED: |
477 status_code = kHTTPNotAllowed; | 478 status_code = kHTTPNotAllowed; |
478 status_txt = kHTTPNotAllowedText; | 479 status_txt = kHTTPNotAllowedText; |
479 break; | 480 break; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 // We don't support multiple range requests in one single URL request, | 536 // We don't support multiple range requests in one single URL request, |
536 // because we need to do multipart encoding here. | 537 // because we need to do multipart encoding here. |
537 // TODO(jianli): Support multipart byte range requests. | 538 // TODO(jianli): Support multipart byte range requests. |
538 NotifyFailure(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); | 539 NotifyFailure(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); |
539 } | 540 } |
540 } | 541 } |
541 } | 542 } |
542 } | 543 } |
543 | 544 |
544 } // namespace webkit_blob | 545 } // namespace webkit_blob |
OLD | NEW |