| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 net::NetLogWithSource& net_log, | 50 const net::NetLogWithSource& net_log, |
| 51 base::WeakPtr<DownloadDestinationObserver> observer); | 51 base::WeakPtr<DownloadDestinationObserver> observer); |
| 52 | 52 |
| 53 ~DownloadFileImpl() override; | 53 ~DownloadFileImpl() override; |
| 54 | 54 |
| 55 // DownloadFile functions. | 55 // DownloadFile functions. |
| 56 void Initialize(const InitializeCallback& callback, | 56 void Initialize(const InitializeCallback& initialize_callback, |
| 57 const CancelRequestCallback& cancel_request_callback, |
| 57 const DownloadItem::ReceivedSlices& received_slices) override; | 58 const DownloadItem::ReceivedSlices& received_slices) override; |
| 58 | 59 |
| 59 void AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, | 60 void AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, |
| 60 int64_t offset, | 61 int64_t offset, |
| 61 int64_t length) override; | 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, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 void OnWriteBytesToDisk(int64_t bytes_write); | 108 void OnWriteBytesToDisk(int64_t bytes_write); |
| 108 | 109 |
| 109 // Given a data block that is already written, truncate the length of this | 110 // Given a data block that is already written, truncate the length of this |
| 110 // object to avoid overwriting that block. | 111 // object to avoid overwriting that block. |
| 111 void TruncateLengthWithWrittenDataBlock(int64_t offset, | 112 void TruncateLengthWithWrittenDataBlock(int64_t offset, |
| 112 int64_t bytes_written); | 113 int64_t bytes_written); |
| 113 | 114 |
| 114 ByteStreamReader* stream_reader() const { return stream_reader_.get(); } | 115 ByteStreamReader* stream_reader() const { return stream_reader_.get(); } |
| 115 int64_t offset() const { return offset_; } | 116 int64_t offset() const { return offset_; } |
| 116 int64_t length() const { return length_; } | 117 int64_t length() const { return length_; } |
| 117 void set_length(int64_t length) { length_ = length; } | |
| 118 int64_t bytes_written() const { return bytes_written_; } | 118 int64_t bytes_written() const { return bytes_written_; } |
| 119 bool is_finished() const { return finished_; } | 119 bool is_finished() const { return finished_; } |
| 120 void set_finished(bool finish) { finished_ = finish; } | 120 void set_finished(bool finish) { finished_ = finish; } |
| 121 size_t index() { return index_; } | 121 size_t index() { return index_; } |
| 122 void set_index(size_t index) { index_ = index; } | 122 void set_index(size_t index) { index_ = index; } |
| 123 | 123 |
| 124 private: | 124 private: |
| 125 // Starting position for the stream to write to disk. | 125 // Starting position for the stream to write to disk. |
| 126 int64_t offset_; | 126 int64_t offset_; |
| 127 | 127 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 void HandleStreamError(SourceStream* source_stream, | 222 void HandleStreamError(SourceStream* source_stream, |
| 223 DownloadInterruptReason reason); | 223 DownloadInterruptReason reason); |
| 224 | 224 |
| 225 // Check whether this file is potentially sparse. | 225 // Check whether this file is potentially sparse. |
| 226 bool IsSparseFile() const; | 226 bool IsSparseFile() const; |
| 227 | 227 |
| 228 // Given a SourceStream object, returns its neighbor that preceds it if | 228 // Given a SourceStream object, returns its neighbor that preceds it if |
| 229 // SourceStreams are ordered by their offsets | 229 // SourceStreams are ordered by their offsets |
| 230 SourceStream* FindPrecedingNeighbor(SourceStream* source_stream); | 230 SourceStream* FindPrecedingNeighbor(SourceStream* source_stream); |
| 231 | 231 |
| 232 // See |cancel_request_callback_|. |
| 233 void CancelRequestOnUIThread(int64_t offset); |
| 234 |
| 232 // Print the internal states for debugging. | 235 // Print the internal states for debugging. |
| 233 void DebugStates() const; | 236 void DebugStates() const; |
| 234 | 237 |
| 235 net::NetLogWithSource net_log_; | 238 net::NetLogWithSource net_log_; |
| 236 | 239 |
| 237 // The base file instance. | 240 // The base file instance. |
| 238 BaseFile file_; | 241 BaseFile file_; |
| 239 | 242 |
| 240 // DownloadSaveInfo provided during construction. Since the DownloadFileImpl | 243 // DownloadSaveInfo provided during construction. Since the DownloadFileImpl |
| 241 // can be created on any thread, this holds the save_info_ until it can be | 244 // can be created on any thread, this holds the save_info_ until it can be |
| 242 // used to initialize file_ on the FILE thread. | 245 // used to initialize file_ on the FILE thread. |
| 243 std::unique_ptr<DownloadSaveInfo> save_info_; | 246 std::unique_ptr<DownloadSaveInfo> save_info_; |
| 244 | 247 |
| 245 // The default directory for creating the download file. | 248 // The default directory for creating the download file. |
| 246 base::FilePath default_download_directory_; | 249 base::FilePath default_download_directory_; |
| 247 | 250 |
| 248 // Map of the offset and the source stream that represents the slice | 251 // Map of the offset and the source stream that represents the slice |
| 249 // starting from offset. | 252 // starting from offset. |
| 250 SourceStreams source_streams_; | 253 SourceStreams source_streams_; |
| 251 | 254 |
| 255 // Used to cancel the request on UI thread, since the ByteStreamReader can't |
| 256 // close the underlying resource writing to the pipe. |
| 257 CancelRequestCallback cancel_request_callback_; |
| 258 |
| 252 // Used to trigger progress updates. | 259 // Used to trigger progress updates. |
| 253 std::unique_ptr<base::RepeatingTimer> update_timer_; | 260 std::unique_ptr<base::RepeatingTimer> update_timer_; |
| 254 | 261 |
| 255 // Potential file length. A range request with an offset larger than this | 262 // Potential file length. A range request with an offset larger than this |
| 256 // value will fail. So the actual file length cannot be larger than this. | 263 // value will fail. So the actual file length cannot be larger than this. |
| 257 int64_t potential_file_length_; | 264 int64_t potential_file_length_; |
| 258 | 265 |
| 259 // Statistics | 266 // Statistics |
| 260 size_t bytes_seen_; | 267 size_t bytes_seen_; |
| 261 base::TimeDelta disk_writes_time_; | 268 base::TimeDelta disk_writes_time_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 273 | 280 |
| 274 base::WeakPtr<DownloadDestinationObserver> observer_; | 281 base::WeakPtr<DownloadDestinationObserver> observer_; |
| 275 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; | 282 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; |
| 276 | 283 |
| 277 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); | 284 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); |
| 278 }; | 285 }; |
| 279 | 286 |
| 280 } // namespace content | 287 } // namespace content |
| 281 | 288 |
| 282 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ | 289 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ |
| OLD | NEW |