| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 base::WorkerPool::PostTask( | 154 base::WorkerPool::PostTask( |
| 155 FROM_HERE, | 155 FROM_HERE, |
| 156 base::Bind(&AsyncResolver::Resolve, async_resolver_.get(), file_path_), | 156 base::Bind(&AsyncResolver::Resolve, async_resolver_.get(), file_path_), |
| 157 true); | 157 true); |
| 158 } | 158 } |
| 159 | 159 |
| 160 void URLRequestFileJob::Kill() { | 160 void URLRequestFileJob::Kill() { |
| 161 // URL requests should not block on the disk! | 161 // URL requests should not block on the disk! |
| 162 // http://code.google.com/p/chromium/issues/detail?id=59849 | 162 // http://code.google.com/p/chromium/issues/detail?id=59849 |
| 163 base::ThreadRestrictions::ScopedAllowIO allow_io; | 163 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 164 stream_.Close(); | 164 stream_.CloseSync(); |
| 165 | 165 |
| 166 if (async_resolver_) { | 166 if (async_resolver_) { |
| 167 async_resolver_->Cancel(); | 167 async_resolver_->Cancel(); |
| 168 async_resolver_ = NULL; | 168 async_resolver_ = NULL; |
| 169 } | 169 } |
| 170 | 170 |
| 171 URLRequestJob::Kill(); | 171 URLRequestJob::Kill(); |
| 172 } | 172 } |
| 173 | 173 |
| 174 bool URLRequestFileJob::ReadRawData(IOBuffer* dest, int dest_size, | 174 bool URLRequestFileJob::ReadRawData(IOBuffer* dest, int dest_size, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 if (!exists) { | 306 if (!exists) { |
| 307 rv = ERR_FILE_NOT_FOUND; | 307 rv = ERR_FILE_NOT_FOUND; |
| 308 } else if (!is_directory_) { | 308 } else if (!is_directory_) { |
| 309 // URL requests should not block on the disk! | 309 // URL requests should not block on the disk! |
| 310 // http://code.google.com/p/chromium/issues/detail?id=59849 | 310 // http://code.google.com/p/chromium/issues/detail?id=59849 |
| 311 base::ThreadRestrictions::ScopedAllowIO allow_io; | 311 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 312 | 312 |
| 313 int flags = base::PLATFORM_FILE_OPEN | | 313 int flags = base::PLATFORM_FILE_OPEN | |
| 314 base::PLATFORM_FILE_READ | | 314 base::PLATFORM_FILE_READ | |
| 315 base::PLATFORM_FILE_ASYNC; | 315 base::PLATFORM_FILE_ASYNC; |
| 316 rv = stream_.Open(file_path_, flags); | 316 rv = stream_.OpenSync(file_path_, flags); |
| 317 } | 317 } |
| 318 | 318 |
| 319 if (rv != OK) { | 319 if (rv != OK) { |
| 320 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 320 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 321 return; | 321 return; |
| 322 } | 322 } |
| 323 | 323 |
| 324 if (!byte_range_.ComputeBounds(file_info.size)) { | 324 if (!byte_range_.ComputeBounds(file_info.size)) { |
| 325 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 325 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
| 326 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 326 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
| (...skipping 32 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 |