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