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 #include "content/browser/download/download_file_impl.h" | 5 #include "content/browser/download/download_file_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 if (length_ == DownloadSaveInfo::kLengthFullContent || | 88 if (length_ == DownloadSaveInfo::kLengthFullContent || |
89 length_ > offset - offset_) { | 89 length_ > offset - offset_) { |
90 length_ = offset - offset_; | 90 length_ = offset - offset_; |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 DownloadFileImpl::DownloadFileImpl( | 94 DownloadFileImpl::DownloadFileImpl( |
95 std::unique_ptr<DownloadSaveInfo> save_info, | 95 std::unique_ptr<DownloadSaveInfo> save_info, |
96 const base::FilePath& default_download_directory, | 96 const base::FilePath& default_download_directory, |
97 std::unique_ptr<ByteStreamReader> stream_reader, | 97 std::unique_ptr<ByteStreamReader> stream_reader, |
98 const std::vector<DownloadItem::ReceivedSlice>& received_slices, | |
99 const net::NetLogWithSource& download_item_net_log, | 98 const net::NetLogWithSource& download_item_net_log, |
100 base::WeakPtr<DownloadDestinationObserver> observer) | 99 base::WeakPtr<DownloadDestinationObserver> observer) |
101 : net_log_( | 100 : net_log_( |
102 net::NetLogWithSource::Make(download_item_net_log.net_log(), | 101 net::NetLogWithSource::Make(download_item_net_log.net_log(), |
103 net::NetLogSourceType::DOWNLOAD_FILE)), | 102 net::NetLogSourceType::DOWNLOAD_FILE)), |
104 file_(net_log_), | 103 file_(net_log_), |
105 save_info_(std::move(save_info)), | 104 save_info_(std::move(save_info)), |
106 default_download_directory_(default_download_directory), | 105 default_download_directory_(default_download_directory), |
107 potential_file_length_(kUnknownContentLength), | 106 potential_file_length_(kUnknownContentLength), |
108 bytes_seen_(0), | 107 bytes_seen_(0), |
109 num_active_streams_(0), | 108 num_active_streams_(0), |
110 record_stream_bandwidth_(true), | 109 record_stream_bandwidth_(true), |
111 bytes_seen_with_parallel_streams_(0), | 110 bytes_seen_with_parallel_streams_(0), |
112 bytes_seen_without_parallel_streams_(0), | 111 bytes_seen_without_parallel_streams_(0), |
113 received_slices_(received_slices), | |
114 observer_(observer), | 112 observer_(observer), |
115 weak_factory_(this) { | 113 weak_factory_(this) { |
116 source_streams_[save_info_->offset] = base::MakeUnique<SourceStream>( | 114 source_streams_[save_info_->offset] = base::MakeUnique<SourceStream>( |
117 save_info_->offset, save_info_->length, std::move(stream_reader)); | 115 save_info_->offset, save_info_->length, std::move(stream_reader)); |
118 | 116 |
119 download_item_net_log.AddEvent( | 117 download_item_net_log.AddEvent( |
120 net::NetLogEventType::DOWNLOAD_FILE_CREATED, | 118 net::NetLogEventType::DOWNLOAD_FILE_CREATED, |
121 net_log_.source().ToEventParametersCallback()); | 119 net_log_.source().ToEventParametersCallback()); |
122 net_log_.BeginEvent( | 120 net_log_.BeginEvent( |
123 net::NetLogEventType::DOWNLOAD_FILE_ACTIVE, | 121 net::NetLogEventType::DOWNLOAD_FILE_ACTIVE, |
124 download_item_net_log.source().ToEventParametersCallback()); | 122 download_item_net_log.source().ToEventParametersCallback()); |
125 } | 123 } |
126 | 124 |
127 DownloadFileImpl::~DownloadFileImpl() { | 125 DownloadFileImpl::~DownloadFileImpl() { |
128 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 126 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
129 net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ACTIVE); | 127 net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ACTIVE); |
130 } | 128 } |
131 | 129 |
132 void DownloadFileImpl::Initialize(const InitializeCallback& callback) { | 130 void DownloadFileImpl::Initialize( |
| 131 const InitializeCallback& callback, |
| 132 const DownloadItem::ReceivedSlices& received_slices) { |
133 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 133 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
134 | 134 |
135 update_timer_.reset(new base::RepeatingTimer()); | 135 update_timer_.reset(new base::RepeatingTimer()); |
136 int64_t bytes_so_far = 0; | 136 int64_t bytes_so_far = 0; |
| 137 received_slices_ = received_slices; |
137 if (IsSparseFile()) { | 138 if (IsSparseFile()) { |
138 for (const auto& received_slice : received_slices_) { | 139 for (const auto& received_slice : received_slices_) { |
139 bytes_so_far += received_slice.received_bytes; | 140 bytes_so_far += received_slice.received_bytes; |
140 } | 141 } |
141 } else { | 142 } else { |
142 bytes_so_far = save_info_->offset; | 143 bytes_so_far = save_info_->offset; |
143 } | 144 } |
144 DownloadInterruptReason result = file_.Initialize( | 145 DownloadInterruptReason result = file_.Initialize( |
145 save_info_->file_path, default_download_directory_, | 146 save_info_->file_path, default_download_directory_, |
146 std::move(save_info_->file), bytes_so_far, | 147 std::move(save_info_->file), bytes_so_far, |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 const base::FilePath& new_path, | 698 const base::FilePath& new_path, |
698 const RenameCompletionCallback& completion_callback) | 699 const RenameCompletionCallback& completion_callback) |
699 : option(option), | 700 : option(option), |
700 new_path(new_path), | 701 new_path(new_path), |
701 retries_left(kMaxRenameRetries), | 702 retries_left(kMaxRenameRetries), |
702 completion_callback(completion_callback) {} | 703 completion_callback(completion_callback) {} |
703 | 704 |
704 DownloadFileImpl::RenameParameters::~RenameParameters() {} | 705 DownloadFileImpl::RenameParameters::~RenameParameters() {} |
705 | 706 |
706 } // namespace content | 707 } // namespace content |
OLD | NEW |