OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/histogram.h" | 7 #include "base/histogram.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
10 #include "chrome/browser/history/query_parser.h" | 10 #include "chrome/browser/history/query_parser.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 } | 243 } |
244 if (offset != result.title().size()) { | 244 if (offset != result.title().size()) { |
245 match->description_class.push_back( | 245 match->description_class.push_back( |
246 ACMatchClassification(offset, ACMatchClassification::NONE)); | 246 ACMatchClassification(offset, ACMatchClassification::NONE)); |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 int HistoryContentsProvider::CalculateRelevance( | 250 int HistoryContentsProvider::CalculateRelevance( |
251 const history::URLResult& result) { | 251 const history::URLResult& result) { |
252 const bool in_title = MatchInTitle(result); | 252 const bool in_title = MatchInTitle(result); |
253 const bool is_starred = | 253 if (!profile_->GetBookmarkModel() || |
254 (profile_->GetBookmarkModel() && | 254 !profile_->GetBookmarkModel()->IsBookmarked(result.url())) |
255 profile_->GetBookmarkModel()->IsBookmarked(result.url())); | 255 return in_title ? (700 + title_count_++) : (500 + contents_count_++); |
256 | 256 return in_title ? |
257 switch (input_type_) { | 257 (1000 + star_title_count_++) : (550 + star_contents_count_++); |
258 case AutocompleteInput::UNKNOWN: | |
259 case AutocompleteInput::REQUESTED_URL: | |
260 if (is_starred) { | |
261 return in_title ? | |
262 (1000 + star_title_count_++) : (550 + star_contents_count_++); | |
263 } | |
264 return in_title ? (700 + title_count_++) : (500 + contents_count_++); | |
265 | |
266 case AutocompleteInput::QUERY: | |
267 case AutocompleteInput::FORCED_QUERY: | |
268 if (is_starred) { | |
269 return in_title ? | |
270 (1200 + star_title_count_++) : (750 + star_contents_count_++); | |
271 } | |
272 return in_title ? (900 + title_count_++) : (700 + contents_count_++); | |
273 | |
274 default: | |
275 NOTREACHED(); | |
276 return 0; | |
277 } | |
278 } | 258 } |
279 | 259 |
280 void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { | 260 void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { |
281 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); | 261 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); |
282 if (!bookmark_model) | 262 if (!bookmark_model) |
283 return; | 263 return; |
284 | 264 |
285 DCHECK(results_.empty()); | 265 DCHECK(results_.empty()); |
286 | 266 |
287 TimeTicks start_time = TimeTicks::Now(); | 267 TimeTicks start_time = TimeTicks::Now(); |
288 std::vector<bookmark_utils::TitleMatch> matches; | 268 std::vector<bookmark_utils::TitleMatch> matches; |
289 bookmark_model->GetBookmarksWithTitlesMatching(input.text(), max_matches(), | 269 bookmark_model->GetBookmarksWithTitlesMatching(input.text(), max_matches(), |
290 &matches); | 270 &matches); |
291 for (size_t i = 0; i < matches.size(); ++i) | 271 for (size_t i = 0; i < matches.size(); ++i) |
292 AddBookmarkTitleMatchToResults(matches[i]); | 272 AddBookmarkTitleMatchToResults(matches[i]); |
293 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", | 273 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", |
294 TimeTicks::Now() - start_time); | 274 TimeTicks::Now() - start_time); |
295 } | 275 } |
296 | 276 |
297 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( | 277 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( |
298 const bookmark_utils::TitleMatch& match) { | 278 const bookmark_utils::TitleMatch& match) { |
299 history::URLResult url_result(match.node->GetURL(), match.match_positions); | 279 history::URLResult url_result(match.node->GetURL(), match.match_positions); |
300 url_result.set_title(match.node->GetTitle()); | 280 url_result.set_title(match.node->GetTitle()); |
301 results_.AppendURLBySwapping(&url_result); | 281 results_.AppendURLBySwapping(&url_result); |
302 } | 282 } |
OLD | NEW |