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

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

Issue 105193002: Replace string16 with base::string16. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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 29 matching lines...) Expand all
40 template <typename T> bool GetAs(const base::Value& in, T* out); 40 template <typename T> bool GetAs(const base::Value& in, T* out);
41 template<> bool GetAs(const base::Value& in, bool* out) { 41 template<> bool GetAs(const base::Value& in, bool* out) {
42 return in.GetAsBoolean(out); 42 return in.GetAsBoolean(out);
43 } 43 }
44 template<> bool GetAs(const base::Value& in, int* out) { 44 template<> bool GetAs(const base::Value& in, int* out) {
45 return in.GetAsInteger(out); 45 return in.GetAsInteger(out);
46 } 46 }
47 template<> bool GetAs(const base::Value& in, std::string* out) { 47 template<> bool GetAs(const base::Value& in, std::string* out) {
48 return in.GetAsString(out); 48 return in.GetAsString(out);
49 } 49 }
50 template<> bool GetAs(const base::Value& in, string16* out) { 50 template<> bool GetAs(const base::Value& in, base::string16* out) {
51 return in.GetAsString(out); 51 return in.GetAsString(out);
52 } 52 }
53 template<> bool GetAs(const base::Value& in, std::vector<string16>* out) { 53 template<> bool GetAs(const base::Value& in, std::vector<string16>* out) {
54 out->clear(); 54 out->clear();
55 const base::ListValue* list = NULL; 55 const base::ListValue* list = NULL;
56 if (!in.GetAsList(&list)) 56 if (!in.GetAsList(&list))
57 return false; 57 return false;
58 for (size_t i = 0; i < list->GetSize(); ++i) { 58 for (size_t i = 0; i < list->GetSize(); ++i) {
59 string16 element; 59 base::string16 element;
60 if (!list->GetString(i, &element)) { 60 if (!list->GetString(i, &element)) {
61 out->clear(); 61 out->clear();
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( 72 static bool MatchesQuery(
73 const std::vector<string16>& query_terms, 73 const std::vector<string16>& query_terms,
74 const DownloadItem& item) { 74 const DownloadItem& item) {
75 DCHECK(!query_terms.empty()); 75 DCHECK(!query_terms.empty());
76 string16 url_raw(UTF8ToUTF16(item.GetOriginalUrl().spec())); 76 base::string16 url_raw(UTF8ToUTF16(item.GetOriginalUrl().spec()));
77 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 = net::FormatUrl(
81 item.GetOriginalUrl(), 81 item.GetOriginalUrl(),
82 profile->GetPrefs()->GetString(prefs::kAcceptLanguages)); 82 profile->GetPrefs()->GetString(prefs::kAcceptLanguages));
83 } 83 }
84 string16 path(item.GetTargetFilePath().LossyDisplayName()); 84 base::string16 path(item.GetTargetFilePath().LossyDisplayName());
85 85
86 for (std::vector<string16>::const_iterator it = query_terms.begin(); 86 for (std::vector<string16>::const_iterator it = query_terms.begin();
87 it != query_terms.end(); ++it) { 87 it != query_terms.end(); ++it) {
88 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) &&
91 !base::i18n::StringSearchIgnoringCaseAndAccents( 91 !base::i18n::StringSearchIgnoringCaseAndAccents(
92 term, url_formatted, NULL, NULL) && 92 term, url_formatted, NULL, NULL) &&
93 !base::i18n::StringSearchIgnoringCaseAndAccents( 93 !base::i18n::StringSearchIgnoringCaseAndAccents(
94 term, path, NULL, NULL)) { 94 term, path, NULL, NULL)) {
95 return false; 95 return false;
96 } 96 }
97 } 97 }
98 return true; 98 return true;
(...skipping 26 matching lines...) Expand all
125 125
126 static bool GetDangerAccepted(const DownloadItem& item) { 126 static bool GetDangerAccepted(const DownloadItem& item) {
127 return (item.GetDangerType() == 127 return (item.GetDangerType() ==
128 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED); 128 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED);
129 } 129 }
130 130
131 static bool GetExists(const DownloadItem& item) { 131 static bool GetExists(const DownloadItem& item) {
132 return !item.GetFileExternallyRemoved(); 132 return !item.GetFileExternallyRemoved();
133 } 133 }
134 134
135 static string16 GetFilename(const DownloadItem& item) { 135 static base::string16 GetFilename(const DownloadItem& item) {
136 // This filename will be compared with strings that could be passed in by the 136 // This filename will be compared with strings that could be passed in by the
137 // user, who only sees LossyDisplayNames. 137 // user, who only sees LossyDisplayNames.
138 return item.GetTargetFilePath().LossyDisplayName(); 138 return item.GetTargetFilePath().LossyDisplayName();
139 } 139 }
140 140
141 static std::string GetFilenameUTF8(const DownloadItem& item) { 141 static std::string GetFilenameUTF8(const DownloadItem& item) {
142 return UTF16ToUTF8(GetFilename(item)); 142 return UTF16ToUTF8(GetFilename(item));
143 } 143 }
144 144
145 static std::string GetUrl(const DownloadItem& item) { 145 static std::string GetUrl(const DownloadItem& item) {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 432
433 void DownloadQuery::FinishSearch(DownloadQuery::DownloadVector* results) const { 433 void DownloadQuery::FinishSearch(DownloadQuery::DownloadVector* results) const {
434 if (!sorters_.empty()) 434 if (!sorters_.empty())
435 std::partial_sort(results->begin(), 435 std::partial_sort(results->begin(),
436 results->begin() + std::min(limit_, results->size()), 436 results->begin() + std::min(limit_, results->size()),
437 results->end(), 437 results->end(),
438 DownloadComparator(sorters_)); 438 DownloadComparator(sorters_));
439 if (results->size() > limit_) 439 if (results->size() > limit_)
440 results->resize(limit_); 440 results->resize(limit_);
441 } 441 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_item_model_unittest.cc ('k') | chrome/browser/download/download_query_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698