| 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_manager_impl.h" | 5 #include "content/browser/download/download_manager_impl.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 BrowserThread::PostTask( | 133 BrowserThread::PostTask( |
| 134 BrowserThread::FILE, FROM_HERE, | 134 BrowserThread::FILE, FROM_HERE, |
| 135 base::Bind(&EnsureNoPendingDownloadsOnFile, | 135 base::Bind(&EnsureNoPendingDownloadsOnFile, |
| 136 download_file_manager, result)); | 136 download_file_manager, result)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 } // namespace | 139 } // namespace |
| 140 | 140 |
| 141 namespace content { | 141 namespace content { |
| 142 | 142 |
| 143 // static | |
| 144 DownloadManager* DownloadManager::Create( | |
| 145 content::DownloadManagerDelegate* delegate, | |
| 146 net::NetLog* net_log) { | |
| 147 return new DownloadManagerImpl(delegate, net_log); | |
| 148 } | |
| 149 | |
| 150 bool DownloadManager::EnsureNoPendingDownloadsForTesting() { | 143 bool DownloadManager::EnsureNoPendingDownloadsForTesting() { |
| 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 152 bool result = true; | 145 bool result = true; |
| 153 BrowserThread::PostTask( | 146 BrowserThread::PostTask( |
| 154 BrowserThread::IO, FROM_HERE, | 147 BrowserThread::IO, FROM_HERE, |
| 155 base::Bind(&EnsureNoPendingDownloadJobsOnIO, &result)); | 148 base::Bind(&EnsureNoPendingDownloadJobsOnIO, &result)); |
| 156 MessageLoop::current()->Run(); | 149 MessageLoop::current()->Run(); |
| 157 return result; | 150 return result; |
| 158 } | 151 } |
| 159 | 152 |
| 160 } // namespace content | 153 } // namespace content |
| 161 | 154 |
| 162 DownloadManagerImpl::DownloadManagerImpl( | 155 DownloadManagerImpl::DownloadManagerImpl(net::NetLog* net_log) |
| 163 content::DownloadManagerDelegate* delegate, | 156 : shutdown_needed_(false), |
| 164 net::NetLog* net_log) | 157 browser_context_(NULL), |
| 165 : shutdown_needed_(false), | 158 file_manager_(NULL), |
| 166 browser_context_(NULL), | 159 delegate_(NULL), |
| 167 file_manager_(NULL), | 160 net_log_(net_log) { |
| 168 delegate_(delegate), | |
| 169 net_log_(net_log) { | |
| 170 } | 161 } |
| 171 | 162 |
| 172 DownloadManagerImpl::~DownloadManagerImpl() { | 163 DownloadManagerImpl::~DownloadManagerImpl() { |
| 173 DCHECK(!shutdown_needed_); | 164 DCHECK(!shutdown_needed_); |
| 174 } | 165 } |
| 175 | 166 |
| 176 DownloadId DownloadManagerImpl::GetNextId() { | 167 DownloadId DownloadManagerImpl::GetNextId() { |
| 177 return delegate_->GetNextId(); | 168 return delegate_->GetNextId(); |
| 178 } | 169 } |
| 179 | 170 |
| 180 bool DownloadManagerImpl::ShouldOpenDownload(DownloadItem* item) { | 171 bool DownloadManagerImpl::ShouldOpenDownload(DownloadItem* item) { |
| 181 return delegate_->ShouldOpenDownload(item); | 172 return delegate_->ShouldOpenDownload(item); |
| 182 } | 173 } |
| 183 | 174 |
| 184 bool DownloadManagerImpl::ShouldOpenFileBasedOnExtension(const FilePath& path) { | 175 bool DownloadManagerImpl::ShouldOpenFileBasedOnExtension(const FilePath& path) { |
| 185 return delegate_->ShouldOpenFileBasedOnExtension(path); | 176 return delegate_->ShouldOpenFileBasedOnExtension(path); |
| 186 } | 177 } |
| 187 | 178 |
| 179 void DownloadManagerImpl::SetDelegate( |
| 180 content::DownloadManagerDelegate* delegate) { |
| 181 delegate_ = delegate; |
| 182 } |
| 183 |
| 188 void DownloadManagerImpl::Shutdown() { | 184 void DownloadManagerImpl::Shutdown() { |
| 189 VLOG(20) << __FUNCTION__ << "()" | 185 VLOG(20) << __FUNCTION__ << "()" |
| 190 << " shutdown_needed_ = " << shutdown_needed_; | 186 << " shutdown_needed_ = " << shutdown_needed_; |
| 191 if (!shutdown_needed_) | 187 if (!shutdown_needed_) |
| 192 return; | 188 return; |
| 193 shutdown_needed_ = false; | 189 shutdown_needed_ = false; |
| 194 | 190 |
| 195 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown(this)); | 191 FOR_EACH_OBSERVER(Observer, observers_, ManagerGoingDown(this)); |
| 196 // TODO(benjhayden): Consider clearing observers_. | 192 // TODO(benjhayden): Consider clearing observers_. |
| 197 | 193 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 active_downloads_.clear(); | 238 active_downloads_.clear(); |
| 243 history_downloads_.clear(); | 239 history_downloads_.clear(); |
| 244 STLDeleteElements(&downloads_to_delete); | 240 STLDeleteElements(&downloads_to_delete); |
| 245 | 241 |
| 246 // We'll have nothing more to report to the observers after this point. | 242 // We'll have nothing more to report to the observers after this point. |
| 247 observers_.Clear(); | 243 observers_.Clear(); |
| 248 | 244 |
| 249 DCHECK(save_page_downloads_.empty()); | 245 DCHECK(save_page_downloads_.empty()); |
| 250 | 246 |
| 251 file_manager_ = NULL; | 247 file_manager_ = NULL; |
| 252 delegate_->Shutdown(); | 248 if (delegate_) |
| 249 delegate_->Shutdown(); |
| 253 } | 250 } |
| 254 | 251 |
| 255 void DownloadManagerImpl::GetTemporaryDownloads( | 252 void DownloadManagerImpl::GetTemporaryDownloads( |
| 256 const FilePath& dir_path, DownloadVector* result) { | 253 const FilePath& dir_path, DownloadVector* result) { |
| 257 DCHECK(result); | 254 DCHECK(result); |
| 258 | 255 |
| 259 for (DownloadMap::iterator it = history_downloads_.begin(); | 256 for (DownloadMap::iterator it = history_downloads_.begin(); |
| 260 it != history_downloads_.end(); ++it) { | 257 it != history_downloads_.end(); ++it) { |
| 261 if (it->second->IsTemporary() && | 258 if (it->second->IsTemporary() && |
| 262 (dir_path.empty() || | 259 (dir_path.empty() || |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 // If the rename failed, we receive an OnDownloadInterrupted() call before we | 1118 // If the rename failed, we receive an OnDownloadInterrupted() call before we |
| 1122 // receive the DownloadRenamedToFinalName() call. | 1119 // receive the DownloadRenamedToFinalName() call. |
| 1123 delegate_->UpdatePathForItemInPersistentStore(download, | 1120 delegate_->UpdatePathForItemInPersistentStore(download, |
| 1124 download->GetFullPath()); | 1121 download->GetFullPath()); |
| 1125 } | 1122 } |
| 1126 | 1123 |
| 1127 void DownloadManagerImpl::SetFileManagerForTesting( | 1124 void DownloadManagerImpl::SetFileManagerForTesting( |
| 1128 DownloadFileManager* file_manager) { | 1125 DownloadFileManager* file_manager) { |
| 1129 file_manager_ = file_manager; | 1126 file_manager_ = file_manager; |
| 1130 } | 1127 } |
| OLD | NEW |