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

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

Issue 1513783005: [Blob] Fix for resetting reader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 5 years 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 <stdint.h> 8 #include <stdint.h>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "net/base/completion_callback.h" 15 #include "net/base/completion_callback.h"
16 #include "net/base/net_errors.h"
16 #include "storage/browser/storage_browser_export.h" 17 #include "storage/browser/storage_browser_export.h"
17 18
18 class GURL; 19 class GURL;
19 20
20 namespace base { 21 namespace base {
21 class FilePath; 22 class FilePath;
22 class SequencedTaskRunner; 23 class SequencedTaskRunner;
23 class TaskRunner; 24 class TaskRunner;
24 class Time; 25 class Time;
25 } 26 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 const GURL& filesystem_url, 59 const GURL& filesystem_url,
59 int64_t offset, 60 int64_t offset,
60 int64_t max_bytes_to_read, 61 int64_t max_bytes_to_read,
61 const base::Time& expected_modification_time) = 0; 62 const base::Time& expected_modification_time) = 0;
62 }; 63 };
63 enum class Status { NET_ERROR, IO_PENDING, DONE }; 64 enum class Status { NET_ERROR, IO_PENDING, DONE };
64 virtual ~BlobReader(); 65 virtual ~BlobReader();
65 66
66 // This calculates the total size of the blob, and initializes the reading 67 // This calculates the total size of the blob, and initializes the reading
67 // cursor. 68 // cursor.
68 // * This should only be called once per reader. 69 // * This hsould only be called once per reader.
michaeln 2015/12/11 02:17:01 stray key strike
69 // * Status::Done means that the total_size() value is populated and you can 70 // * Status::Done means that the total_size() value is populated and you can
70 // continue to SetReadRange or Read. 71 // continue to SetReadRange or Read.
71 // * The 'done' callback is only called if Status::IO_PENDING is returned. 72 // * The 'done' callback is only called if Status::IO_PENDING is returned.
72 // The callback value contains the error code or net::OK. Please use the 73 // The callback value contains the error code or net::OK. Please use the
73 // total_size() value to query the blob size, as it's uint64_t. 74 // total_size() value to query the blob size, as it's uint64_t.
74 Status CalculateSize(const net::CompletionCallback& done); 75 Status CalculateSize(const net::CompletionCallback& done);
75 76
76 // Used to set the read position. 77 // Used to set the read position.
77 // * This should be called after CalculateSize and before Read. 78 // * This should be called after CalculateSize and before Read.
78 // * Range can only be set once. 79 // * Range can only be set once.
(...skipping 23 matching lines...) Expand all
102 // after CalculateSize, and is modified by SetReadRange. 103 // after CalculateSize, and is modified by SetReadRange.
103 uint64_t remaining_bytes() const { return remaining_bytes_; } 104 uint64_t remaining_bytes() const { return remaining_bytes_; }
104 105
105 // Returns the net error code if there was an error. Defaults to net::OK. 106 // Returns the net error code if there was an error. Defaults to net::OK.
106 int net_error() const { return net_error_; } 107 int net_error() const { return net_error_; }
107 108
108 // Returns the total size of the blob. This is populated after CalculateSize 109 // Returns the total size of the blob. This is populated after CalculateSize
109 // is called. 110 // is called.
110 uint64_t total_size() const { return total_size_; } 111 uint64_t total_size() const { return total_size_; }
111 112
113 // Returns if the reader has been used at all.
114 bool dirty() const { return dirty_; }
115
112 protected: 116 protected:
113 friend class BlobDataHandle; 117 friend class BlobDataHandle;
114 friend class BlobReaderTest; 118 friend class BlobReaderTest;
115 119
116 BlobReader(const BlobDataHandle* blob_handle, 120 BlobReader(const BlobDataHandle* blob_handle,
117 scoped_ptr<FileStreamReaderProvider> file_stream_provider, 121 scoped_ptr<FileStreamReaderProvider> file_stream_provider,
118 base::SequencedTaskRunner* file_task_runner); 122 base::SequencedTaskRunner* file_task_runner);
119 123
120 bool total_size_calculated() const { return total_size_calculated_; } 124 bool total_size_calculated() const { return total_size_calculated_; }
121 125
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 void SetFileReaderAtIndex(size_t index, scoped_ptr<FileStreamReader> reader); 160 void SetFileReaderAtIndex(size_t index, scoped_ptr<FileStreamReader> reader);
157 // Creates a FileStreamReader for the item with additional_offset. 161 // Creates a FileStreamReader for the item with additional_offset.
158 scoped_ptr<FileStreamReader> CreateFileStreamReader( 162 scoped_ptr<FileStreamReader> CreateFileStreamReader(
159 const BlobDataItem& item, 163 const BlobDataItem& item,
160 uint64_t additional_offset); 164 uint64_t additional_offset);
161 165
162 scoped_ptr<BlobDataSnapshot> blob_data_; 166 scoped_ptr<BlobDataSnapshot> blob_data_;
163 scoped_ptr<FileStreamReaderProvider> file_stream_provider_; 167 scoped_ptr<FileStreamReaderProvider> file_stream_provider_;
164 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; 168 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
165 169
166 int net_error_; 170 int net_error_ = net::OK;
167 bool item_list_populated_ = false;
168 std::vector<uint64_t> item_length_list_; 171 std::vector<uint64_t> item_length_list_;
169 172
170 scoped_refptr<net::DrainableIOBuffer> read_buf_; 173 scoped_refptr<net::DrainableIOBuffer> read_buf_;
171 174
172 bool total_size_calculated_ = false; 175 bool total_size_calculated_ = false;
173 uint64_t total_size_ = 0; 176 uint64_t total_size_ = 0;
174 uint64_t remaining_bytes_ = 0; 177 uint64_t remaining_bytes_ = 0;
175 size_t pending_get_file_info_count_ = 0; 178 size_t pending_get_file_info_count_ = 0;
176 std::map<size_t, FileStreamReader*> index_to_reader_; 179 std::map<size_t, scoped_ptr<FileStreamReader>> index_to_reader_;
177 size_t current_item_index_ = 0; 180 size_t current_item_index_ = 0;
178 uint64_t current_item_offset_ = 0; 181 uint64_t current_item_offset_ = 0;
179 182
183 bool dirty_ = false;
180 bool io_pending_ = false; 184 bool io_pending_ = false;
181 185
182 net::CompletionCallback size_callback_; 186 net::CompletionCallback size_callback_;
183 net::CompletionCallback read_callback_; 187 net::CompletionCallback read_callback_;
184 188
185 base::WeakPtrFactory<BlobReader> weak_factory_; 189 base::WeakPtrFactory<BlobReader> weak_factory_;
186 DISALLOW_COPY_AND_ASSIGN(BlobReader); 190 DISALLOW_COPY_AND_ASSIGN(BlobReader);
187 }; 191 };
188 192
189 } // namespace storage 193 } // namespace storage
190 #endif // STORAGE_BROWSER_BLOB_BLOB_READER_H_ 194 #endif // STORAGE_BROWSER_BLOB_BLOB_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698