| 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 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 // If the rename failed, we receive an OnDownloadInterrupted() call before we | 1117 // If the rename failed, we receive an OnDownloadInterrupted() call before we |
| 1122 // receive the DownloadRenamedToFinalName() call. | 1118 // receive the DownloadRenamedToFinalName() call. |
| 1123 delegate_->UpdatePathForItemInPersistentStore(download, | 1119 delegate_->UpdatePathForItemInPersistentStore(download, |
| 1124 download->GetFullPath()); | 1120 download->GetFullPath()); |
| 1125 } | 1121 } |
| 1126 | 1122 |
| 1127 void DownloadManagerImpl::SetFileManagerForTesting( | 1123 void DownloadManagerImpl::SetFileManagerForTesting( |
| 1128 DownloadFileManager* file_manager) { | 1124 DownloadFileManager* file_manager) { |
| 1129 file_manager_ = file_manager; | 1125 file_manager_ = file_manager; |
| 1130 } | 1126 } |
| OLD | NEW |