OLD | NEW |
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/gtest_prod_util.h" |
13 #include "base/macros.h" | 14 #include "base/macros.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; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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); |
| 121 FRIEND_TEST_ALL_PREFIXES(BlobReaderTest, ReadFromIncompleteBlob); |
119 | 122 |
120 BlobReader(const BlobDataHandle* blob_handle, | 123 BlobReader(const BlobDataHandle* blob_handle, |
121 scoped_ptr<FileStreamReaderProvider> file_stream_provider, | 124 scoped_ptr<FileStreamReaderProvider> file_stream_provider, |
122 base::SequencedTaskRunner* file_task_runner); | 125 base::SequencedTaskRunner* file_task_runner); |
123 | 126 |
124 bool total_size_calculated() const { return total_size_calculated_; } | 127 bool total_size_calculated() const { return total_size_calculated_; } |
125 | 128 |
126 private: | 129 private: |
127 Status ReportError(int net_error); | 130 Status ReportError(int net_error); |
128 void InvalidateCallbacksAndDone(int net_error, net::CompletionCallback done); | 131 void InvalidateCallbacksAndDone(int net_error, net::CompletionCallback done); |
129 | 132 |
| 133 void AsyncCalculateSize(const net::CompletionCallback& done, |
| 134 bool async_succeeded); |
| 135 Status CalculateSizeImpl(const net::CompletionCallback& done); |
130 bool AddItemLength(size_t index, uint64_t length); | 136 bool AddItemLength(size_t index, uint64_t length); |
131 bool ResolveFileItemLength(const BlobDataItem& item, | 137 bool ResolveFileItemLength(const BlobDataItem& item, |
132 int64_t total_length, | 138 int64_t total_length, |
133 uint64_t* output_length); | 139 uint64_t* output_length); |
134 void DidGetFileItemLength(size_t index, int64_t result); | 140 void DidGetFileItemLength(size_t index, int64_t result); |
135 void DidCountSize(); | 141 void DidCountSize(); |
136 | 142 |
137 // For reading the blob. | 143 // For reading the blob. |
138 // Returns if we're done, PENDING_IO if we're waiting on async. | 144 // Returns if we're done, PENDING_IO if we're waiting on async. |
139 Status ReadLoop(int* bytes_read); | 145 Status ReadLoop(int* bytes_read); |
(...skipping 16 matching lines...) Expand all Loading... |
156 // Returns a FileStreamReader for a blob item at |index|. | 162 // Returns a FileStreamReader for a blob item at |index|. |
157 // If the item at |index| is not of file this returns NULL. | 163 // If the item at |index| is not of file this returns NULL. |
158 FileStreamReader* GetOrCreateFileReaderAtIndex(size_t index); | 164 FileStreamReader* GetOrCreateFileReaderAtIndex(size_t index); |
159 // If the reader is null, then this basically performs a delete operation. | 165 // If the reader is null, then this basically performs a delete operation. |
160 void SetFileReaderAtIndex(size_t index, scoped_ptr<FileStreamReader> reader); | 166 void SetFileReaderAtIndex(size_t index, scoped_ptr<FileStreamReader> reader); |
161 // Creates a FileStreamReader for the item with additional_offset. | 167 // Creates a FileStreamReader for the item with additional_offset. |
162 scoped_ptr<FileStreamReader> CreateFileStreamReader( | 168 scoped_ptr<FileStreamReader> CreateFileStreamReader( |
163 const BlobDataItem& item, | 169 const BlobDataItem& item, |
164 uint64_t additional_offset); | 170 uint64_t additional_offset); |
165 | 171 |
| 172 scoped_ptr<BlobDataHandle> blob_handle_; |
166 scoped_ptr<BlobDataSnapshot> blob_data_; | 173 scoped_ptr<BlobDataSnapshot> blob_data_; |
167 scoped_ptr<FileStreamReaderProvider> file_stream_provider_; | 174 scoped_ptr<FileStreamReaderProvider> file_stream_provider_; |
168 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | 175 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
169 | 176 |
170 int net_error_; | 177 int net_error_; |
171 bool item_list_populated_ = false; | 178 bool item_list_populated_ = false; |
172 std::vector<uint64_t> item_length_list_; | 179 std::vector<uint64_t> item_length_list_; |
173 | 180 |
174 scoped_refptr<net::DrainableIOBuffer> read_buf_; | 181 scoped_refptr<net::DrainableIOBuffer> read_buf_; |
175 | 182 |
176 bool total_size_calculated_ = false; | 183 bool total_size_calculated_ = false; |
177 uint64_t total_size_ = 0; | 184 uint64_t total_size_ = 0; |
178 uint64_t remaining_bytes_ = 0; | 185 uint64_t remaining_bytes_ = 0; |
179 size_t pending_get_file_info_count_ = 0; | 186 size_t pending_get_file_info_count_ = 0; |
180 std::map<size_t, FileStreamReader*> index_to_reader_; | 187 std::map<size_t, FileStreamReader*> index_to_reader_; |
181 size_t current_item_index_ = 0; | 188 size_t current_item_index_ = 0; |
182 uint64_t current_item_offset_ = 0; | 189 uint64_t current_item_offset_ = 0; |
183 | 190 |
184 bool io_pending_ = false; | 191 bool io_pending_ = false; |
185 | 192 |
186 net::CompletionCallback size_callback_; | 193 net::CompletionCallback size_callback_; |
187 net::CompletionCallback read_callback_; | 194 net::CompletionCallback read_callback_; |
188 | 195 |
189 base::WeakPtrFactory<BlobReader> weak_factory_; | 196 base::WeakPtrFactory<BlobReader> weak_factory_; |
190 DISALLOW_COPY_AND_ASSIGN(BlobReader); | 197 DISALLOW_COPY_AND_ASSIGN(BlobReader); |
191 }; | 198 }; |
192 | 199 |
193 } // namespace storage | 200 } // namespace storage |
194 #endif // STORAGE_BROWSER_BLOB_BLOB_READER_H_ | 201 #endif // STORAGE_BROWSER_BLOB_BLOB_READER_H_ |
OLD | NEW |