Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 const net::NetLogWithSource& net_log, | 51 const net::NetLogWithSource& net_log, |
| 52 bool is_sparse_file, | 52 bool is_sparse_file, |
| 53 base::WeakPtr<DownloadDestinationObserver> observer); | 53 base::WeakPtr<DownloadDestinationObserver> observer); |
| 54 | 54 |
| 55 ~DownloadFileImpl() override; | 55 ~DownloadFileImpl() override; |
| 56 | 56 |
| 57 // DownloadFile functions. | 57 // DownloadFile functions. |
| 58 void Initialize(const InitializeCallback& callback) override; | 58 void Initialize(const InitializeCallback& callback) override; |
| 59 | 59 |
| 60 void AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, | 60 void AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, |
| 61 int64_t offset) override; | 61 int64_t offset, |
| 62 int64_t length) override; | |
| 62 | 63 |
| 63 void RenameAndUniquify(const base::FilePath& full_path, | 64 void RenameAndUniquify(const base::FilePath& full_path, |
| 64 const RenameCompletionCallback& callback) override; | 65 const RenameCompletionCallback& callback) override; |
| 65 void RenameAndAnnotate(const base::FilePath& full_path, | 66 void RenameAndAnnotate(const base::FilePath& full_path, |
| 66 const std::string& client_guid, | 67 const std::string& client_guid, |
| 67 const GURL& source_url, | 68 const GURL& source_url, |
| 68 const GURL& referrer_url, | 69 const GURL& referrer_url, |
| 69 const RenameCompletionCallback& callback) override; | 70 const RenameCompletionCallback& callback) override; |
| 70 void Detach() override; | 71 void Detach() override; |
| 71 void Cancel() override; | 72 void Cancel() override; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 87 private: | 88 private: |
| 88 friend class DownloadFileTest; | 89 friend class DownloadFileTest; |
| 89 | 90 |
| 90 // Wrapper of a ByteStreamReader, and the meta data needed to write to a | 91 // Wrapper of a ByteStreamReader, and the meta data needed to write to a |
| 91 // slice of the target file. | 92 // slice of the target file. |
| 92 // | 93 // |
| 93 // Does not require the stream reader ready when constructor is called. | 94 // Does not require the stream reader ready when constructor is called. |
| 94 // |stream_reader_| can be set later when the network response is handled. | 95 // |stream_reader_| can be set later when the network response is handled. |
| 95 // | 96 // |
| 96 // Multiple SourceStreams can concurrently write to the same file sink. | 97 // Multiple SourceStreams can concurrently write to the same file sink. |
| 97 // | |
| 98 // The file IO processing is finished when all SourceStreams are finished. | |
| 99 class CONTENT_EXPORT SourceStream { | 98 class CONTENT_EXPORT SourceStream { |
| 100 public: | 99 public: |
| 101 SourceStream(int64_t offset, int64_t length); | 100 SourceStream(int64_t offset, int64_t length); |
| 102 ~SourceStream(); | 101 ~SourceStream(); |
| 103 | 102 |
| 104 void SetByteStream(std::unique_ptr<ByteStreamReader> stream_reader); | 103 void SetByteStream(std::unique_ptr<ByteStreamReader> stream_reader); |
| 105 | 104 |
| 106 // Called after successfully writing a buffer to disk. | 105 // Called after successfully writing a buffer to disk. |
| 107 void OnWriteBytesToDisk(int64_t bytes_write); | 106 void OnWriteBytesToDisk(int64_t bytes_write); |
| 108 | 107 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 // DownloadSaveInfo provided during construction. Since the DownloadFileImpl | 195 // DownloadSaveInfo provided during construction. Since the DownloadFileImpl |
| 197 // can be created on any thread, this holds the save_info_ until it can be | 196 // can be created on any thread, this holds the save_info_ until it can be |
| 198 // used to initialize file_ on the FILE thread. | 197 // used to initialize file_ on the FILE thread. |
| 199 std::unique_ptr<DownloadSaveInfo> save_info_; | 198 std::unique_ptr<DownloadSaveInfo> save_info_; |
| 200 | 199 |
| 201 // The default directory for creating the download file. | 200 // The default directory for creating the download file. |
| 202 base::FilePath default_download_directory_; | 201 base::FilePath default_download_directory_; |
| 203 | 202 |
| 204 // Map of the offset and the source stream that represents the slice | 203 // Map of the offset and the source stream that represents the slice |
| 205 // starting from offset. | 204 // starting from offset. |
| 206 // Must be created on the same thread that constructs the DownloadFile. | 205 // Can be modified in constructor on any thread, later must be accessed on |
| 207 // Should not add or remove elements after creation. | 206 // file thread. |
|
asanka
2017/03/14 19:44:01
Doesn't need to be restated here. The thread restr
xingliu
2017/03/14 22:48:29
Done.
| |
| 208 // Any byte stream should have a SourceStream before added to the download | |
| 209 // file. | |
| 210 // The disk IO is completed when all source streams are finished. | |
| 211 SourceStreams source_streams_; | 207 SourceStreams source_streams_; |
| 212 | 208 |
| 213 // Used to trigger progress updates. | 209 // Used to trigger progress updates. |
| 214 std::unique_ptr<base::RepeatingTimer> update_timer_; | 210 std::unique_ptr<base::RepeatingTimer> update_timer_; |
| 215 | 211 |
| 216 // Set to true when multiple byte streams write to the same file. | 212 // Set to true when multiple byte streams write to the same file. |
| 217 // The file may contain null bytes(holes) in between of valid data slices. | 213 // The file may contain null bytes(holes) in between of valid data slices. |
| 218 // TODO(xingliu): Pass a slice info vector to determine if the file is sparse. | 214 // TODO(xingliu): Pass a slice info vector to determine if the file is sparse. |
| 219 bool is_sparse_file_; | 215 bool is_sparse_file_; |
| 220 | 216 |
| 221 // Statistics | 217 // Statistics |
| 222 size_t bytes_seen_; | 218 size_t bytes_seen_; |
| 223 base::TimeDelta disk_writes_time_; | 219 base::TimeDelta disk_writes_time_; |
| 224 base::TimeTicks download_start_; | 220 base::TimeTicks download_start_; |
| 225 RateEstimator rate_estimator_; | 221 RateEstimator rate_estimator_; |
| 226 | 222 |
| 227 std::vector<DownloadItem::ReceivedSlice> received_slices_; | 223 std::vector<DownloadItem::ReceivedSlice> received_slices_; |
| 228 | 224 |
| 229 base::WeakPtr<DownloadDestinationObserver> observer_; | 225 base::WeakPtr<DownloadDestinationObserver> observer_; |
| 230 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; | 226 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; |
| 231 | 227 |
| 232 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); | 228 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); |
| 233 }; | 229 }; |
| 234 | 230 |
| 235 } // namespace content | 231 } // namespace content |
| 236 | 232 |
| 237 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ | 233 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ |
| OLD | NEW |