Fix searching on chrome://downloads

PS1@r216878

BUG=270998

Review URL: https://codereview.chromium.org/22773003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216886 0039d316-1c4b-4281-b951-d872f2087c98
parent f2f3fcb6
...@@ -758,7 +758,19 @@ function load() { ...@@ -758,7 +758,19 @@ function load() {
function setSearch(searchText) { function setSearch(searchText) {
fifoResults.length = 0; fifoResults.length = 0;
downloads.setSearchText(searchText); downloads.setSearchText(searchText);
chrome.send('getDownloads', [searchText.toString()]); searchText = searchText.toString().match(/(?:[^\s"]+|"[^"]*")+/g);
if (searchText) {
searchText = searchText.map(function(term) {
// strip quotes
return (term.match(/\s/) &&
term[0].match(/["']/) &&
term[term.length - 1] == term[0]) ?
term.substr(1, term.length - 2) : term;
});
} else {
searchText = [];
}
chrome.send('getDownloads', searchText);
} }
function clearAll() { function clearAll() {
......
...@@ -262,8 +262,7 @@ bool IsDownloadDisplayable(const content::DownloadItem& item) { ...@@ -262,8 +262,7 @@ bool IsDownloadDisplayable(const content::DownloadItem& item) {
} // namespace } // namespace
DownloadsDOMHandler::DownloadsDOMHandler(content::DownloadManager* dlm) DownloadsDOMHandler::DownloadsDOMHandler(content::DownloadManager* dlm)
: search_text_(), : main_notifier_(dlm, this),
main_notifier_(dlm, this),
update_scheduled_(false), update_scheduled_(false),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
// Create our fileicon data source. // Create our fileicon data source.
...@@ -338,16 +337,14 @@ void DownloadsDOMHandler::OnDownloadUpdated( ...@@ -338,16 +337,14 @@ void DownloadsDOMHandler::OnDownloadUpdated(
content::DownloadManager* manager, content::DownloadManager* manager,
content::DownloadItem* download_item) { content::DownloadItem* download_item) {
if (IsDownloadDisplayable(*download_item)) { if (IsDownloadDisplayable(*download_item)) {
if (!search_text_.empty()) { if (search_terms_ && !search_terms_->empty()) {
// Don't CallDownloadUpdated() if download_item doesn't match // Don't CallDownloadUpdated() if download_item doesn't match
// search_text_. // search_terms_.
// TODO(benjhayden): Consider splitting MatchesQuery() out to a function. // TODO(benjhayden): Consider splitting MatchesQuery() out to a function.
content::DownloadManager::DownloadVector all_items, filtered_items; content::DownloadManager::DownloadVector all_items, filtered_items;
all_items.push_back(download_item); all_items.push_back(download_item);
DownloadQuery query; DownloadQuery query;
scoped_ptr<base::Value> query_text(base::Value::CreateStringValue( query.AddFilter(DownloadQuery::FILTER_QUERY, *search_terms_.get());
search_text_));
query.AddFilter(DownloadQuery::FILTER_QUERY, *query_text.get());
query.Search(all_items.begin(), all_items.end(), &filtered_items); query.Search(all_items.begin(), all_items.end(), &filtered_items);
if (filtered_items.empty()) if (filtered_items.empty())
return; return;
...@@ -379,7 +376,7 @@ void DownloadsDOMHandler::OnDownloadRemoved( ...@@ -379,7 +376,7 @@ void DownloadsDOMHandler::OnDownloadRemoved(
void DownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) { void DownloadsDOMHandler::HandleGetDownloads(const base::ListValue* args) {
CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS); CountDownloadsDOMEvents(DOWNLOADS_DOM_EVENT_GET_DOWNLOADS);
search_text_ = ExtractStringValue(args); search_terms_.reset((args && !args->empty()) ? args->DeepCopy() : NULL);
SendCurrentDownloads(); SendCurrentDownloads();
} }
...@@ -523,10 +520,8 @@ void DownloadsDOMHandler::SendCurrentDownloads() { ...@@ -523,10 +520,8 @@ void DownloadsDOMHandler::SendCurrentDownloads() {
original_notifier_->GetManager()->CheckForHistoryFilesRemoval(); original_notifier_->GetManager()->CheckForHistoryFilesRemoval();
} }
DownloadQuery query; DownloadQuery query;
if (!search_text_.empty()) { if (search_terms_ && !search_terms_->empty()) {
scoped_ptr<base::Value> query_text(base::Value::CreateStringValue( query.AddFilter(DownloadQuery::FILTER_QUERY, *search_terms_.get());
search_text_));
query.AddFilter(DownloadQuery::FILTER_QUERY, *query_text.get());
} }
query.AddFilter(base::Bind(&IsDownloadDisplayable)); query.AddFilter(base::Bind(&IsDownloadDisplayable));
query.AddSorter(DownloadQuery::SORT_START_TIME, DownloadQuery::DESCENDING); query.AddSorter(DownloadQuery::SORT_START_TIME, DownloadQuery::DESCENDING);
......
...@@ -130,8 +130,8 @@ class DownloadsDOMHandler : public content::WebUIMessageHandler, ...@@ -130,8 +130,8 @@ class DownloadsDOMHandler : public content::WebUIMessageHandler,
// Returns the download that is referred to in a given value. // Returns the download that is referred to in a given value.
content::DownloadItem* GetDownloadByValue(const base::ListValue* args); content::DownloadItem* GetDownloadByValue(const base::ListValue* args);
// Current search text. // Current search terms.
string16 search_text_; scoped_ptr<base::ListValue> search_terms_;
// Notifies OnDownload*() and provides safe access to the DownloadManager. // Notifies OnDownload*() and provides safe access to the DownloadManager.
AllDownloadItemNotifier main_notifier_; AllDownloadItemNotifier main_notifier_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment