| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 bound_net_log), | 52 bound_net_log), |
| 53 default_download_directory_(default_download_directory), | 53 default_download_directory_(default_download_directory), |
| 54 stream_reader_(stream.Pass()), | 54 stream_reader_(stream.Pass()), |
| 55 bytes_seen_(0), | 55 bytes_seen_(0), |
| 56 bound_net_log_(bound_net_log), | 56 bound_net_log_(bound_net_log), |
| 57 observer_(observer), | 57 observer_(observer), |
| 58 weak_factory_(this) { | 58 weak_factory_(this) { |
| 59 } | 59 } |
| 60 | 60 |
| 61 DownloadFileImpl::~DownloadFileImpl() { | 61 DownloadFileImpl::~DownloadFileImpl() { |
| 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 62 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 63 --number_active_objects_; | 63 --number_active_objects_; |
| 64 } | 64 } |
| 65 | 65 |
| 66 void DownloadFileImpl::Initialize(const InitializeCallback& callback) { | 66 void DownloadFileImpl::Initialize(const InitializeCallback& callback) { |
| 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 67 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 68 | 68 |
| 69 update_timer_.reset(new base::RepeatingTimer<DownloadFileImpl>()); | 69 update_timer_.reset(new base::RepeatingTimer<DownloadFileImpl>()); |
| 70 DownloadInterruptReason result = | 70 DownloadInterruptReason result = |
| 71 file_.Initialize(default_download_directory_); | 71 file_.Initialize(default_download_directory_); |
| 72 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { | 72 if (result != DOWNLOAD_INTERRUPT_REASON_NONE) { |
| 73 BrowserThread::PostTask( | 73 BrowserThread::PostTask( |
| 74 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); | 74 BrowserThread::UI, FROM_HERE, base::Bind(callback, result)); |
| 75 return; | 75 return; |
| 76 } | 76 } |
| 77 | 77 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 88 | 88 |
| 89 BrowserThread::PostTask( | 89 BrowserThread::PostTask( |
| 90 BrowserThread::UI, FROM_HERE, base::Bind( | 90 BrowserThread::UI, FROM_HERE, base::Bind( |
| 91 callback, DOWNLOAD_INTERRUPT_REASON_NONE)); | 91 callback, DOWNLOAD_INTERRUPT_REASON_NONE)); |
| 92 | 92 |
| 93 ++number_active_objects_; | 93 ++number_active_objects_; |
| 94 } | 94 } |
| 95 | 95 |
| 96 DownloadInterruptReason DownloadFileImpl::AppendDataToFile( | 96 DownloadInterruptReason DownloadFileImpl::AppendDataToFile( |
| 97 const char* data, size_t data_len) { | 97 const char* data, size_t data_len) { |
| 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 98 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 99 | 99 |
| 100 if (!update_timer_->IsRunning()) { | 100 if (!update_timer_->IsRunning()) { |
| 101 update_timer_->Start(FROM_HERE, | 101 update_timer_->Start(FROM_HERE, |
| 102 base::TimeDelta::FromMilliseconds(kUpdatePeriodMs), | 102 base::TimeDelta::FromMilliseconds(kUpdatePeriodMs), |
| 103 this, &DownloadFileImpl::SendUpdate); | 103 this, &DownloadFileImpl::SendUpdate); |
| 104 } | 104 } |
| 105 rate_estimator_.Increment(data_len); | 105 rate_estimator_.Increment(data_len); |
| 106 return file_.AppendDataToFile(data, data_len); | 106 return file_.AppendDataToFile(data, data_len); |
| 107 } | 107 } |
| 108 | 108 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 137 bool DownloadFileImpl::ShouldRetryFailedRename(DownloadInterruptReason reason) { | 137 bool DownloadFileImpl::ShouldRetryFailedRename(DownloadInterruptReason reason) { |
| 138 return reason == DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR; | 138 return reason == DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR; |
| 139 } | 139 } |
| 140 | 140 |
| 141 void DownloadFileImpl::RenameWithRetryInternal( | 141 void DownloadFileImpl::RenameWithRetryInternal( |
| 142 const base::FilePath& full_path, | 142 const base::FilePath& full_path, |
| 143 RenameOption option, | 143 RenameOption option, |
| 144 int retries_left, | 144 int retries_left, |
| 145 base::TimeTicks time_of_first_failure, | 145 base::TimeTicks time_of_first_failure, |
| 146 const RenameCompletionCallback& callback) { | 146 const RenameCompletionCallback& callback) { |
| 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 147 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 148 | 148 |
| 149 base::FilePath new_path(full_path); | 149 base::FilePath new_path(full_path); |
| 150 | 150 |
| 151 if ((option & UNIQUIFY) && full_path != file_.full_path()) { | 151 if ((option & UNIQUIFY) && full_path != file_.full_path()) { |
| 152 int uniquifier = | 152 int uniquifier = |
| 153 base::GetUniquePathNumber(new_path, base::FilePath::StringType()); | 153 base::GetUniquePathNumber(new_path, base::FilePath::StringType()); |
| 154 if (uniquifier > 0) | 154 if (uniquifier > 0) |
| 155 new_path = new_path.InsertBeforeExtensionASCII( | 155 new_path = new_path.InsertBeforeExtensionASCII( |
| 156 base::StringPrintf(" (%d)", uniquifier)); | 156 base::StringPrintf(" (%d)", uniquifier)); |
| 157 } | 157 } |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 observer_, file_.bytes_so_far(), CurrentSpeed(), | 352 observer_, file_.bytes_so_far(), CurrentSpeed(), |
| 353 GetHashState())); | 353 GetHashState())); |
| 354 } | 354 } |
| 355 | 355 |
| 356 // static | 356 // static |
| 357 int DownloadFile::GetNumberOfDownloadFiles() { | 357 int DownloadFile::GetNumberOfDownloadFiles() { |
| 358 return number_active_objects_; | 358 return number_active_objects_; |
| 359 } | 359 } |
| 360 | 360 |
| 361 } // namespace content | 361 } // namespace content |
| OLD | NEW |