| 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, |
| 101 int64_t length, |
| 102 std::unique_ptr<ByteStreamReader> stream_reader); |
| 102 ~SourceStream(); | 103 ~SourceStream(); |
| 103 | 104 |
| 104 void SetByteStream(std::unique_ptr<ByteStreamReader> stream_reader); | |
| 105 | |
| 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 |
| 109 ByteStreamReader* stream_reader() const { return stream_reader_.get(); } | 108 ByteStreamReader* stream_reader() const { return stream_reader_.get(); } |
| 110 int64_t offset() const { return offset_; } | 109 int64_t offset() const { return offset_; } |
| 111 int64_t length() const { return length_; } | 110 int64_t length() const { return length_; } |
| 112 int64_t bytes_written() const { return bytes_written_; } | 111 int64_t bytes_written() const { return bytes_written_; } |
| 113 bool is_finished() const { return finished_; } | 112 bool is_finished() const { return finished_; } |
| 114 void set_finished(bool finish) { finished_ = finish; } | 113 void set_finished(bool finish) { finished_ = finish; } |
| 115 | 114 |
| (...skipping 80 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. | |
| 207 // Should not add or remove elements after creation. | |
| 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_; | 205 SourceStreams source_streams_; |
| 212 | 206 |
| 213 // Used to trigger progress updates. | 207 // Used to trigger progress updates. |
| 214 std::unique_ptr<base::RepeatingTimer> update_timer_; | 208 std::unique_ptr<base::RepeatingTimer> update_timer_; |
| 215 | 209 |
| 216 // Set to true when multiple byte streams write to the same file. | 210 // 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. | 211 // 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. | 212 // TODO(xingliu): Pass a slice info vector to determine if the file is sparse. |
| 219 bool is_sparse_file_; | 213 bool is_sparse_file_; |
| 220 | 214 |
| 221 // Statistics | 215 // Statistics |
| 222 size_t bytes_seen_; | 216 size_t bytes_seen_; |
| 223 base::TimeDelta disk_writes_time_; | 217 base::TimeDelta disk_writes_time_; |
| 224 base::TimeTicks download_start_; | 218 base::TimeTicks download_start_; |
| 225 RateEstimator rate_estimator_; | 219 RateEstimator rate_estimator_; |
| 226 | 220 |
| 227 std::vector<DownloadItem::ReceivedSlice> received_slices_; | 221 std::vector<DownloadItem::ReceivedSlice> received_slices_; |
| 228 | 222 |
| 229 base::WeakPtr<DownloadDestinationObserver> observer_; | 223 base::WeakPtr<DownloadDestinationObserver> observer_; |
| 230 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; | 224 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; |
| 231 | 225 |
| 232 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); | 226 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); |
| 233 }; | 227 }; |
| 234 | 228 |
| 235 } // namespace content | 229 } // namespace content |
| 236 | 230 |
| 237 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ | 231 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ |
| OLD | NEW |