| 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 258 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
| 259 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 259 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
| 260 return; | 260 return; |
| 261 } | 261 } |
| 262 | 262 |
| 263 remaining_bytes_ = byte_range_.last_byte_position() - | 263 remaining_bytes_ = byte_range_.last_byte_position() - |
| 264 byte_range_.first_byte_position() + 1; | 264 byte_range_.first_byte_position() + 1; |
| 265 DCHECK_GE(remaining_bytes_, 0); | 265 DCHECK_GE(remaining_bytes_, 0); |
| 266 | 266 |
| 267 if (remaining_bytes_ > 0 && byte_range_.first_byte_position() != 0) { | 267 if (remaining_bytes_ > 0 && byte_range_.first_byte_position() != 0) { |
| 268 int rv = stream_->Seek(base::File::FROM_BEGIN, | 268 int rv = stream_->Seek(byte_range_.first_byte_position(), |
| 269 byte_range_.first_byte_position(), | |
| 270 base::Bind(&URLRequestFileJob::DidSeek, | 269 base::Bind(&URLRequestFileJob::DidSeek, |
| 271 weak_ptr_factory_.GetWeakPtr())); | 270 weak_ptr_factory_.GetWeakPtr())); |
| 272 if (rv != ERR_IO_PENDING) { | 271 if (rv != ERR_IO_PENDING) { |
| 273 // stream_->Seek() failed, so pass an intentionally erroneous value | 272 // stream_->Seek() failed, so pass an intentionally erroneous value |
| 274 // into DidSeek(). | 273 // into DidSeek(). |
| 275 DidSeek(-1); | 274 DidSeek(-1); |
| 276 } | 275 } |
| 277 } else { | 276 } else { |
| 278 // We didn't need to call stream_->Seek() at all, so we pass to DidSeek() | 277 // We didn't need to call stream_->Seek() at all, so we pass to DidSeek() |
| 279 // the value that would mean seek success. This way we skip the code | 278 // the value that would mean seek success. This way we skip the code |
| (...skipping 27 matching lines...) Expand all Loading... |
| 307 if (result == 0) { | 306 if (result == 0) { |
| 308 NotifyDone(URLRequestStatus()); | 307 NotifyDone(URLRequestStatus()); |
| 309 } else if (result < 0) { | 308 } else if (result < 0) { |
| 310 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 309 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 311 } | 310 } |
| 312 | 311 |
| 313 NotifyReadComplete(result); | 312 NotifyReadComplete(result); |
| 314 } | 313 } |
| 315 | 314 |
| 316 } // namespace net | 315 } // namespace net |
| OLD | NEW |