| 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 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 if (item->IsInProgress()) | 929 if (item->IsInProgress()) |
| 930 ++count; | 930 ++count; |
| 931 } | 931 } |
| 932 return count; | 932 return count; |
| 933 } | 933 } |
| 934 | 934 |
| 935 void DownloadManagerImpl::NotifyModelChanged() { | 935 void DownloadManagerImpl::NotifyModelChanged() { |
| 936 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged(this)); | 936 FOR_EACH_OBSERVER(Observer, observers_, ModelChanged(this)); |
| 937 } | 937 } |
| 938 | 938 |
| 939 DownloadItem* DownloadManagerImpl::GetDownloadItem(int download_id) { | |
| 940 DownloadItem* download = GetDownload(download_id); | |
| 941 return (download && download->IsPersisted()) ? download : NULL; | |
| 942 } | |
| 943 | |
| 944 DownloadItem* DownloadManagerImpl::GetDownload(int download_id) { | 939 DownloadItem* DownloadManagerImpl::GetDownload(int download_id) { |
| 945 return ContainsKey(downloads_, download_id) ? downloads_[download_id] : NULL; | 940 return ContainsKey(downloads_, download_id) ? downloads_[download_id] : NULL; |
| 946 } | 941 } |
| 947 | 942 |
| 948 void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) { | 943 void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) { |
| 949 for (DownloadMap::iterator it = downloads_.begin(); | 944 for (DownloadMap::iterator it = downloads_.begin(); |
| 950 it != downloads_.end(); ++it) { | 945 it != downloads_.end(); ++it) { |
| 951 downloads->push_back(it->second); | 946 downloads->push_back(it->second); |
| 952 } | 947 } |
| 953 } | 948 } |
| 954 | 949 |
| 955 DownloadItem* DownloadManagerImpl::GetActiveDownloadItem(int download_id) { | |
| 956 if (ContainsKey(active_downloads_, download_id)) | |
| 957 return active_downloads_[download_id]; | |
| 958 return NULL; | |
| 959 } | |
| 960 | |
| 961 // Confirm that everything in all maps is also in |downloads_|, and that | 950 // Confirm that everything in all maps is also in |downloads_|, and that |
| 962 // everything in |downloads_| is also in some other map. | 951 // everything in |downloads_| is also in some other map. |
| 963 void DownloadManagerImpl::AssertContainersConsistent() const { | 952 void DownloadManagerImpl::AssertContainersConsistent() const { |
| 964 #if !defined(NDEBUG) | 953 #if !defined(NDEBUG) |
| 965 // Turn everything into sets. | 954 // Turn everything into sets. |
| 966 const DownloadMap* input_maps[] = {&active_downloads_}; | 955 const DownloadMap* input_maps[] = {&active_downloads_}; |
| 967 DownloadSet active_set; | 956 DownloadSet active_set; |
| 968 DownloadSet* all_sets[] = {&active_set}; | 957 DownloadSet* all_sets[] = {&active_set}; |
| 969 DCHECK_EQ(ARRAYSIZE_UNSAFE(input_maps), ARRAYSIZE_UNSAFE(all_sets)); | 958 DCHECK_EQ(ARRAYSIZE_UNSAFE(input_maps), ARRAYSIZE_UNSAFE(all_sets)); |
| 970 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_maps); i++) { | 959 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_maps); i++) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 void DownloadManagerImpl::DownloadRenamedToFinalName( | 1044 void DownloadManagerImpl::DownloadRenamedToFinalName( |
| 1056 DownloadItemImpl* download) { | 1045 DownloadItemImpl* download) { |
| 1057 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1046 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1058 // If the rename failed, we receive an OnDownloadInterrupted() call before we | 1047 // If the rename failed, we receive an OnDownloadInterrupted() call before we |
| 1059 // receive the DownloadRenamedToFinalName() call. | 1048 // receive the DownloadRenamedToFinalName() call. |
| 1060 if (delegate_) { | 1049 if (delegate_) { |
| 1061 delegate_->UpdatePathForItemInPersistentStore( | 1050 delegate_->UpdatePathForItemInPersistentStore( |
| 1062 download, download->GetFullPath()); | 1051 download, download->GetFullPath()); |
| 1063 } | 1052 } |
| 1064 } | 1053 } |
| OLD | NEW |