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

Side by Side Diff: content/browser/fileapi/upload_file_system_file_element_reader.cc

Issue 470323003: [fsp] Improve performance for reading small chunks of data. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/fileapi/upload_file_system_file_element_reader.h" 5 #include "content/browser/fileapi/upload_file_system_file_element_reader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/numerics/safe_conversions.h"
10 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
11 #include "webkit/browser/blob/file_stream_reader.h" 12 #include "webkit/browser/blob/file_stream_reader.h"
12 #include "webkit/browser/fileapi/file_system_context.h" 13 #include "webkit/browser/fileapi/file_system_context.h"
13 #include "webkit/browser/fileapi/file_system_url.h" 14 #include "webkit/browser/fileapi/file_system_url.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 UploadFileSystemFileElementReader::UploadFileSystemFileElementReader( 18 UploadFileSystemFileElementReader::UploadFileSystemFileElementReader(
18 storage::FileSystemContext* file_system_context, 19 storage::FileSystemContext* file_system_context,
19 const GURL& url, 20 const GURL& url,
(...skipping 14 matching lines...) Expand all
34 } 35 }
35 36
36 int UploadFileSystemFileElementReader::Init( 37 int UploadFileSystemFileElementReader::Init(
37 const net::CompletionCallback& callback) { 38 const net::CompletionCallback& callback) {
38 // Reset states. 39 // Reset states.
39 weak_ptr_factory_.InvalidateWeakPtrs(); 40 weak_ptr_factory_.InvalidateWeakPtrs();
40 stream_length_ = 0; 41 stream_length_ = 0;
41 position_ = 0; 42 position_ = 0;
42 43
43 // Initialize the stream reader and the length. 44 // Initialize the stream reader and the length.
44 stream_reader_ = 45 stream_reader_ = file_system_context_->CreateFileStreamReader(
45 file_system_context_->CreateFileStreamReader( 46 file_system_context_->CrackURL(url_),
46 file_system_context_->CrackURL(url_), 47 range_offset_,
47 range_offset_, 48 base::checked_cast<int64>(range_length_),
48 expected_modification_time_); 49 expected_modification_time_);
49 DCHECK(stream_reader_); 50 DCHECK(stream_reader_);
50 51
51 const int64 result = stream_reader_->GetLength( 52 const int64 result = stream_reader_->GetLength(
52 base::Bind(&UploadFileSystemFileElementReader::OnGetLength, 53 base::Bind(&UploadFileSystemFileElementReader::OnGetLength,
53 weak_ptr_factory_.GetWeakPtr(), 54 weak_ptr_factory_.GetWeakPtr(),
54 callback)); 55 callback));
55 if (result >= 0) { 56 if (result >= 0) {
56 stream_length_ = result; 57 stream_length_ = result;
57 return net::OK; 58 return net::OK;
58 } 59 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 int result) { 109 int result) {
109 if (result > 0) { 110 if (result > 0) {
110 position_ += result; 111 position_ += result;
111 DCHECK_LE(position_, GetContentLength()); 112 DCHECK_LE(position_, GetContentLength());
112 } 113 }
113 if (!callback.is_null()) 114 if (!callback.is_null())
114 callback.Run(result); 115 callback.Run(result);
115 } 116 }
116 117
117 } // namespace content 118 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698