Chromium Code Reviews| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 if (remaining_bytes_ < dest_size) | 92 if (remaining_bytes_ < dest_size) |
| 93 dest_size = static_cast<int>(remaining_bytes_); | 93 dest_size = static_cast<int>(remaining_bytes_); |
| 94 | 94 |
| 95 // If we should copy zero bytes because |remaining_bytes_| is zero, short | 95 // If we should copy zero bytes because |remaining_bytes_| is zero, short |
| 96 // circuit here. | 96 // circuit here. |
| 97 if (!dest_size) { | 97 if (!dest_size) { |
| 98 *bytes_read = 0; | 98 *bytes_read = 0; |
| 99 return true; | 99 return true; |
| 100 } | 100 } |
| 101 | 101 |
| 102 int rv = stream_->Read(dest, dest_size, | 102 int rv = stream_->Read(dest, |
| 103 dest_size, | |
| 103 base::Bind(&URLRequestFileJob::DidRead, | 104 base::Bind(&URLRequestFileJob::DidRead, |
| 104 weak_ptr_factory_.GetWeakPtr())); | 105 weak_ptr_factory_.GetWeakPtr(), |
| 106 base::Unretained(dest))); | |
|
rvargas (doing something else)
2014/04/08 16:53:45
This cannot be unretained because the stream is al
asargent_no_longer_on_chrome
2014/04/09 20:59:59
Ok, I guess I was confused by both the code flow a
rvargas (doing something else)
2014/04/09 23:48:50
yeah, the comment definitely can be improved.
| |
| 105 if (rv >= 0) { | 107 if (rv >= 0) { |
| 106 // Data is immediately available. | 108 // Data is immediately available. |
| 107 *bytes_read = rv; | 109 *bytes_read = rv; |
| 108 remaining_bytes_ -= rv; | 110 remaining_bytes_ -= rv; |
| 109 DCHECK_GE(remaining_bytes_, 0); | 111 DCHECK_GE(remaining_bytes_, 0); |
| 110 return true; | 112 return true; |
| 111 } | 113 } |
| 112 | 114 |
| 113 // Otherwise, a read error occured. We may just need to wait... | 115 // Otherwise, a read error occured. We may just need to wait... |
| 114 if (rv == ERR_IO_PENDING) { | 116 if (rv == ERR_IO_PENDING) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 // because we need to do multipart encoding here. | 187 // because we need to do multipart encoding here. |
| 186 // TODO(hclam): decide whether we want to support multiple range | 188 // TODO(hclam): decide whether we want to support multiple range |
| 187 // requests. | 189 // requests. |
| 188 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 190 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
| 189 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 191 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
| 190 } | 192 } |
| 191 } | 193 } |
| 192 } | 194 } |
| 193 } | 195 } |
| 194 | 196 |
| 197 void URLRequestFileJob::OnSeekComplete(int64 result) {} | |
|
rvargas (doing something else)
2014/04/08 16:53:45
nit: use {
}
and an empty line between the methods
asargent_no_longer_on_chrome
2014/04/09 20:59:59
Done.
(Note that 'git cl format' does {} without
| |
| 198 void URLRequestFileJob::OnReadComplete(net::IOBuffer* buf, int result) {} | |
| 199 | |
| 195 URLRequestFileJob::~URLRequestFileJob() { | 200 URLRequestFileJob::~URLRequestFileJob() { |
| 196 } | 201 } |
| 197 | 202 |
| 198 void URLRequestFileJob::FetchMetaInfo(const base::FilePath& file_path, | 203 void URLRequestFileJob::FetchMetaInfo(const base::FilePath& file_path, |
| 199 FileMetaInfo* meta_info) { | 204 FileMetaInfo* meta_info) { |
| 200 base::File::Info file_info; | 205 base::File::Info file_info; |
| 201 meta_info->file_exists = base::GetFileInfo(file_path, &file_info); | 206 meta_info->file_exists = base::GetFileInfo(file_path, &file_info); |
| 202 if (meta_info->file_exists) { | 207 if (meta_info->file_exists) { |
| 203 meta_info->file_size = file_info.size; | 208 meta_info->file_size = file_info.size; |
| 204 meta_info->is_directory = file_info.is_directory; | 209 meta_info->is_directory = file_info.is_directory; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 } | 271 } |
| 267 } else { | 272 } else { |
| 268 // We didn't need to call stream_->Seek() at all, so we pass to DidSeek() | 273 // We didn't need to call stream_->Seek() at all, so we pass to DidSeek() |
| 269 // the value that would mean seek success. This way we skip the code | 274 // the value that would mean seek success. This way we skip the code |
| 270 // handling seek failure. | 275 // handling seek failure. |
| 271 DidSeek(byte_range_.first_byte_position()); | 276 DidSeek(byte_range_.first_byte_position()); |
| 272 } | 277 } |
| 273 } | 278 } |
| 274 | 279 |
| 275 void URLRequestFileJob::DidSeek(int64 result) { | 280 void URLRequestFileJob::DidSeek(int64 result) { |
| 281 OnSeekComplete(result); | |
| 276 if (result != byte_range_.first_byte_position()) { | 282 if (result != byte_range_.first_byte_position()) { |
| 277 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 283 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
| 278 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 284 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
| 279 return; | 285 return; |
| 280 } | 286 } |
| 281 | 287 |
| 282 set_expected_content_size(remaining_bytes_); | 288 set_expected_content_size(remaining_bytes_); |
| 283 NotifyHeadersComplete(); | 289 NotifyHeadersComplete(); |
| 284 } | 290 } |
| 285 | 291 |
| 286 void URLRequestFileJob::DidRead(int result) { | 292 void URLRequestFileJob::DidRead(net::IOBuffer* buf, int result) { |
| 293 OnReadComplete(buf, result); | |
| 287 if (result > 0) { | 294 if (result > 0) { |
| 288 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status | 295 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status |
| 289 } else if (result == 0) { | 296 } else if (result == 0) { |
| 290 NotifyDone(URLRequestStatus()); | 297 NotifyDone(URLRequestStatus()); |
| 291 } else { | 298 } else { |
| 292 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 299 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
| 293 } | 300 } |
| 294 | 301 |
| 295 remaining_bytes_ -= result; | 302 remaining_bytes_ -= result; |
| 296 DCHECK_GE(remaining_bytes_, 0); | 303 DCHECK_GE(remaining_bytes_, 0); |
| 297 | 304 |
| 298 NotifyReadComplete(result); | 305 NotifyReadComplete(result); |
| 299 } | 306 } |
| 300 | 307 |
| 301 } // namespace net | 308 } // namespace net |
| OLD | NEW |