| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 DownloadFileImpl::~DownloadFileImpl() { | 67 DownloadFileImpl::~DownloadFileImpl() { |
| 68 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 68 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 69 net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ACTIVE); | 69 net_log_.EndEvent(net::NetLogEventType::DOWNLOAD_FILE_ACTIVE); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void DownloadFileImpl::Initialize(const InitializeCallback& callback) { | 72 void DownloadFileImpl::Initialize(const InitializeCallback& callback) { |
| 73 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 73 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 74 | 74 |
| 75 update_timer_.reset(new base::RepeatingTimer()); | 75 update_timer_.reset(new base::RepeatingTimer()); |
| 76 DownloadInterruptReason result = | 76 DownloadInterruptReason result = |
| 77 file_.Initialize(save_info_->file_path, | 77 file_.Initialize(save_info_->file_path, default_download_directory_, |
| 78 default_download_directory_, | 78 std::move(save_info_->file), save_info_->offset, |
| 79 std::move(save_info_->file), | |
| 80 save_info_->offset, | |
| 81 save_info_->hash_of_partial_file, | 79 save_info_->hash_of_partial_file, |
| 82 std::move(save_info_->hash_state)); | 80 std::move(save_info_->hash_state), BaseFile::EXCLUSIVE); |
| 83 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { | 81 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 84 BrowserThread::PostTask( | 82 BrowserThread::PostTask( |
| 85 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); | 83 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); |
| 86 return; | 84 return; |
| 87 } | 85 } |
| 88 | 86 |
| 89 stream_reader_->RegisterCallback( | 87 stream_reader_->RegisterCallback( |
| 90 base::Bind(&DownloadFileImpl::StreamActive, weak_factory_.GetWeakPtr())); | 88 base::Bind(&DownloadFileImpl::StreamActive, weak_factory_.GetWeakPtr())); |
| 91 | 89 |
| 92 download_start_ = base::TimeTicks::Now(); | 90 download_start_ = base::TimeTicks::Now(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 105 DownloadInterruptReason DownloadFileImpl::AppendDataToFile( | 103 DownloadInterruptReason DownloadFileImpl::AppendDataToFile( |
| 106 const char* data, size_t data_len) { | 104 const char* data, size_t data_len) { |
| 107 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 105 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 108 | 106 |
| 109 if (!update_timer_->IsRunning()) { | 107 if (!update_timer_->IsRunning()) { |
| 110 update_timer_->Start(FROM_HERE, | 108 update_timer_->Start(FROM_HERE, |
| 111 base::TimeDelta::FromMilliseconds(kUpdatePeriodMs), | 109 base::TimeDelta::FromMilliseconds(kUpdatePeriodMs), |
| 112 this, &DownloadFileImpl::SendUpdate); | 110 this, &DownloadFileImpl::SendUpdate); |
| 113 } | 111 } |
| 114 rate_estimator_.Increment(data_len); | 112 rate_estimator_.Increment(data_len); |
| 115 return file_.AppendDataToFile(data, data_len); | 113 return file_.WriteDataToFile(data, data_len); |
| 116 } | 114 } |
| 117 | 115 |
| 118 void DownloadFileImpl::RenameAndUniquify( | 116 void DownloadFileImpl::RenameAndUniquify( |
| 119 const base::FilePath& full_path, | 117 const base::FilePath& full_path, |
| 120 const RenameCompletionCallback& callback) { | 118 const RenameCompletionCallback& callback) { |
| 121 std::unique_ptr<RenameParameters> parameters( | 119 std::unique_ptr<RenameParameters> parameters( |
| 122 new RenameParameters(UNIQUIFY, full_path, callback)); | 120 new RenameParameters(UNIQUIFY, full_path, callback)); |
| 123 RenameWithRetryInternal(std::move(parameters)); | 121 RenameWithRetryInternal(std::move(parameters)); |
| 124 } | 122 } |
| 125 | 123 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 const base::FilePath& new_path, | 356 const base::FilePath& new_path, |
| 359 const RenameCompletionCallback& completion_callback) | 357 const RenameCompletionCallback& completion_callback) |
| 360 : option(option), | 358 : option(option), |
| 361 new_path(new_path), | 359 new_path(new_path), |
| 362 retries_left(kMaxRenameRetries), | 360 retries_left(kMaxRenameRetries), |
| 363 completion_callback(completion_callback) {} | 361 completion_callback(completion_callback) {} |
| 364 | 362 |
| 365 DownloadFileImpl::RenameParameters::~RenameParameters() {} | 363 DownloadFileImpl::RenameParameters::~RenameParameters() {} |
| 366 | 364 |
| 367 } // namespace content | 365 } // namespace content |
| OLD | NEW |