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

Side by Side Diff: chrome/browser/download/download_query.cc

Issue 1428833005: MD Downloads: track downloads in C++, dispatch discrete JS updates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: silly windows Created 5 years 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
OLDNEW
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 "chrome/browser/download/download_query.h" 5 #include "chrome/browser/download/download_query.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 return false; 62 return false;
63 } 63 }
64 out->push_back(element); 64 out->push_back(element);
65 } 65 }
66 return true; 66 return true;
67 } 67 }
68 68
69 // The next several functions are helpers for making Callbacks that access 69 // The next several functions are helpers for making Callbacks that access
70 // DownloadItem fields. 70 // DownloadItem fields.
71 71
72 static bool MatchesQuery(
73 const std::vector<base::string16>& query_terms,
74 const DownloadItem& item) {
75 DCHECK(!query_terms.empty());
76 base::string16 url_raw(base::UTF8ToUTF16(item.GetOriginalUrl().spec()));
77 base::string16 url_formatted = url_raw;
78 if (item.GetBrowserContext()) {
79 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext());
80 url_formatted = url_formatter::FormatUrl(
81 item.GetOriginalUrl(),
82 profile->GetPrefs()->GetString(prefs::kAcceptLanguages));
83 }
84 base::string16 path(item.GetTargetFilePath().LossyDisplayName());
85
86 for (std::vector<base::string16>::const_iterator it = query_terms.begin();
87 it != query_terms.end(); ++it) {
88 base::string16 term = base::i18n::ToLower(*it);
89 if (!base::i18n::StringSearchIgnoringCaseAndAccents(
90 term, url_raw, NULL, NULL) &&
91 !base::i18n::StringSearchIgnoringCaseAndAccents(
92 term, url_formatted, NULL, NULL) &&
93 !base::i18n::StringSearchIgnoringCaseAndAccents(
94 term, path, NULL, NULL)) {
95 return false;
96 }
97 }
98 return true;
99 }
100
101 static int64 GetStartTimeMsEpoch(const DownloadItem& item) { 72 static int64 GetStartTimeMsEpoch(const DownloadItem& item) {
102 return (item.GetStartTime() - base::Time::UnixEpoch()).InMilliseconds(); 73 return (item.GetStartTime() - base::Time::UnixEpoch()).InMilliseconds();
103 } 74 }
104 75
105 static int64 GetEndTimeMsEpoch(const DownloadItem& item) { 76 static int64 GetEndTimeMsEpoch(const DownloadItem& item) {
106 return (item.GetEndTime() - base::Time::UnixEpoch()).InMilliseconds(); 77 return (item.GetEndTime() - base::Time::UnixEpoch()).InMilliseconds();
107 } 78 }
108 79
109 std::string TimeToISO8601(const base::Time& t) { 80 std::string TimeToISO8601(const base::Time& t) {
110 base::Time::Exploded exploded; 81 base::Time::Exploded exploded;
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 ValueType left_value = accessor.Run(left); 201 ValueType left_value = accessor.Run(left);
231 ValueType right_value = accessor.Run(right); 202 ValueType right_value = accessor.Run(right);
232 if (left_value > right_value) return GT; 203 if (left_value > right_value) return GT;
233 if (left_value < right_value) return LT; 204 if (left_value < right_value) return LT;
234 DCHECK_EQ(left_value, right_value); 205 DCHECK_EQ(left_value, right_value);
235 return EQ; 206 return EQ;
236 } 207 }
237 208
238 } // anonymous namespace 209 } // anonymous namespace
239 210
211 // static
212 bool DownloadQuery::MatchesQuery(const std::vector<base::string16>& query_terms,
213 const DownloadItem& item) {
214 if (query_terms.empty())
215 return true;
Dan Beam 2015/11/25 20:23:23 asanka@: note ^
asanka 2015/11/25 20:49:06 Noted.
216
217 base::string16 url_raw(base::UTF8ToUTF16(item.GetOriginalUrl().spec()));
218 base::string16 url_formatted = url_raw;
219 if (item.GetBrowserContext()) {
220 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext());
221 url_formatted = url_formatter::FormatUrl(
222 item.GetOriginalUrl(),
223 profile->GetPrefs()->GetString(prefs::kAcceptLanguages));
224 }
225 base::string16 path(item.GetTargetFilePath().LossyDisplayName());
226
227 for (std::vector<base::string16>::const_iterator it = query_terms.begin();
228 it != query_terms.end(); ++it) {
229 base::string16 term = base::i18n::ToLower(*it);
230 if (!base::i18n::StringSearchIgnoringCaseAndAccents(
231 term, url_raw, NULL, NULL) &&
232 !base::i18n::StringSearchIgnoringCaseAndAccents(
233 term, url_formatted, NULL, NULL) &&
234 !base::i18n::StringSearchIgnoringCaseAndAccents(
235 term, path, NULL, NULL)) {
236 return false;
237 }
238 }
239 return true;
240 }
241
240 DownloadQuery::DownloadQuery() : limit_(kuint32max), skip_(0U) {} 242 DownloadQuery::DownloadQuery() : limit_(kuint32max), skip_(0U) {}
241 DownloadQuery::~DownloadQuery() {} 243 DownloadQuery::~DownloadQuery() {}
242 244
243 // AddFilter() pushes a new FilterCallback to filters_. Most FilterCallbacks are 245 // AddFilter() pushes a new FilterCallback to filters_. Most FilterCallbacks are
244 // Callbacks to FieldMatches<>(). Search() iterates over given DownloadItems, 246 // Callbacks to FieldMatches<>(). Search() iterates over given DownloadItems,
245 // discarding items for which any filter returns false. A DownloadQuery may have 247 // discarding items for which any filter returns false. A DownloadQuery may have
246 // zero or more FilterCallbacks. 248 // zero or more FilterCallbacks.
247 249
248 bool DownloadQuery::AddFilter(const DownloadQuery::FilterCallback& value) { 250 bool DownloadQuery::AddFilter(const DownloadQuery::FilterCallback& value) {
249 if (value.is_null()) return false; 251 if (value.is_null()) return false;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 results->begin() + std::min(limit_ + skip_, results->size()), 441 results->begin() + std::min(limit_ + skip_, results->size()),
440 results->end(), 442 results->end(),
441 DownloadComparator(sorters_)); 443 DownloadComparator(sorters_));
442 } 444 }
443 445
444 results->erase(results->begin(), results->begin() + skip_); 446 results->erase(results->begin(), results->begin() + skip_);
445 447
446 if (results->size() > limit_) 448 if (results->size() > limit_)
447 results->resize(limit_); 449 results->resize(limit_);
448 } 450 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_query.h ('k') | chrome/browser/resources/md_downloads/action_service.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698