| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 if (remaining_bytes_ < dest_size) | 180 if (remaining_bytes_ < dest_size) |
| 181 dest_size = static_cast<int>(remaining_bytes_); | 181 dest_size = static_cast<int>(remaining_bytes_); |
| 182 | 182 |
| 183 // If we should copy zero bytes because |remaining_bytes_| is zero, short | 183 // If we should copy zero bytes because |remaining_bytes_| is zero, short |
| 184 // circuit here. | 184 // circuit here. |
| 185 if (!dest_size) { | 185 if (!dest_size) { |
| 186 *bytes_read = 0; | 186 *bytes_read = 0; |
| 187 return true; | 187 return true; |
| 188 } | 188 } |
| 189 | 189 |
| 190 int rv = stream_.Read(dest->data(), dest_size, | 190 int rv = stream_.Read(dest, dest_size, |
| 191 base::Bind(&URLRequestFileJob::DidRead, | 191 base::Bind(&URLRequestFileJob::DidRead, |
| 192 base::Unretained(this))); | 192 base::Unretained(this))); |
| 193 if (rv >= 0) { | 193 if (rv >= 0) { |
| 194 // Data is immediately available. | 194 // Data is immediately available. |
| 195 *bytes_read = rv; | 195 *bytes_read = rv; |
| 196 remaining_bytes_ -= rv; | 196 remaining_bytes_ -= rv; |
| 197 DCHECK_GE(remaining_bytes_, 0); | 197 DCHECK_GE(remaining_bytes_, 0); |
| 198 return true; | 198 return true; |
| 199 } | 199 } |
| 200 | 200 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 359 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 360 } | 360 } |
| 361 | 361 |
| 362 remaining_bytes_ -= result; | 362 remaining_bytes_ -= result; |
| 363 DCHECK_GE(remaining_bytes_, 0); | 363 DCHECK_GE(remaining_bytes_, 0); |
| 364 | 364 |
| 365 NotifyReadComplete(result); | 365 NotifyReadComplete(result); |
| 366 } | 366 } |
| 367 | 367 |
| 368 } // namespace net | 368 } // namespace net |
| OLD | NEW |