Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: content/browser/download/download_manager.cc

Issue 7825035: Implement chrome.experimental.downloads.search() (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: merge Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_stats.h" 29 #include "content/browser/download/download_stats.h"
29 #include "content/browser/download/download_status_updater.h" 30 #include "content/browser/download/download_status_updater.h"
30 #include "content/browser/download/interrupt_reasons.h" 31 #include "content/browser/download/interrupt_reasons.h"
31 #include "content/browser/renderer_host/render_process_host.h" 32 #include "content/browser/renderer_host/render_process_host.h"
32 #include "content/browser/renderer_host/render_view_host.h" 33 #include "content/browser/renderer_host/render_view_host.h"
33 #include "content/browser/renderer_host/resource_dispatcher_host.h" 34 #include "content/browser/renderer_host/resource_dispatcher_host.h"
34 #include "content/browser/tab_contents/tab_contents.h" 35 #include "content/browser/tab_contents/tab_contents.h"
35 #include "content/common/notification_service.h" 36 #include "content/common/notification_service.h"
36 #include "content/public/browser/notification_types.h" 37 #include "content/public/browser/notification_types.h"
37 38
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 DCHECK(result); 168 DCHECK(result);
168 169
169 for (DownloadMap::iterator it = history_downloads_.begin(); 170 for (DownloadMap::iterator it = history_downloads_.begin();
170 it != history_downloads_.end(); ++it) { 171 it != history_downloads_.end(); ++it) {
171 if (!it->second->is_temporary() && 172 if (!it->second->is_temporary() &&
172 (dir_path.empty() || it->second->full_path().DirName() == dir_path)) 173 (dir_path.empty() || it->second->full_path().DirName() == dir_path))
173 result->push_back(it->second); 174 result->push_back(it->second);
174 } 175 }
175 } 176 }
176 177
178 void DownloadManager::Search(const download_util::DownloadQuery& query,
179 DownloadVector* results) const {
180 query.Search(downloads_.begin(), downloads_.end(), results);
181 }
182
177 void DownloadManager::SearchDownloads(const string16& query, 183 void DownloadManager::SearchDownloads(const string16& query,
178 DownloadVector* result) { 184 DownloadVector* result) {
179 string16 query_lower(base::i18n::ToLower(query)); 185 string16 query_lower(base::i18n::ToLower(query));
180 186
181 for (DownloadMap::iterator it = history_downloads_.begin(); 187 for (DownloadMap::iterator it = history_downloads_.begin();
182 it != history_downloads_.end(); ++it) { 188 it != history_downloads_.end(); ++it) {
183 DownloadItem* download_item = it->second; 189 DownloadItem* download_item = it->second;
184 190
185 if (download_item->is_temporary()) 191 if (download_item->is_temporary())
186 continue; 192 continue;
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 826
821 // The history service has retrieved all download entries. 'entries' contains 827 // The history service has retrieved all download entries. 'entries' contains
822 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time). 828 // 'DownloadPersistentStoreInfo's in sorted order (by ascending start_time).
823 void DownloadManager::OnPersistentStoreQueryComplete( 829 void DownloadManager::OnPersistentStoreQueryComplete(
824 std::vector<DownloadPersistentStoreInfo>* entries) { 830 std::vector<DownloadPersistentStoreInfo>* entries) {
825 // TODO(rdsmith): Remove this and related logic when 831 // TODO(rdsmith): Remove this and related logic when
826 // http://crbug.com/85408 is fixed. 832 // http://crbug.com/85408 is fixed.
827 largest_db_handle_in_history_ = 0; 833 largest_db_handle_in_history_ = 0;
828 834
829 for (size_t i = 0; i < entries->size(); ++i) { 835 for (size_t i = 0; i < entries->size(); ++i) {
830 DownloadItem* download = new DownloadItem(this, entries->at(i)); 836 DownloadItem* download = new DownloadItem(this, entries->at(i), -1 - i);
cbentzel 2011/10/20 18:18:53 Why -1 - i?
831 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved. 837 // TODO(rdsmith): Remove after http://crbug.com/85408 resolved.
832 CHECK(!ContainsKey(history_downloads_, download->db_handle())); 838 CHECK(!ContainsKey(history_downloads_, download->db_handle()));
833 downloads_.insert(download); 839 downloads_.insert(download);
834 history_downloads_[download->db_handle()] = download; 840 history_downloads_[download->db_handle()] = download;
835 VLOG(20) << __FUNCTION__ << "()" << i << ">" 841 VLOG(20) << __FUNCTION__ << "()" << i << ">"
836 << " download = " << download->DebugString(true); 842 << " download = " << download->DebugString(true);
837 843
838 if (download->db_handle() > largest_db_handle_in_history_) 844 if (download->db_handle() > largest_db_handle_in_history_)
839 largest_db_handle_in_history_ = download->db_handle(); 845 largest_db_handle_in_history_ = download->db_handle();
840 } 846 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 void DownloadManager::MarkDownloadOpened(DownloadItem* download) { 1089 void DownloadManager::MarkDownloadOpened(DownloadItem* download) {
1084 delegate_->UpdateItemInPersistentStore(download); 1090 delegate_->UpdateItemInPersistentStore(download);
1085 int num_unopened = 0; 1091 int num_unopened = 0;
1086 for (DownloadMap::iterator it = history_downloads_.begin(); 1092 for (DownloadMap::iterator it = history_downloads_.begin();
1087 it != history_downloads_.end(); ++it) { 1093 it != history_downloads_.end(); ++it) {
1088 if (it->second->IsComplete() && !it->second->opened()) 1094 if (it->second->IsComplete() && !it->second->opened())
1089 ++num_unopened; 1095 ++num_unopened;
1090 } 1096 }
1091 download_stats::RecordOpensOutstanding(num_unopened); 1097 download_stats::RecordOpensOutstanding(num_unopened);
1092 } 1098 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698