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

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

Issue 2013008: Remove --omnibox-popup-count flag. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: nits Created 10 years, 7 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 (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/histogram.h" 8 #include "base/histogram.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "chrome/browser/bookmarks/bookmark_model.h" 10 #include "chrome/browser/bookmarks/bookmark_model.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 167 }
168 168
169 // Get the top matches and add them. Always do max number of matches the popup 169 // Get the top matches and add them. Always do max number of matches the popup
170 // will show plus one. This ensures that if the other providers provide the 170 // will show plus one. This ensures that if the other providers provide the
171 // exact same set of results, and the db only has max_matches + 1 results 171 // exact same set of results, and the db only has max_matches + 1 results
172 // available for this query, we know the last one. 172 // available for this query, we know the last one.
173 // 173 //
174 // This is done to avoid having the history search shortcut show 174 // This is done to avoid having the history search shortcut show
175 // 'See 1 previously viewed ...'. 175 // 'See 1 previously viewed ...'.
176 // 176 //
177 // Note that AutocompleteResult::max_matches() (maximum size of the popup) 177 // Note that AutocompleteResult::kMaxMatches (maximum size of the popup)
178 // is different than both max_matches (the provider's maximum) and 178 // is different than both kMaxMatches (the provider's maximum) and
179 // kMaxMatchCount (the number of items we want from the history). 179 // kMaxMatchCount (the number of items we want from the history).
180 size_t max_for_popup = std::min(AutocompleteResult::max_matches() + 1, 180 size_t max_for_popup = std::min(AutocompleteResult::kMaxMatches + 1,
181 result_refs.size()); 181 result_refs.size());
182 size_t max_for_provider = std::min(max_matches(), result_refs.size()); 182 size_t max_for_provider = std::min(kMaxMatches, result_refs.size());
183 std::partial_sort(result_refs.begin(), result_refs.begin() + max_for_popup, 183 std::partial_sort(result_refs.begin(), result_refs.begin() + max_for_popup,
184 result_refs.end(), &CompareMatchRelevance); 184 result_refs.end(), &CompareMatchRelevance);
185 matches_.clear(); 185 matches_.clear();
186 for (size_t i = 0; i < max_for_popup; i++) { 186 for (size_t i = 0; i < max_for_popup; i++) {
187 matches_.push_back(ResultToMatch(*result_refs[i].result, 187 matches_.push_back(ResultToMatch(*result_refs[i].result,
188 result_refs[i].relevance)); 188 result_refs[i].relevance));
189 } 189 }
190 190
191 // We made more matches than the autocomplete service requested for this 191 // We made more matches than the autocomplete service requested for this
192 // provider (see previous comment). We invert the weights for the items 192 // provider (see previous comment). We invert the weights for the items
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { 259 void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) {
260 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); 260 BookmarkModel* bookmark_model = profile_->GetBookmarkModel();
261 if (!bookmark_model) 261 if (!bookmark_model)
262 return; 262 return;
263 263
264 DCHECK(results_.empty()); 264 DCHECK(results_.empty());
265 265
266 TimeTicks start_time = TimeTicks::Now(); 266 TimeTicks start_time = TimeTicks::Now();
267 std::vector<bookmark_utils::TitleMatch> matches; 267 std::vector<bookmark_utils::TitleMatch> matches;
268 bookmark_model->GetBookmarksWithTitlesMatching(input.text(), max_matches(), 268 bookmark_model->GetBookmarksWithTitlesMatching(input.text(), kMaxMatches,
269 &matches); 269 &matches);
270 for (size_t i = 0; i < matches.size(); ++i) 270 for (size_t i = 0; i < matches.size(); ++i)
271 AddBookmarkTitleMatchToResults(matches[i]); 271 AddBookmarkTitleMatchToResults(matches[i]);
272 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", 272 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime",
273 TimeTicks::Now() - start_time); 273 TimeTicks::Now() - start_time);
274 } 274 }
275 275
276 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( 276 void HistoryContentsProvider::AddBookmarkTitleMatchToResults(
277 const bookmark_utils::TitleMatch& match) { 277 const bookmark_utils::TitleMatch& match) {
278 history::URLResult url_result(match.node->GetURL(), match.match_positions); 278 history::URLResult url_result(match.node->GetURL(), match.match_positions);
279 url_result.set_title(match.node->GetTitle()); 279 url_result.set_title(match.node->GetTitle());
280 results_.AppendURLBySwapping(&url_result); 280 results_.AppendURLBySwapping(&url_result);
281 } 281 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete.cc ('k') | chrome/browser/autocomplete/history_url_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698