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

Side by Side Diff: components/omnibox/answers_cache.cc

Issue 1220653002: Fix some case-insensitive cases for StartsWith (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: grt's review comments, Mac fix Created 5 years, 5 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/omnibox/answers_cache.h" 5 #include "components/omnibox/answers_cache.h"
6 6
7 #include "base/i18n/case_conversion.h"
7 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
8 9
9 AnswersQueryData::AnswersQueryData() { 10 AnswersQueryData::AnswersQueryData() {
10 } 11 }
11 AnswersQueryData::AnswersQueryData(const base::string16& text, 12 AnswersQueryData::AnswersQueryData(const base::string16& text,
12 const base::string16& type) 13 const base::string16& type)
13 : full_query_text(text), query_type(type) { 14 : full_query_text(text), query_type(type) {
14 } 15 }
15 16
16 AnswersCache::AnswersCache(size_t max_entries) : max_entries_(max_entries) { 17 AnswersCache::AnswersCache(size_t max_entries) : max_entries_(max_entries) {
17 } 18 }
18 19
19 AnswersCache::~AnswersCache() { 20 AnswersCache::~AnswersCache() {
20 } 21 }
21 22
22 AnswersQueryData AnswersCache::GetTopAnswerEntry(const base::string16& query) { 23 AnswersQueryData AnswersCache::GetTopAnswerEntry(const base::string16& query) {
23 base::string16 collapsed_query = base::CollapseWhitespace(query, false); 24 base::string16 collapsed_query = base::i18n::ToLower(
25 base::CollapseWhitespace(query, false));
24 for (Cache::iterator it = cache_.begin(); it != cache_.end(); ++it) { 26 for (Cache::iterator it = cache_.begin(); it != cache_.end(); ++it) {
25 // If the query text starts with trimmed input, this is valid prefetch data. 27 // If the query text starts with trimmed input, this is valid prefetch data.
26 if (base::StartsWith(it->full_query_text, collapsed_query, false)) { 28 if (base::StartsWith(base::i18n::ToLower(it->full_query_text),
29 collapsed_query, base::CompareCase::SENSITIVE)) {
27 // Move the touched item to the front of the list. 30 // Move the touched item to the front of the list.
28 cache_.splice(cache_.begin(), cache_, it); 31 cache_.splice(cache_.begin(), cache_, it);
29 return cache_.front(); 32 return cache_.front();
30 } 33 }
31 } 34 }
32 return AnswersQueryData(); 35 return AnswersQueryData();
33 } 36 }
34 37
35 void AnswersCache::UpdateRecentAnswers(const base::string16& full_query_text, 38 void AnswersCache::UpdateRecentAnswers(const base::string16& full_query_text,
36 const base::string16& query_type) { 39 const base::string16& query_type) {
37 // If this entry is already part of the cache, just update recency. 40 // If this entry is already part of the cache, just update recency.
38 for (Cache::iterator it = cache_.begin(); it != cache_.end(); ++it) { 41 for (Cache::iterator it = cache_.begin(); it != cache_.end(); ++it) {
39 if (full_query_text == it->full_query_text && 42 if (full_query_text == it->full_query_text &&
40 query_type == it->query_type) { 43 query_type == it->query_type) {
41 cache_.splice(cache_.begin(), cache_, it); 44 cache_.splice(cache_.begin(), cache_, it);
42 return; 45 return;
43 } 46 }
44 } 47 }
45 48
46 // Evict if cache size is exceeded. 49 // Evict if cache size is exceeded.
47 if (cache_.size() >= max_entries_) 50 if (cache_.size() >= max_entries_)
48 cache_.pop_back(); 51 cache_.pop_back();
49 52
50 cache_.push_front(AnswersQueryData(full_query_text, query_type)); 53 cache_.push_front(AnswersQueryData(full_query_text, query_type));
51 } 54 }
OLDNEW
« no previous file with comments | « components/browser_watcher/exit_code_watcher_win_unittest.cc ('k') | components/omnibox/base_search_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698