Index: chrome/browser/download/download_query.cc |
diff --git a/chrome/browser/download/download_query.cc b/chrome/browser/download/download_query.cc |
index 4b717c6d22812593e41c3c14b602058179c58221..d3ec33e2e7967dd0dac7e3c5bcf73cdd06490867 100644 |
--- a/chrome/browser/download/download_query.cc |
+++ b/chrome/browser/download/download_query.cc |
@@ -69,11 +69,11 @@ template<> bool GetAs(const base::Value& in, std::vector<base::string16>* out) { |
// The next several functions are helpers for making Callbacks that access |
// DownloadItem fields. |
-static int64_t GetStartTimeMsEpoch(const DownloadItem& item) { |
+int64_t GetStartTimeMsEpoch(const DownloadItem& item) { |
return (item.GetStartTime() - base::Time::UnixEpoch()).InMilliseconds(); |
} |
-static int64_t GetEndTimeMsEpoch(const DownloadItem& item) { |
+int64_t GetEndTimeMsEpoch(const DownloadItem& item) { |
return (item.GetEndTime() - base::Time::UnixEpoch()).InMilliseconds(); |
} |
@@ -86,58 +86,62 @@ std::string TimeToISO8601(const base::Time& t) { |
exploded.millisecond); |
} |
-static std::string GetStartTime(const DownloadItem& item) { |
+std::string GetStartTime(const DownloadItem& item) { |
return TimeToISO8601(item.GetStartTime()); |
} |
-static std::string GetEndTime(const DownloadItem& item) { |
+std::string GetEndTime(const DownloadItem& item) { |
return TimeToISO8601(item.GetEndTime()); |
} |
-static bool GetDangerAccepted(const DownloadItem& item) { |
+bool GetDangerAccepted(const DownloadItem& item) { |
return (item.GetDangerType() == |
content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED); |
} |
-static bool GetExists(const DownloadItem& item) { |
+bool GetExists(const DownloadItem& item) { |
return !item.GetFileExternallyRemoved(); |
} |
-static base::string16 GetFilename(const DownloadItem& item) { |
+base::string16 GetFilename(const DownloadItem& item) { |
// This filename will be compared with strings that could be passed in by the |
// user, who only sees LossyDisplayNames. |
return item.GetTargetFilePath().LossyDisplayName(); |
} |
-static std::string GetFilenameUTF8(const DownloadItem& item) { |
+std::string GetFilenameUTF8(const DownloadItem& item) { |
return base::UTF16ToUTF8(GetFilename(item)); |
} |
-static std::string GetUrl(const DownloadItem& item) { |
+std::string GetOriginalUrl(const DownloadItem& item) { |
return item.GetOriginalUrl().spec(); |
} |
-static DownloadItem::DownloadState GetState(const DownloadItem& item) { |
+std::string GetUrl(const DownloadItem& item) { |
+ return item.GetURL().spec(); |
+} |
+ |
+DownloadItem::DownloadState GetState(const DownloadItem& item) { |
return item.GetState(); |
} |
-static DownloadDangerType GetDangerType(const DownloadItem& item) { |
+DownloadDangerType GetDangerType(const DownloadItem& item) { |
return item.GetDangerType(); |
} |
-static int GetReceivedBytes(const DownloadItem& item) { |
+int GetReceivedBytes(const DownloadItem& item) { |
return item.GetReceivedBytes(); |
} |
-static int GetTotalBytes(const DownloadItem& item) { |
+int GetTotalBytes(const DownloadItem& item) { |
return item.GetTotalBytes(); |
} |
-static std::string GetMimeType(const DownloadItem& item) { |
+std::string GetMimeType(const DownloadItem& item) { |
return item.GetMimeType(); |
} |
-static bool IsPaused(const DownloadItem& item) { |
+bool IsPaused(const DownloadItem& item) { |
return item.IsPaused(); |
} |
@@ -148,7 +152,7 @@ enum ComparisonType {LT, EQ, GT}; |
// DownloadItem and returns one of its fields, which is then compared to |
// |value|. |
template<typename ValueType> |
-static bool FieldMatches( |
+bool FieldMatches( |
const ValueType& value, |
ComparisonType cmptype, |
const base::Callback<ValueType(const DownloadItem&)>& accessor, |
@@ -173,7 +177,7 @@ template <typename ValueType> DownloadQuery::FilterCallback BuildFilter( |
} |
// Returns true if |accessor.Run(item)| matches |pattern|. |
-static bool FindRegex( |
+bool FindRegex( |
RE2* pattern, |
const base::Callback<std::string(const DownloadItem&)>& accessor, |
const DownloadItem& item) { |
@@ -195,7 +199,7 @@ DownloadQuery::FilterCallback BuildRegexFilter( |
// Returns a ComparisonType to indicate whether a field in |left| is less than, |
// greater than or equal to the same field in |right|. |
template<typename ValueType> |
-static ComparisonType Compare( |
+ComparisonType Compare( |
const base::Callback<ValueType(const DownloadItem&)>& accessor, |
const DownloadItem& left, const DownloadItem& right) { |
ValueType left_value = accessor.Run(left); |
@@ -214,16 +218,25 @@ bool DownloadQuery::MatchesQuery(const std::vector<base::string16>& query_terms, |
if (query_terms.empty()) |
return true; |
- base::string16 url_raw(base::UTF8ToUTF16(item.GetOriginalUrl().spec())); |
+ base::string16 original_url_raw( |
+ base::UTF8ToUTF16(item.GetOriginalUrl().spec())); |
+ base::string16 original_url_formatted = original_url_raw; |
+ base::string16 url_raw(base::UTF8ToUTF16(item.GetURL().spec())); |
base::string16 url_formatted = url_raw; |
- if (item.GetBrowserContext()) |
- url_formatted = url_formatter::FormatUrl(item.GetOriginalUrl()); |
+ if (item.GetBrowserContext()) { |
asanka
2016/06/22 19:05:14
Download items are indirectly owned by the Browser
mharanczyk
2016/06/23 10:33:21
Done.
mharanczyk
2016/06/23 10:33:21
This is leftover from times when formatter require
|
+ original_url_formatted = url_formatter::FormatUrl(item.GetOriginalUrl()); |
+ url_formatted = url_formatter::FormatUrl(item.GetURL()); |
asanka
2016/06/22 19:05:14
The biggest thing we are doing here is removing un
mharanczyk
2016/06/23 10:33:21
Done.
|
+ } |
base::string16 path(item.GetTargetFilePath().LossyDisplayName()); |
for (std::vector<base::string16>::const_iterator it = query_terms.begin(); |
it != query_terms.end(); ++it) { |
base::string16 term = base::i18n::ToLower(*it); |
if (!base::i18n::StringSearchIgnoringCaseAndAccents( |
+ term, original_url_raw, NULL, NULL) && |
+ !base::i18n::StringSearchIgnoringCaseAndAccents( |
+ term, original_url_formatted, NULL, NULL) && |
+ !base::i18n::StringSearchIgnoringCaseAndAccents( |
term, url_raw, NULL, NULL) && |
!base::i18n::StringSearchIgnoringCaseAndAccents( |
term, url_formatted, NULL, NULL) && |
@@ -300,6 +313,10 @@ bool DownloadQuery::AddFilter(DownloadQuery::FilterType type, |
return AddFilter(BuildFilter<int>(value, GT, &GetTotalBytes)); |
case FILTER_TOTAL_BYTES_LESS: |
return AddFilter(BuildFilter<int>(value, LT, &GetTotalBytes)); |
+ case FILTER_ORIGINAL_URL: |
+ return AddFilter(BuildFilter<std::string>(value, EQ, &GetOriginalUrl)); |
+ case FILTER_ORIGINAL_URL_REGEX: |
+ return AddFilter(BuildRegexFilter(value, &GetOriginalUrl)); |
case FILTER_URL: |
return AddFilter(BuildFilter<std::string>(value, EQ, &GetUrl)); |
case FILTER_URL_REGEX: |
@@ -390,6 +407,10 @@ void DownloadQuery::AddSorter(DownloadQuery::SortType type, |
sorters_.push_back( |
Sorter::Build<int64_t>(direction, &GetStartTimeMsEpoch)); |
break; |
+ case SORT_ORIGINAL_URL: |
+ sorters_.push_back( |
+ Sorter::Build<std::string>(direction, &GetOriginalUrl)); |
+ break; |
case SORT_URL: |
sorters_.push_back(Sorter::Build<std::string>(direction, &GetUrl)); |
break; |