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

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

Issue 2782033002: remove is_sparse_file_ from DownloadFileImpl (Closed)
Patch Set: add IsSparseFile() helper method Created 3 years, 8 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // 42 //
43 // Note that the DownloadFileImpl automatically reads from the passed in 43 // Note that the DownloadFileImpl automatically reads from the passed in
44 // stream, and sends updates and status of those reads to the 44 // stream, and sends updates and status of those reads to the
45 // DownloadDestinationObserver. 45 // DownloadDestinationObserver.
46 DownloadFileImpl( 46 DownloadFileImpl(
47 std::unique_ptr<DownloadSaveInfo> save_info, 47 std::unique_ptr<DownloadSaveInfo> save_info,
48 const base::FilePath& default_downloads_directory, 48 const base::FilePath& default_downloads_directory,
49 std::unique_ptr<ByteStreamReader> stream_reader, 49 std::unique_ptr<ByteStreamReader> stream_reader,
50 const std::vector<DownloadItem::ReceivedSlice>& received_slices, 50 const std::vector<DownloadItem::ReceivedSlice>& received_slices,
51 const net::NetLogWithSource& net_log, 51 const net::NetLogWithSource& net_log,
52 bool is_sparse_file,
53 base::WeakPtr<DownloadDestinationObserver> observer); 52 base::WeakPtr<DownloadDestinationObserver> observer);
54 53
55 ~DownloadFileImpl() override; 54 ~DownloadFileImpl() override;
56 55
57 // DownloadFile functions. 56 // DownloadFile functions.
58 void Initialize(const InitializeCallback& callback) override; 57 void Initialize(const InitializeCallback& callback) override;
59 58
60 void AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, 59 void AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader,
61 int64_t offset, 60 int64_t offset,
62 int64_t length) override; 61 int64_t length) override;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 214
216 // Return the total valid bytes received in the target file. 215 // Return the total valid bytes received in the target file.
217 // If the file is a sparse file, return the total number of valid bytes. 216 // If the file is a sparse file, return the total number of valid bytes.
218 // Otherwise, return the current file size. 217 // Otherwise, return the current file size.
219 int64_t TotalBytesReceived() const; 218 int64_t TotalBytesReceived() const;
220 219
221 // Helper method to handle stream error 220 // Helper method to handle stream error
222 void HandleStreamError(SourceStream* source_stream, 221 void HandleStreamError(SourceStream* source_stream,
223 DownloadInterruptReason reason); 222 DownloadInterruptReason reason);
224 223
224 // Check whether this file is potentially sparse.
225 bool IsSparseFile() const;
226
225 // Given a SourceStream object, returns its neighbor that preceds it if 227 // Given a SourceStream object, returns its neighbor that preceds it if
226 // SourceStreams are ordered by their offsets 228 // SourceStreams are ordered by their offsets
227 SourceStream* FindPrecedingNeighbor(SourceStream* source_stream); 229 SourceStream* FindPrecedingNeighbor(SourceStream* source_stream);
228 230
229 // Print the internal states for debugging. 231 // Print the internal states for debugging.
230 void DebugStates() const; 232 void DebugStates() const;
231 233
232 net::NetLogWithSource net_log_; 234 net::NetLogWithSource net_log_;
233 235
234 // The base file instance. 236 // The base file instance.
235 BaseFile file_; 237 BaseFile file_;
236 238
237 // DownloadSaveInfo provided during construction. Since the DownloadFileImpl 239 // DownloadSaveInfo provided during construction. Since the DownloadFileImpl
238 // can be created on any thread, this holds the save_info_ until it can be 240 // can be created on any thread, this holds the save_info_ until it can be
239 // used to initialize file_ on the FILE thread. 241 // used to initialize file_ on the FILE thread.
240 std::unique_ptr<DownloadSaveInfo> save_info_; 242 std::unique_ptr<DownloadSaveInfo> save_info_;
241 243
242 // The default directory for creating the download file. 244 // The default directory for creating the download file.
243 base::FilePath default_download_directory_; 245 base::FilePath default_download_directory_;
244 246
245 // Map of the offset and the source stream that represents the slice 247 // Map of the offset and the source stream that represents the slice
246 // starting from offset. 248 // starting from offset.
247 SourceStreams source_streams_; 249 SourceStreams source_streams_;
248 250
249 // Used to trigger progress updates. 251 // Used to trigger progress updates.
250 std::unique_ptr<base::RepeatingTimer> update_timer_; 252 std::unique_ptr<base::RepeatingTimer> update_timer_;
251 253
252 // Set to true when multiple byte streams write to the same file.
253 // The file may contain null bytes(holes) in between of valid data slices.
254 // TODO(xingliu): Remove this variable. We can use size of |received_slices_|
255 // to determine if the file is sparse
256 bool is_sparse_file_;
257
258 // Statistics 254 // Statistics
259 size_t bytes_seen_; 255 size_t bytes_seen_;
260 base::TimeDelta disk_writes_time_; 256 base::TimeDelta disk_writes_time_;
261 base::TimeTicks download_start_; 257 base::TimeTicks download_start_;
262 RateEstimator rate_estimator_; 258 RateEstimator rate_estimator_;
263 int num_active_streams_; 259 int num_active_streams_;
264 bool record_stream_bandwidth_; 260 bool record_stream_bandwidth_;
265 base::TimeTicks last_update_time_; 261 base::TimeTicks last_update_time_;
266 size_t bytes_seen_with_parallel_streams_; 262 size_t bytes_seen_with_parallel_streams_;
267 size_t bytes_seen_without_parallel_streams_; 263 size_t bytes_seen_without_parallel_streams_;
268 base::TimeDelta download_time_with_parallel_streams_; 264 base::TimeDelta download_time_with_parallel_streams_;
269 base::TimeDelta download_time_without_parallel_streams_; 265 base::TimeDelta download_time_without_parallel_streams_;
270 266
271 std::vector<DownloadItem::ReceivedSlice> received_slices_; 267 std::vector<DownloadItem::ReceivedSlice> received_slices_;
272 268
273 base::WeakPtr<DownloadDestinationObserver> observer_; 269 base::WeakPtr<DownloadDestinationObserver> observer_;
274 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; 270 base::WeakPtrFactory<DownloadFileImpl> weak_factory_;
275 271
276 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); 272 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl);
277 }; 273 };
278 274
279 } // namespace content 275 } // namespace content
280 276
281 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ 277 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698