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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 287 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
288 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 288 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
289 return; | 289 return; |
290 } | 290 } |
291 | 291 |
292 set_expected_content_size(remaining_bytes_); | 292 set_expected_content_size(remaining_bytes_); |
293 NotifyHeadersComplete(); | 293 NotifyHeadersComplete(); |
294 } | 294 } |
295 | 295 |
296 void URLRequestFileJob::DidRead(scoped_refptr<net::IOBuffer> buf, int result) { | 296 void URLRequestFileJob::DidRead(scoped_refptr<net::IOBuffer> buf, int result) { |
| 297 if (result > 0) { |
| 298 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status |
| 299 remaining_bytes_ -= result; |
| 300 DCHECK_GE(remaining_bytes_, 0); |
| 301 } |
| 302 |
297 OnReadComplete(buf.get(), result); | 303 OnReadComplete(buf.get(), result); |
298 buf = NULL; | 304 buf = NULL; |
299 if (result > 0) { | 305 |
300 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status | 306 if (result == 0) { |
301 } else if (result == 0) { | |
302 NotifyDone(URLRequestStatus()); | 307 NotifyDone(URLRequestStatus()); |
303 } else { | 308 } else if (result < 0) { |
304 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 309 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
305 } | 310 } |
306 | 311 |
307 remaining_bytes_ -= result; | |
308 DCHECK_GE(remaining_bytes_, 0); | |
309 | |
310 NotifyReadComplete(result); | 312 NotifyReadComplete(result); |
311 } | 313 } |
312 | 314 |
313 } // namespace net | 315 } // namespace net |
OLD | NEW |