| 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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 DownloadItemImpl* item = it->second; | 342 DownloadItemImpl* item = it->second; |
| 343 // TODO(benjhayden): Don't check IsPersisted(). | 343 // TODO(benjhayden): Don't check IsPersisted(). |
| 344 if (item->IsTemporary() && | 344 if (item->IsTemporary() && |
| 345 item->IsPersisted() && | 345 item->IsPersisted() && |
| 346 (dir_path.empty() || | 346 (dir_path.empty() || |
| 347 item->GetTargetFilePath().DirName() == dir_path)) | 347 item->GetTargetFilePath().DirName() == dir_path)) |
| 348 result->push_back(item); | 348 result->push_back(item); |
| 349 } | 349 } |
| 350 } | 350 } |
| 351 | 351 |
| 352 void DownloadManagerImpl::GetAllDownloads( | |
| 353 const FilePath& dir_path, DownloadVector* result) { | |
| 354 DCHECK(result); | |
| 355 | |
| 356 for (DownloadMap::iterator it = downloads_.begin(); | |
| 357 it != downloads_.end(); ++it) { | |
| 358 DownloadItemImpl* item = it->second; | |
| 359 // TODO(benjhayden): Don't check IsPersisted(). | |
| 360 if (!item->IsTemporary() && | |
| 361 item->IsPersisted() && | |
| 362 (dir_path.empty() || | |
| 363 item->GetTargetFilePath().DirName() == dir_path)) | |
| 364 result->push_back(item); | |
| 365 } | |
| 366 } | |
| 367 | |
| 368 void DownloadManagerImpl::SearchDownloads(const string16& query, | 352 void DownloadManagerImpl::SearchDownloads(const string16& query, |
| 369 DownloadVector* result) { | 353 DownloadVector* result) { |
| 370 string16 query_lower(base::i18n::ToLower(query)); | 354 string16 query_lower(base::i18n::ToLower(query)); |
| 371 | 355 |
| 372 for (DownloadMap::iterator it = downloads_.begin(); | 356 for (DownloadMap::iterator it = downloads_.begin(); |
| 373 it != downloads_.end(); ++it) { | 357 it != downloads_.end(); ++it) { |
| 374 DownloadItemImpl* download_item = it->second; | 358 DownloadItemImpl* download_item = it->second; |
| 375 // TODO(benjhayden): Don't check IsPersisted(). | 359 // TODO(benjhayden): Don't check IsPersisted(). |
| 376 if (!download_item->IsTemporary() && | 360 if (!download_item->IsTemporary() && |
| 377 download_item->IsPersisted() && | 361 download_item->IsPersisted() && |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 | 959 |
| 976 DownloadItem* DownloadManagerImpl::GetDownloadItem(int download_id) { | 960 DownloadItem* DownloadManagerImpl::GetDownloadItem(int download_id) { |
| 977 DownloadItem* download = GetDownload(download_id); | 961 DownloadItem* download = GetDownload(download_id); |
| 978 return (download && download->IsPersisted()) ? download : NULL; | 962 return (download && download->IsPersisted()) ? download : NULL; |
| 979 } | 963 } |
| 980 | 964 |
| 981 DownloadItem* DownloadManagerImpl::GetDownload(int download_id) { | 965 DownloadItem* DownloadManagerImpl::GetDownload(int download_id) { |
| 982 return ContainsKey(downloads_, download_id) ? downloads_[download_id] : NULL; | 966 return ContainsKey(downloads_, download_id) ? downloads_[download_id] : NULL; |
| 983 } | 967 } |
| 984 | 968 |
| 969 void DownloadManagerImpl::GetAllDownloads(DownloadVector* downloads) { |
| 970 for (DownloadMap::iterator it = downloads_.begin(); |
| 971 it != downloads_.end(); ++it) { |
| 972 downloads->push_back(it->second); |
| 973 } |
| 974 } |
| 975 |
| 985 DownloadItem* DownloadManagerImpl::GetActiveDownloadItem(int download_id) { | 976 DownloadItem* DownloadManagerImpl::GetActiveDownloadItem(int download_id) { |
| 986 if (ContainsKey(active_downloads_, download_id)) | 977 if (ContainsKey(active_downloads_, download_id)) |
| 987 return active_downloads_[download_id]; | 978 return active_downloads_[download_id]; |
| 988 return NULL; | 979 return NULL; |
| 989 } | 980 } |
| 990 | 981 |
| 991 // Confirm that everything in all maps is also in |downloads_|, and that | 982 // Confirm that everything in all maps is also in |downloads_|, and that |
| 992 // everything in |downloads_| is also in some other map. | 983 // everything in |downloads_| is also in some other map. |
| 993 void DownloadManagerImpl::AssertContainersConsistent() const { | 984 void DownloadManagerImpl::AssertContainersConsistent() const { |
| 994 #if !defined(NDEBUG) | 985 #if !defined(NDEBUG) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 void DownloadManagerImpl::DownloadRenamedToFinalName( | 1081 void DownloadManagerImpl::DownloadRenamedToFinalName( |
| 1091 DownloadItemImpl* download) { | 1082 DownloadItemImpl* download) { |
| 1092 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1083 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1093 // If the rename failed, we receive an OnDownloadInterrupted() call before we | 1084 // If the rename failed, we receive an OnDownloadInterrupted() call before we |
| 1094 // receive the DownloadRenamedToFinalName() call. | 1085 // receive the DownloadRenamedToFinalName() call. |
| 1095 if (delegate_) { | 1086 if (delegate_) { |
| 1096 delegate_->UpdatePathForItemInPersistentStore( | 1087 delegate_->UpdatePathForItemInPersistentStore( |
| 1097 download, download->GetFullPath()); | 1088 download, download->GetFullPath()); |
| 1098 } | 1089 } |
| 1099 } | 1090 } |
| OLD | NEW |