| 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> |
| 11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <unordered_map> | 15 #include <unordered_map> |
| 16 #include <vector> |
| 16 | 17 |
| 17 #include "base/files/file.h" | 18 #include "base/files/file.h" |
| 18 #include "base/macros.h" | 19 #include "base/macros.h" |
| 19 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
| 21 #include "base/threading/thread_checker.h" | 22 #include "base/threading/thread_checker.h" |
| 22 #include "base/time/time.h" | 23 #include "base/time/time.h" |
| 23 #include "base/timer/timer.h" | 24 #include "base/timer/timer.h" |
| 24 #include "content/browser/byte_stream.h" | 25 #include "content/browser/byte_stream.h" |
| 25 #include "content/browser/download/base_file.h" | 26 #include "content/browser/download/base_file.h" |
| 26 #include "content/browser/download/rate_estimator.h" | 27 #include "content/browser/download/rate_estimator.h" |
| 28 #include "content/public/browser/download_item.h" |
| 27 #include "content/public/browser/download_save_info.h" | 29 #include "content/public/browser/download_save_info.h" |
| 28 #include "net/log/net_log_with_source.h" | 30 #include "net/log/net_log_with_source.h" |
| 29 | 31 |
| 30 namespace content { | 32 namespace content { |
| 31 class ByteStreamReader; | 33 class ByteStreamReader; |
| 32 class DownloadDestinationObserver; | 34 class DownloadDestinationObserver; |
| 33 | 35 |
| 34 class CONTENT_EXPORT DownloadFileImpl : public DownloadFile { | 36 class CONTENT_EXPORT DownloadFileImpl : public DownloadFile { |
| 35 public: | 37 public: |
| 36 // Takes ownership of the object pointed to by |request_handle|. | 38 // Takes ownership of the object pointed to by |request_handle|. |
| 37 // |net_log| will be used for logging the download file's events. | 39 // |net_log| will be used for logging the download file's events. |
| 38 // May be constructed on any thread. All methods besides the constructor | 40 // May be constructed on any thread. All methods besides the constructor |
| 39 // (including destruction) must occur on the FILE thread. | 41 // (including destruction) must occur on the FILE thread. |
| 40 // | 42 // |
| 41 // Note that the DownloadFileImpl automatically reads from the passed in | 43 // Note that the DownloadFileImpl automatically reads from the passed in |
| 42 // stream, and sends updates and status of those reads to the | 44 // stream, and sends updates and status of those reads to the |
| 43 // DownloadDestinationObserver. | 45 // DownloadDestinationObserver. |
| 44 DownloadFileImpl(std::unique_ptr<DownloadSaveInfo> save_info, | 46 DownloadFileImpl( |
| 45 const base::FilePath& default_downloads_directory, | 47 std::unique_ptr<DownloadSaveInfo> save_info, |
| 46 std::unique_ptr<ByteStreamReader> stream_reader, | 48 const base::FilePath& default_downloads_directory, |
| 47 const net::NetLogWithSource& net_log, | 49 std::unique_ptr<ByteStreamReader> stream_reader, |
| 48 bool is_sparse_file, | 50 const std::vector<DownloadItem::ReceivedSlice>& received_slices, |
| 49 base::WeakPtr<DownloadDestinationObserver> observer); | 51 const net::NetLogWithSource& net_log, |
| 52 bool is_sparse_file, |
| 53 base::WeakPtr<DownloadDestinationObserver> observer); |
| 50 | 54 |
| 51 ~DownloadFileImpl() override; | 55 ~DownloadFileImpl() override; |
| 52 | 56 |
| 53 // DownloadFile functions. | 57 // DownloadFile functions. |
| 54 void Initialize(const InitializeCallback& callback) override; | 58 void Initialize(const InitializeCallback& callback) override; |
| 55 | 59 |
| 56 void AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, | 60 void AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, |
| 57 int64_t offset) override; | 61 int64_t offset) override; |
| 58 | 62 |
| 59 void RenameAndUniquify(const base::FilePath& full_path, | 63 void RenameAndUniquify(const base::FilePath& full_path, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // The file may contain null bytes(holes) in between of valid data slices. | 217 // The file may contain null bytes(holes) in between of valid data slices. |
| 214 // TODO(xingliu): Pass a slice info vector to determine if the file is sparse. | 218 // TODO(xingliu): Pass a slice info vector to determine if the file is sparse. |
| 215 bool is_sparse_file_; | 219 bool is_sparse_file_; |
| 216 | 220 |
| 217 // Statistics | 221 // Statistics |
| 218 size_t bytes_seen_; | 222 size_t bytes_seen_; |
| 219 base::TimeDelta disk_writes_time_; | 223 base::TimeDelta disk_writes_time_; |
| 220 base::TimeTicks download_start_; | 224 base::TimeTicks download_start_; |
| 221 RateEstimator rate_estimator_; | 225 RateEstimator rate_estimator_; |
| 222 | 226 |
| 227 std::vector<DownloadItem::ReceivedSlice> received_slices_; |
| 228 |
| 223 base::WeakPtr<DownloadDestinationObserver> observer_; | 229 base::WeakPtr<DownloadDestinationObserver> observer_; |
| 224 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; | 230 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; |
| 225 | 231 |
| 226 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); | 232 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); |
| 227 }; | 233 }; |
| 228 | 234 |
| 229 } // namespace content | 235 } // namespace content |
| 230 | 236 |
| 231 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ | 237 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ |
| OLD | NEW |