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

Side by Side Diff: storage/browser/blob/blob_reader.h

Issue 1234813004: [BlobAsync] Asynchronous Blob Construction Final Patch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-protocol-change
Patch Set: added shared memory test, and fixed memory leak Created 4 years, 10 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef STORAGE_BROWSER_BLOB_BLOB_READER_H_ 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_READER_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_READER_H_ 6 #define STORAGE_BROWSER_BLOB_BLOB_READER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <map> 10 #include <map>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/gtest_prod_util.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
16 #include "net/base/completion_callback.h" 17 #include "net/base/completion_callback.h"
17 #include "storage/browser/storage_browser_export.h" 18 #include "storage/browser/storage_browser_export.h"
18 19
19 class GURL; 20 class GURL;
20 21
21 namespace base { 22 namespace base {
22 class FilePath; 23 class FilePath;
23 class SequencedTaskRunner; 24 class SequencedTaskRunner;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // Returns the total size of the blob. This is populated after CalculateSize 110 // Returns the total size of the blob. This is populated after CalculateSize
110 // is called. 111 // is called.
111 uint64_t total_size() const { 112 uint64_t total_size() const {
112 DCHECK(total_size_calculated_); 113 DCHECK(total_size_calculated_);
113 return total_size_; 114 return total_size_;
114 } 115 }
115 116
116 protected: 117 protected:
117 friend class BlobDataHandle; 118 friend class BlobDataHandle;
118 friend class BlobReaderTest; 119 friend class BlobReaderTest;
120 FRIEND_TEST_ALL_PREFIXES(BlobReaderTest, HandleBeforeAsyncCancel);
119 121
120 BlobReader(const BlobDataHandle* blob_handle, 122 BlobReader(const BlobDataHandle* blob_handle,
121 scoped_ptr<FileStreamReaderProvider> file_stream_provider, 123 scoped_ptr<FileStreamReaderProvider> file_stream_provider,
122 base::SequencedTaskRunner* file_task_runner); 124 base::SequencedTaskRunner* file_task_runner);
123 125
124 bool total_size_calculated() const { return total_size_calculated_; } 126 bool total_size_calculated() const { return total_size_calculated_; }
125 127
126 private: 128 private:
127 Status ReportError(int net_error); 129 Status ReportError(int net_error);
128 void InvalidateCallbacksAndDone(int net_error, net::CompletionCallback done); 130 void InvalidateCallbacksAndDone(int net_error, net::CompletionCallback done);
129 131
132 void AsyncCalculateSize(const net::CompletionCallback& done,
133 bool async_succeeded);
134 Status CalculateSizeImpl(const net::CompletionCallback& done);
130 bool AddItemLength(size_t index, uint64_t length); 135 bool AddItemLength(size_t index, uint64_t length);
131 bool ResolveFileItemLength(const BlobDataItem& item, 136 bool ResolveFileItemLength(const BlobDataItem& item,
132 int64_t total_length, 137 int64_t total_length,
133 uint64_t* output_length); 138 uint64_t* output_length);
134 void DidGetFileItemLength(size_t index, int64_t result); 139 void DidGetFileItemLength(size_t index, int64_t result);
135 void DidCountSize(); 140 void DidCountSize();
136 141
137 // For reading the blob. 142 // For reading the blob.
138 // Returns if we're done, PENDING_IO if we're waiting on async. 143 // Returns if we're done, PENDING_IO if we're waiting on async.
139 Status ReadLoop(int* bytes_read); 144 Status ReadLoop(int* bytes_read);
(...skipping 16 matching lines...) Expand all
156 // Returns a FileStreamReader for a blob item at |index|. 161 // Returns a FileStreamReader for a blob item at |index|.
157 // If the item at |index| is not of file this returns NULL. 162 // If the item at |index| is not of file this returns NULL.
158 FileStreamReader* GetOrCreateFileReaderAtIndex(size_t index); 163 FileStreamReader* GetOrCreateFileReaderAtIndex(size_t index);
159 // If the reader is null, then this basically performs a delete operation. 164 // If the reader is null, then this basically performs a delete operation.
160 void SetFileReaderAtIndex(size_t index, scoped_ptr<FileStreamReader> reader); 165 void SetFileReaderAtIndex(size_t index, scoped_ptr<FileStreamReader> reader);
161 // Creates a FileStreamReader for the item with additional_offset. 166 // Creates a FileStreamReader for the item with additional_offset.
162 scoped_ptr<FileStreamReader> CreateFileStreamReader( 167 scoped_ptr<FileStreamReader> CreateFileStreamReader(
163 const BlobDataItem& item, 168 const BlobDataItem& item,
164 uint64_t additional_offset); 169 uint64_t additional_offset);
165 170
171 scoped_ptr<BlobDataHandle> blob_handle_;
166 scoped_ptr<BlobDataSnapshot> blob_data_; 172 scoped_ptr<BlobDataSnapshot> blob_data_;
167 scoped_ptr<FileStreamReaderProvider> file_stream_provider_; 173 scoped_ptr<FileStreamReaderProvider> file_stream_provider_;
168 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; 174 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
169 175
170 int net_error_; 176 int net_error_;
171 bool item_list_populated_ = false; 177 bool item_list_populated_ = false;
172 std::vector<uint64_t> item_length_list_; 178 std::vector<uint64_t> item_length_list_;
173 179
174 scoped_refptr<net::DrainableIOBuffer> read_buf_; 180 scoped_refptr<net::DrainableIOBuffer> read_buf_;
175 181
176 bool total_size_calculated_ = false; 182 bool total_size_calculated_ = false;
177 uint64_t total_size_ = 0; 183 uint64_t total_size_ = 0;
178 uint64_t remaining_bytes_ = 0; 184 uint64_t remaining_bytes_ = 0;
179 size_t pending_get_file_info_count_ = 0; 185 size_t pending_get_file_info_count_ = 0;
180 std::map<size_t, FileStreamReader*> index_to_reader_; 186 std::map<size_t, FileStreamReader*> index_to_reader_;
181 size_t current_item_index_ = 0; 187 size_t current_item_index_ = 0;
182 uint64_t current_item_offset_ = 0; 188 uint64_t current_item_offset_ = 0;
183 189
184 bool io_pending_ = false; 190 bool io_pending_ = false;
185 191
186 net::CompletionCallback size_callback_; 192 net::CompletionCallback size_callback_;
187 net::CompletionCallback read_callback_; 193 net::CompletionCallback read_callback_;
188 194
189 base::WeakPtrFactory<BlobReader> weak_factory_; 195 base::WeakPtrFactory<BlobReader> weak_factory_;
190 DISALLOW_COPY_AND_ASSIGN(BlobReader); 196 DISALLOW_COPY_AND_ASSIGN(BlobReader);
191 }; 197 };
192 198
193 } // namespace storage 199 } // namespace storage
194 #endif // STORAGE_BROWSER_BLOB_BLOB_READER_H_ 200 #endif // STORAGE_BROWSER_BLOB_BLOB_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698