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

Side by Side Diff: chrome/browser/autocomplete/history_contents_provider.cc

Issue 6268005: Removes the link in the omnibox for searching history. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/autocomplete/history_contents_provider.h" 5 #include "chrome/browser/autocomplete/history_contents_provider.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 ConvertResults(); 126 ConvertResults();
127 127
128 if (!input.synchronous_only()) { 128 if (!input.synchronous_only()) {
129 HistoryService* history = 129 HistoryService* history =
130 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 130 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
131 if (history) { 131 if (history) {
132 done_ = false; 132 done_ = false;
133 133
134 history::QueryOptions options; 134 history::QueryOptions options;
135 options.SetRecentDayRange(kDaysToSearch); 135 options.SetRecentDayRange(kDaysToSearch);
136 options.max_count = kMaxMatchCount; 136 options.max_count = kMaxMatches;
137 history->QueryHistory(WideToUTF16(input.text()), options, 137 history->QueryHistory(WideToUTF16(input.text()), options,
138 &request_consumer_, 138 &request_consumer_,
139 NewCallback(this, &HistoryContentsProvider::QueryComplete)); 139 NewCallback(this, &HistoryContentsProvider::QueryComplete));
140 } 140 }
141 } 141 }
142 } 142 }
143 143
144 void HistoryContentsProvider::Stop() { 144 void HistoryContentsProvider::Stop() {
145 done_ = true; 145 done_ = true;
146 request_consumer_.CancelAllRequests(); 146 request_consumer_.CancelAllRequests();
(...skipping 29 matching lines...) Expand all
176 176
177 // Results are sorted in decreasing order so we run the loop backwards so that 177 // Results are sorted in decreasing order so we run the loop backwards so that
178 // the relevance increment favors the higher ranked results. 178 // the relevance increment favors the higher ranked results.
179 for (std::vector<history::URLResult*>::const_reverse_iterator i = 179 for (std::vector<history::URLResult*>::const_reverse_iterator i =
180 results_.rbegin(); i != results_.rend(); ++i) { 180 results_.rbegin(); i != results_.rend(); ++i) {
181 history::URLResult* result = *i; 181 history::URLResult* result = *i;
182 MatchReference ref(result, CalculateRelevance(*result)); 182 MatchReference ref(result, CalculateRelevance(*result));
183 result_refs.push_back(ref); 183 result_refs.push_back(ref);
184 } 184 }
185 185
186 // Get the top matches and add them. Always do max number of matches the popup 186 // Get the top matches and add them.
187 // will show plus one. This ensures that if the other providers provide the
188 // exact same set of results, and the db only has max_matches + 1 results
189 // available for this query, we know the last one.
190 //
191 // This is done to avoid having the history search shortcut show
192 // 'See 1 previously viewed ...'.
193 //
194 // Note that AutocompleteResult::kMaxMatches (maximum size of the popup)
195 // is different than both kMaxMatches (the provider's maximum) and
196 // kMaxMatchCount (the number of items we want from the history).
197 size_t max_for_popup = std::min(AutocompleteResult::kMaxMatches + 1,
198 result_refs.size());
199 size_t max_for_provider = std::min(kMaxMatches, result_refs.size()); 187 size_t max_for_provider = std::min(kMaxMatches, result_refs.size());
200 std::partial_sort(result_refs.begin(), result_refs.begin() + max_for_popup, 188 std::partial_sort(result_refs.begin(), result_refs.begin() + max_for_provider,
201 result_refs.end(), &CompareMatchRelevance); 189 result_refs.end(), &CompareMatchRelevance);
202 matches_.clear(); 190 matches_.clear();
203 for (size_t i = 0; i < max_for_popup; i++) { 191 for (size_t i = 0; i < max_for_provider; i++) {
204 matches_.push_back(ResultToMatch(*result_refs[i].result, 192 matches_.push_back(ResultToMatch(*result_refs[i].result,
205 result_refs[i].relevance)); 193 result_refs[i].relevance));
206 } 194 }
207
208 // We made more matches than the autocomplete service requested for this
209 // provider (see previous comment). We invert the weights for the items
210 // we want to get removed, but preserve their magnitude which will be used
211 // to fill them in with our other results.
212 for (size_t i = max_for_provider; i < max_for_popup; i++)
213 matches_[i].relevance = -matches_[i].relevance;
214 } 195 }
215 196
216 static bool MatchInTitle(const history::URLResult& result) { 197 static bool MatchInTitle(const history::URLResult& result) {
217 return !result.title_match_positions().empty(); 198 return !result.title_match_positions().empty();
218 } 199 }
219 200
220 AutocompleteMatch HistoryContentsProvider::ResultToMatch( 201 AutocompleteMatch HistoryContentsProvider::ResultToMatch(
221 const history::URLResult& result, 202 const history::URLResult& result,
222 int score) { 203 int score) {
223 // TODO(sky): if matched title highlight matching words in title. 204 // TODO(sky): if matched title highlight matching words in title.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", 272 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime",
292 TimeTicks::Now() - start_time); 273 TimeTicks::Now() - start_time);
293 } 274 }
294 275
295 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( 276 void HistoryContentsProvider::AddBookmarkTitleMatchToResults(
296 const bookmark_utils::TitleMatch& match) { 277 const bookmark_utils::TitleMatch& match) {
297 history::URLResult url_result(match.node->GetURL(), match.match_positions); 278 history::URLResult url_result(match.node->GetURL(), match.match_positions);
298 url_result.set_title(match.node->GetTitle()); 279 url_result.set_title(match.node->GetTitle());
299 results_.AppendURLBySwapping(&url_result); 280 results_.AppendURLBySwapping(&url_result);
300 } 281 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_contents_provider.h ('k') | chrome/browser/ui/gtk/gtk_theme_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698