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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } // namespace | 216 } // namespace |
217 | 217 |
218 DownloadManagerImpl::DownloadManagerImpl( | 218 DownloadManagerImpl::DownloadManagerImpl( |
219 net::NetLog* net_log) | 219 net::NetLog* net_log) |
220 : item_factory_(new DownloadItemFactoryImpl()), | 220 : item_factory_(new DownloadItemFactoryImpl()), |
221 file_factory_(new DownloadFileFactory()), | 221 file_factory_(new DownloadFileFactory()), |
222 history_size_(0), | 222 history_size_(0), |
223 shutdown_needed_(false), | 223 shutdown_needed_(false), |
224 browser_context_(NULL), | 224 browser_context_(NULL), |
225 delegate_(NULL), | 225 delegate_(NULL), |
226 net_log_(net_log) { | 226 net_log_(net_log), |
| 227 open_enabled_(true) { |
227 } | 228 } |
228 | 229 |
229 DownloadManagerImpl::~DownloadManagerImpl() { | 230 DownloadManagerImpl::~DownloadManagerImpl() { |
230 DCHECK(!shutdown_needed_); | 231 DCHECK(!shutdown_needed_); |
231 } | 232 } |
232 | 233 |
233 DownloadId DownloadManagerImpl::GetNextId() { | 234 DownloadId DownloadManagerImpl::GetNextId() { |
234 DownloadId id; | 235 DownloadId id; |
235 if (delegate_) | 236 if (delegate_) |
236 id = delegate_->GetNextId(); | 237 id = delegate_->GetNextId(); |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 return ContainsKey(downloads_, download_id) ? downloads_[download_id] : NULL; | 653 return ContainsKey(downloads_, download_id) ? downloads_[download_id] : NULL; |
653 } | 654 } |
654 | 655 |
655 void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) { | 656 void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) { |
656 for (DownloadMap::iterator it = downloads_.begin(); | 657 for (DownloadMap::iterator it = downloads_.begin(); |
657 it != downloads_.end(); ++it) { | 658 it != downloads_.end(); ++it) { |
658 downloads->push_back(it->second); | 659 downloads->push_back(it->second); |
659 } | 660 } |
660 } | 661 } |
661 | 662 |
662 void DownloadManagerImpl::DownloadOpened(DownloadItemImpl* download) { | 663 void DownloadManagerImpl::MockDownloadOpenForTesting() { |
| 664 open_enabled_ = false; |
| 665 } |
| 666 |
| 667 void DownloadManagerImpl::OpenDownload(DownloadItemImpl* download) { |
663 int num_unopened = 0; | 668 int num_unopened = 0; |
664 for (DownloadMap::iterator it = downloads_.begin(); | 669 for (DownloadMap::iterator it = downloads_.begin(); |
665 it != downloads_.end(); ++it) { | 670 it != downloads_.end(); ++it) { |
666 DownloadItemImpl* item = it->second; | 671 DownloadItemImpl* item = it->second; |
667 if (item->IsComplete() && | 672 if (item->IsComplete() && |
668 !item->GetOpened()) | 673 !item->GetOpened()) |
669 ++num_unopened; | 674 ++num_unopened; |
670 } | 675 } |
671 RecordOpensOutstanding(num_unopened); | 676 RecordOpensOutstanding(num_unopened); |
| 677 |
| 678 if (delegate_ && open_enabled_) // Some tests disable OpenDownload(). |
| 679 delegate_->OpenDownload(download); |
| 680 } |
| 681 |
| 682 void DownloadManagerImpl::ShowDownloadInShell(DownloadItemImpl* download) { |
| 683 if (delegate_) |
| 684 delegate_->ShowDownloadInShell(download); |
672 } | 685 } |
673 | 686 |
674 } // namespace content | 687 } // namespace content |
OLD | NEW |