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

Side by Side Diff: content/browser/download/download_file_impl.h

Issue 2737033002: Update the received slices vector when stream is written to disk (Closed)
Patch Set: fix unit test Created 3 years, 9 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 (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 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_
7 7
8 #include "content/browser/download/download_file.h" 8 #include "content/browser/download/download_file.h"
9 9
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 ~SourceStream(); 102 ~SourceStream();
103 103
104 void SetByteStream(std::unique_ptr<ByteStreamReader> stream_reader); 104 void SetByteStream(std::unique_ptr<ByteStreamReader> stream_reader);
105 105
106 // Called after successfully writing a buffer to disk. 106 // Called after successfully writing a buffer to disk.
107 void OnWriteBytesToDisk(int64_t bytes_write); 107 void OnWriteBytesToDisk(int64_t bytes_write);
108 108
109 ByteStreamReader* stream_reader() const { return stream_reader_.get(); } 109 ByteStreamReader* stream_reader() const { return stream_reader_.get(); }
110 int64_t offset() const { return offset_; } 110 int64_t offset() const { return offset_; }
111 int64_t length() const { return length_; } 111 int64_t length() const { return length_; }
112 void set_length(int64_t length) { length_ = length; }
112 int64_t bytes_written() const { return bytes_written_; } 113 int64_t bytes_written() const { return bytes_written_; }
113 bool is_finished() const { return finished_; } 114 bool is_finished() const { return finished_; }
114 void set_finished(bool finish) { finished_ = finish; } 115 void set_finished(bool finish) { finished_ = finish; }
116 size_t index() { return index_; }
117 void set_index(size_t index) { index_ = index; }
115 118
116 private: 119 private:
117 // Starting position for the stream to write to disk. 120 // Starting position for the stream to write to disk.
118 int64_t offset_; 121 int64_t offset_;
119 122
120 // The maximum length to write to the disk. If set to 0, keep writing until 123 // The maximum length to write to the disk. If set to 0, keep writing until
121 // the stream depletes. 124 // the stream depletes.
122 int64_t length_; 125 int64_t length_;
123 126
124 // Number of bytes written to disk from the stream. 127 // Number of bytes written to disk from the stream.
125 // Next write position is (|offset_| + |bytes_written_|). 128 // Next write position is (|offset_| + |bytes_written_|).
126 int64_t bytes_written_; 129 int64_t bytes_written_;
127 130
128 // If all the data read from the stream has been successfully written to 131 // If all the data read from the stream has been successfully written to
129 // disk. 132 // disk.
130 bool finished_; 133 bool finished_;
131 134
135 // The slice index in the |received_slices_| vector. A slice was created
136 // once the stream started writing data to the target file.
137 size_t index_;
138
132 // The stream through which data comes. 139 // The stream through which data comes.
133 std::unique_ptr<ByteStreamReader> stream_reader_; 140 std::unique_ptr<ByteStreamReader> stream_reader_;
134 141
135 DISALLOW_COPY_AND_ASSIGN(SourceStream); 142 DISALLOW_COPY_AND_ASSIGN(SourceStream);
136 }; 143 };
137 144
138 typedef std::unordered_map<int64_t, std::unique_ptr<SourceStream>> 145 typedef std::unordered_map<int64_t, std::unique_ptr<SourceStream>>
139 SourceStreams; 146 SourceStreams;
140 147
141 // Options for RenameWithRetryInternal. 148 // Options for RenameWithRetryInternal.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // Called before the data is written to disk. 183 // Called before the data is written to disk.
177 void WillWriteToDisk(size_t data_len); 184 void WillWriteToDisk(size_t data_len);
178 185
179 // Called when there's some activity on the byte stream that needs to be 186 // Called when there's some activity on the byte stream that needs to be
180 // handled. 187 // handled.
181 void StreamActive(SourceStream* source_stream); 188 void StreamActive(SourceStream* source_stream);
182 189
183 // Register callback and start to read data from the stream. 190 // Register callback and start to read data from the stream.
184 void RegisterAndActivateStream(SourceStream* source_stream); 191 void RegisterAndActivateStream(SourceStream* source_stream);
185 192
193 // Adds a new slice to |received_slices_| and update the existing entries in
194 // |source_streams_| as their lengths will change.
195 // TODO(qinmin): add a test for this function.
196 void AddNewSlice(int64_t offset, int64_t length);
197
186 // Return the total valid bytes received in the target file. 198 // Return the total valid bytes received in the target file.
187 // If the file is a sparse file, return the total number of valid bytes. 199 // If the file is a sparse file, return the total number of valid bytes.
188 // Otherwise, return the current file size. 200 // Otherwise, return the current file size.
189 int64_t TotalBytesReceived() const; 201 int64_t TotalBytesReceived() const;
190 202
191 net::NetLogWithSource net_log_; 203 net::NetLogWithSource net_log_;
192 204
193 // The base file instance. 205 // The base file instance.
194 BaseFile file_; 206 BaseFile file_;
195 207
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 240
229 base::WeakPtr<DownloadDestinationObserver> observer_; 241 base::WeakPtr<DownloadDestinationObserver> observer_;
230 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; 242 base::WeakPtrFactory<DownloadFileImpl> weak_factory_;
231 243
232 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); 244 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl);
233 }; 245 };
234 246
235 } // namespace content 247 } // namespace content
236 248
237 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ 249 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/download_file_impl.cc » ('j') | content/browser/download/download_file_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698