OLD | NEW |
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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/i18n/case_conversion.h" | 14 #include "base/i18n/case_conversion.h" |
15 #include "base/i18n/string_search.h" | 15 #include "base/i18n/string_search.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/prefs/pref_service.h" | 18 #include "base/prefs/pref_service.h" |
19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
21 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
25 #include "base/values.h" | 25 #include "base/values.h" |
26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 28 #include "components/url_formatter/url_formatter.h" |
28 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
29 #include "content/public/browser/download_item.h" | 30 #include "content/public/browser/download_item.h" |
30 #include "net/base/net_util.h" | |
31 #include "third_party/re2/re2/re2.h" | 31 #include "third_party/re2/re2/re2.h" |
32 #include "url/gurl.h" | 32 #include "url/gurl.h" |
33 | 33 |
34 using content::DownloadDangerType; | 34 using content::DownloadDangerType; |
35 using content::DownloadItem; | 35 using content::DownloadItem; |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // Templatized base::Value::GetAs*(). | 39 // Templatized base::Value::GetAs*(). |
40 template <typename T> bool GetAs(const base::Value& in, T* out); | 40 template <typename T> bool GetAs(const base::Value& in, T* out); |
(...skipping 29 matching lines...) Expand all Loading... |
70 // DownloadItem fields. | 70 // DownloadItem fields. |
71 | 71 |
72 static bool MatchesQuery( | 72 static bool MatchesQuery( |
73 const std::vector<base::string16>& query_terms, | 73 const std::vector<base::string16>& query_terms, |
74 const DownloadItem& item) { | 74 const DownloadItem& item) { |
75 DCHECK(!query_terms.empty()); | 75 DCHECK(!query_terms.empty()); |
76 base::string16 url_raw(base::UTF8ToUTF16(item.GetOriginalUrl().spec())); | 76 base::string16 url_raw(base::UTF8ToUTF16(item.GetOriginalUrl().spec())); |
77 base::string16 url_formatted = url_raw; | 77 base::string16 url_formatted = url_raw; |
78 if (item.GetBrowserContext()) { | 78 if (item.GetBrowserContext()) { |
79 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext()); | 79 Profile* profile = Profile::FromBrowserContext(item.GetBrowserContext()); |
80 url_formatted = net::FormatUrl( | 80 url_formatted = url_formatter::FormatUrl( |
81 item.GetOriginalUrl(), | 81 item.GetOriginalUrl(), |
82 profile->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 82 profile->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
83 } | 83 } |
84 base::string16 path(item.GetTargetFilePath().LossyDisplayName()); | 84 base::string16 path(item.GetTargetFilePath().LossyDisplayName()); |
85 | 85 |
86 for (std::vector<base::string16>::const_iterator it = query_terms.begin(); | 86 for (std::vector<base::string16>::const_iterator it = query_terms.begin(); |
87 it != query_terms.end(); ++it) { | 87 it != query_terms.end(); ++it) { |
88 base::string16 term = base::i18n::ToLower(*it); | 88 base::string16 term = base::i18n::ToLower(*it); |
89 if (!base::i18n::StringSearchIgnoringCaseAndAccents( | 89 if (!base::i18n::StringSearchIgnoringCaseAndAccents( |
90 term, url_raw, NULL, NULL) && | 90 term, url_raw, NULL, NULL) && |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 433 |
434 void DownloadQuery::FinishSearch(DownloadQuery::DownloadVector* results) const { | 434 void DownloadQuery::FinishSearch(DownloadQuery::DownloadVector* results) const { |
435 if (!sorters_.empty()) | 435 if (!sorters_.empty()) |
436 std::partial_sort(results->begin(), | 436 std::partial_sort(results->begin(), |
437 results->begin() + std::min(limit_, results->size()), | 437 results->begin() + std::min(limit_, results->size()), |
438 results->end(), | 438 results->end(), |
439 DownloadComparator(sorters_)); | 439 DownloadComparator(sorters_)); |
440 if (results->size() > limit_) | 440 if (results->size() > limit_) |
441 results->resize(limit_); | 441 results->resize(limit_); |
442 } | 442 } |
OLD | NEW |