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