| 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 // For loading files, we make use of overlapped i/o to ensure that reading from | 5 // For loading files, we make use of overlapped i/o to ensure that reading from |
| 6 // the filesystem (e.g., a network filesystem) does not block the calling | 6 // the filesystem (e.g., a network filesystem) does not block the calling |
| 7 // thread. An alternative approach would be to use a background thread or pool | 7 // thread. An alternative approach would be to use a background thread or pool |
| 8 // of threads, but it seems better to leverage the operating system's ability | 8 // of threads, but it seems better to leverage the operating system's ability |
| 9 // to do background file reads for us. | 9 // to do background file reads for us. |
| 10 // | 10 // |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 DCHECK_GE(remaining_bytes_, 0); | 333 DCHECK_GE(remaining_bytes_, 0); |
| 334 | 334 |
| 335 // URL requests should not block on the disk! | 335 // URL requests should not block on the disk! |
| 336 // http://code.google.com/p/chromium/issues/detail?id=59849 | 336 // http://code.google.com/p/chromium/issues/detail?id=59849 |
| 337 { | 337 { |
| 338 base::ThreadRestrictions::ScopedAllowIO allow_io; | 338 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 339 // Do the seek at the beginning of the request. | 339 // Do the seek at the beginning of the request. |
| 340 if (remaining_bytes_ > 0 && | 340 if (remaining_bytes_ > 0 && |
| 341 byte_range_.first_byte_position() != 0 && | 341 byte_range_.first_byte_position() != 0 && |
| 342 byte_range_.first_byte_position() != | 342 byte_range_.first_byte_position() != |
| 343 stream_.Seek(FROM_BEGIN, byte_range_.first_byte_position())) { | 343 stream_.SeekSync(FROM_BEGIN, byte_range_.first_byte_position())) { |
| 344 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 344 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
| 345 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 345 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
| 346 return; | 346 return; |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 | 349 |
| 350 set_expected_content_size(remaining_bytes_); | 350 set_expected_content_size(remaining_bytes_); |
| 351 NotifyHeadersComplete(); | 351 NotifyHeadersComplete(); |
| 352 } | 352 } |
| 353 | 353 |
| 354 void URLRequestFileJob::DidRead(int result) { | 354 void URLRequestFileJob::DidRead(int result) { |
| 355 if (result > 0) { | 355 if (result > 0) { |
| 356 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status | 356 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status |
| 357 } else if (result == 0) { | 357 } else if (result == 0) { |
| 358 NotifyDone(URLRequestStatus()); | 358 NotifyDone(URLRequestStatus()); |
| 359 } else { | 359 } else { |
| 360 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 360 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 361 } | 361 } |
| 362 | 362 |
| 363 remaining_bytes_ -= result; | 363 remaining_bytes_ -= result; |
| 364 DCHECK_GE(remaining_bytes_, 0); | 364 DCHECK_GE(remaining_bytes_, 0); |
| 365 | 365 |
| 366 NotifyReadComplete(result); | 366 NotifyReadComplete(result); |
| 367 } | 367 } |
| 368 | 368 |
| 369 } // namespace net | 369 } // namespace net |
| OLD | NEW |