Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: storage/browser/blob/blob_url_request_job.cc

Issue 470323003: [fsp] Improve performance for reading small chunks of data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "storage/browser/blob/blob_url_request_job.h" 5 #include "storage/browser/blob/blob_url_request_job.h"
6 6
7 #include <algorithm>
7 #include <limits> 8 #include <limits>
9 #include <string>
10 #include <vector>
8 11
9 #include "base/basictypes.h" 12 #include "base/basictypes.h"
10 #include "base/bind.h" 13 #include "base/bind.h"
11 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
12 #include "base/files/file_util_proxy.h" 15 #include "base/files/file_util_proxy.h"
13 #include "base/format_macros.h" 16 #include "base/format_macros.h"
14 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
15 #include "base/message_loop/message_loop_proxy.h" 18 #include "base/message_loop/message_loop_proxy.h"
19 #include "base/numerics/safe_conversions.h"
16 #include "base/stl_util.h" 20 #include "base/stl_util.h"
17 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
19 #include "net/base/io_buffer.h" 23 #include "net/base/io_buffer.h"
20 #include "net/base/net_errors.h" 24 #include "net/base/net_errors.h"
21 #include "net/http/http_request_headers.h" 25 #include "net/http/http_request_headers.h"
22 #include "net/http/http_response_headers.h" 26 #include "net/http/http_response_headers.h"
23 #include "net/http/http_response_info.h" 27 #include "net/http/http_response_info.h"
24 #include "net/http/http_util.h" 28 #include "net/http/http_util.h"
25 #include "net/url_request/url_request.h" 29 #include "net/url_request/url_request.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 NotifyFailure(error); 220 NotifyFailure(error);
217 return; 221 return;
218 } 222 }
219 223
220 // Apply the range requirement. 224 // Apply the range requirement.
221 if (!byte_range_.ComputeBounds(total_size_)) { 225 if (!byte_range_.ComputeBounds(total_size_)) {
222 NotifyFailure(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); 226 NotifyFailure(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
223 return; 227 return;
224 } 228 }
225 229
226 remaining_bytes_ = byte_range_.last_byte_position() - 230 remaining_bytes_ = base::checked_cast<int64>(
227 byte_range_.first_byte_position() + 1; 231 byte_range_.last_byte_position() - byte_range_.first_byte_position() + 1);
228 DCHECK_GE(remaining_bytes_, 0); 232 DCHECK_GE(remaining_bytes_, 0);
229 233
230 // Do the seek at the beginning of the request. 234 // Do the seek at the beginning of the request.
231 if (byte_range_.first_byte_position()) 235 if (byte_range_.first_byte_position())
232 Seek(byte_range_.first_byte_position()); 236 Seek(byte_range_.first_byte_position());
233 237
234 NotifySuccess(); 238 NotifySuccess();
235 } 239 }
236 240
237 void BlobURLRequestJob::DidGetFileItemLength(size_t index, int64 result) { 241 void BlobURLRequestJob::DidGetFileItemLength(size_t index, int64 result) {
(...skipping 17 matching lines...) Expand all
255 uint64 item_offset = item.offset(); 259 uint64 item_offset = item.offset();
256 uint64 item_length = item.length(); 260 uint64 item_length = item.length();
257 261
258 if (item_offset > file_length) { 262 if (item_offset > file_length) {
259 NotifyFailure(net::ERR_FILE_NOT_FOUND); 263 NotifyFailure(net::ERR_FILE_NOT_FOUND);
260 return; 264 return;
261 } 265 }
262 266
263 uint64 max_length = file_length - item_offset; 267 uint64 max_length = file_length - item_offset;
264 268
265 // If item length is -1, we need to use the file size being resolved 269 // If item length is undefined, then we need to use the file size being
266 // in the real time. 270 // resolved in the real time.
267 if (item_length == static_cast<uint64>(-1)) { 271 if (item_length == std::numeric_limits<uint64>::max()) {
268 item_length = max_length; 272 item_length = max_length;
269 } else if (item_length > max_length) { 273 } else if (item_length > max_length) {
270 NotifyFailure(net::ERR_FILE_NOT_FOUND); 274 NotifyFailure(net::ERR_FILE_NOT_FOUND);
271 return; 275 return;
272 } 276 }
273 277
274 if (!AddItemLength(index, item_length)) 278 if (!AddItemLength(index, item_length))
275 return; 279 return;
276 280
277 if (--pending_get_file_info_count_ == 0) 281 if (--pending_get_file_info_count_ == 0)
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 FileStreamReader* reader = NULL; 569 FileStreamReader* reader = NULL;
566 switch (item.type()) { 570 switch (item.type()) {
567 case BlobData::Item::TYPE_FILE: 571 case BlobData::Item::TYPE_FILE:
568 reader = FileStreamReader::CreateForLocalFile( 572 reader = FileStreamReader::CreateForLocalFile(
569 file_thread_proxy_.get(), 573 file_thread_proxy_.get(),
570 item.path(), 574 item.path(),
571 item.offset() + additional_offset, 575 item.offset() + additional_offset,
572 item.expected_modification_time()); 576 item.expected_modification_time());
573 break; 577 break;
574 case BlobData::Item::TYPE_FILE_FILESYSTEM: 578 case BlobData::Item::TYPE_FILE_FILESYSTEM:
575 reader = file_system_context_->CreateFileStreamReader( 579 reader = file_system_context_
576 storage::FileSystemURL( 580 ->CreateFileStreamReader(
577 file_system_context_->CrackURL( 581 storage::FileSystemURL(file_system_context_->CrackURL(
578 item.filesystem_url())), 582 item.filesystem_url())),
579 item.offset() + additional_offset, 583 item.offset() + additional_offset,
580 item.expected_modification_time()) 584 item.length() == std::numeric_limits<uint64>::max()
585 ? storage::kMaximumLength
586 : item.length() - additional_offset,
jianli 2014/09/11 17:45:51 Should this be item.length() - item.offset() - add
mtomasz 2014/09/16 08:58:22 I don't think so. item.offset() is the start posit
587 item.expected_modification_time())
581 .release(); 588 .release();
582 break; 589 break;
583 default: 590 default:
584 NOTREACHED(); 591 NOTREACHED();
585 } 592 }
586 DCHECK(reader); 593 DCHECK(reader);
587 index_to_reader_[index] = reader; 594 index_to_reader_[index] = reader;
588 } 595 }
589 596
590 } // namespace storage 597 } // namespace storage
OLDNEW
« no previous file with comments | « content/public/test/test_file_system_backend.cc ('k') | storage/browser/fileapi/copy_or_move_operation_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698