Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "content/browser/download/download_manager.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" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/i18n/case_conversion.h" | 12 #include "base/i18n/case_conversion.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "base/sys_string_conversions.h" | 17 #include "base/sys_string_conversions.h" |
| 18 #include "base/task.h" | 18 #include "base/task.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "content/browser/browser_context.h" | 20 #include "content/browser/browser_context.h" |
| 21 #include "content/browser/browser_thread.h" | 21 #include "content/browser/browser_thread.h" |
| 22 #include "content/browser/content_browser_client.h" | 22 #include "content/browser/content_browser_client.h" |
| 23 #include "content/browser/download/download_create_info.h" | 23 #include "content/browser/download/download_create_info.h" |
| 24 #include "content/browser/download/download_file_manager.h" | 24 #include "content/browser/download/download_file_manager.h" |
| 25 #include "content/browser/download/download_item.h" | 25 #include "content/browser/download/download_item.h" |
| 26 #include "content/browser/download/download_manager_delegate.h" | 26 #include "content/browser/download/download_manager_delegate.h" |
| 27 #include "content/browser/download/download_persistent_store_info.h" | 27 #include "content/browser/download/download_persistent_store_info.h" |
| 28 #include "content/browser/download/download_query.h" | |
| 28 #include "content/browser/download/download_status_updater.h" | 29 #include "content/browser/download/download_status_updater.h" |
| 29 #include "content/browser/download/interrupt_reasons.h" | 30 #include "content/browser/download/interrupt_reasons.h" |
| 30 #include "content/browser/renderer_host/render_process_host.h" | 31 #include "content/browser/renderer_host/render_process_host.h" |
| 31 #include "content/browser/renderer_host/render_view_host.h" | 32 #include "content/browser/renderer_host/render_view_host.h" |
| 32 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 33 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
| 33 #include "content/browser/tab_contents/tab_contents.h" | 34 #include "content/browser/tab_contents/tab_contents.h" |
| 34 #include "content/common/content_notification_types.h" | 35 #include "content/common/content_notification_types.h" |
| 35 #include "content/common/notification_service.h" | 36 #include "content/common/notification_service.h" |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 DCHECK(result); | 167 DCHECK(result); |
| 167 | 168 |
| 168 for (DownloadMap::iterator it = history_downloads_.begin(); | 169 for (DownloadMap::iterator it = history_downloads_.begin(); |
| 169 it != history_downloads_.end(); ++it) { | 170 it != history_downloads_.end(); ++it) { |
| 170 if (!it->second->is_temporary() && | 171 if (!it->second->is_temporary() && |
| 171 (dir_path.empty() || it->second->full_path().DirName() == dir_path)) | 172 (dir_path.empty() || it->second->full_path().DirName() == dir_path)) |
| 172 result->push_back(it->second); | 173 result->push_back(it->second); |
| 173 } | 174 } |
| 174 } | 175 } |
| 175 | 176 |
| 177 void DownloadManager::Search(const download_util::DownloadQuery& query, | |
| 178 DownloadVector* results) const { | |
| 179 CHECK(results); | |
| 180 results->clear(); | |
| 181 DownloadVector all_items; | |
| 182 for (DownloadSet::const_iterator it = downloads_.begin(); | |
| 183 it != downloads_.end(); ++it) { | |
| 184 all_items.push_back(*it); | |
| 185 } | |
| 186 query.Search(all_items, results); | |
|
Randy Smith (Not in Mondays)
2011/10/13 23:23:11
Potentially tacky, but may be worth considering: C
benjhayden
2011/10/14 19:31:02
Done.
| |
| 187 } | |
| 188 | |
| 176 void DownloadManager::SearchDownloads(const string16& query, | 189 void DownloadManager::SearchDownloads(const string16& query, |
| 177 DownloadVector* result) { | 190 DownloadVector* result) { |
| 178 string16 query_lower(base::i18n::ToLower(query)); | 191 string16 query_lower(base::i18n::ToLower(query)); |
| 179 | 192 |
| 180 for (DownloadMap::iterator it = history_downloads_.begin(); | 193 for (DownloadMap::iterator it = history_downloads_.begin(); |
| 181 it != history_downloads_.end(); ++it) { | 194 it != history_downloads_.end(); ++it) { |
| 182 DownloadItem* download_item = it->second; | 195 DownloadItem* download_item = it->second; |
| 183 | 196 |
| 184 if (download_item->is_temporary()) | 197 if (download_item->is_temporary()) |
| 185 continue; | 198 continue; |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 | 831 |
| 819 // The history service has retrieved all download entries. 'entries' contains | 832 // The history service has retrieved all download entries. 'entries' contains |
| 820 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time). | 833 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time). |
| 821 void DownloadManager::OnPersistentStoreQueryComplete( | 834 void DownloadManager::OnPersistentStoreQueryComplete( |
| 822 std::vector<DownloadPersistentStoreInfo>* entries) { | 835 std::vector<DownloadPersistentStoreInfo>* entries) { |
| 823 // TODO(rdsmith): Remove this and related logic when | 836 // TODO(rdsmith): Remove this and related logic when |
| 824 // http://crbug.com/85408 is fixed. | 837 // http://crbug.com/85408 is fixed. |
| 825 largest_db_handle_in_history_ = 0; | 838 largest_db_handle_in_history_ = 0; |
| 826 | 839 |
| 827 for (size_t i = 0; i < entries->size(); ++i) { | 840 for (size_t i = 0; i < entries->size(); ++i) { |
| 828 DownloadItem* download = new DownloadItem(this, entries->at(i)); | 841 DownloadItem* download = new DownloadItem(this, entries->at(i), -1 - i); |
| 829 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. | 842 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. |
| 830 CHECK(!ContainsKey(history_downloads_, download->db_handle())); | 843 CHECK(!ContainsKey(history_downloads_, download->db_handle())); |
| 831 downloads_.insert(download); | 844 downloads_.insert(download); |
| 832 history_downloads_[download->db_handle()] = download; | 845 history_downloads_[download->db_handle()] = download; |
| 833 VLOG(20) << __FUNCTION__ << "()" << i << ">" | 846 VLOG(20) << __FUNCTION__ << "()" << i << ">" |
| 834 << " download = " << download->DebugString(true); | 847 << " download = " << download->DebugString(true); |
| 835 | 848 |
| 836 if (download->db_handle() > largest_db_handle_in_history_) | 849 if (download->db_handle() > largest_db_handle_in_history_) |
| 837 largest_db_handle_in_history_ = download->db_handle(); | 850 largest_db_handle_in_history_ = download->db_handle(); |
| 838 } | 851 } |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1068 DCHECK(ContainsKey(save_page_downloads_, download->id())); | 1081 DCHECK(ContainsKey(save_page_downloads_, download->id())); |
| 1069 save_page_downloads_.erase(download->id()); | 1082 save_page_downloads_.erase(download->id()); |
| 1070 | 1083 |
| 1071 if (download->IsComplete()) | 1084 if (download->IsComplete()) |
| 1072 NotificationService::current()->Notify( | 1085 NotificationService::current()->Notify( |
| 1073 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, | 1086 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, |
| 1074 Source<DownloadManager>(this), | 1087 Source<DownloadManager>(this), |
| 1075 Details<DownloadItem>(download)); | 1088 Details<DownloadItem>(download)); |
| 1076 } | 1089 } |
| 1077 } | 1090 } |
| OLD | NEW |