| OLD | NEW |
| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 // Want results in reverse-chronological order all else being equal. | 46 // Want results in reverse-chronological order all else being equal. |
| 47 return a.result->last_visit() > b.result->last_visit(); | 47 return a.result->last_visit() > b.result->last_visit(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 using history::HistoryDatabase; | 52 using history::HistoryDatabase; |
| 53 | 53 |
| 54 HistoryContentsProvider::HistoryContentsProvider(ACProviderListener* listener, | 54 HistoryContentsProvider::HistoryContentsProvider(ACProviderListener* listener, |
| 55 Profile* profile) | 55 Profile* profile) |
| 56 : AutocompleteProvider(listener, profile, "HistoryContents"), | 56 : HistoryProvider(listener, profile, "HistoryContents"), |
| 57 star_title_count_(0), | 57 star_title_count_(0), |
| 58 star_contents_count_(0), | 58 star_contents_count_(0), |
| 59 title_count_(0), | 59 title_count_(0), |
| 60 contents_count_(0), | 60 contents_count_(0), |
| 61 input_type_(AutocompleteInput::INVALID), | 61 input_type_(AutocompleteInput::INVALID), |
| 62 trim_http_(false), | 62 trim_http_(false), |
| 63 have_results_(false) { | 63 have_results_(false) { |
| 64 } | 64 } |
| 65 | 65 |
| 66 void HistoryContentsProvider::Start(const AutocompleteInput& input, | 66 void HistoryContentsProvider::Start(const AutocompleteInput& input, |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 | 215 |
| 216 static bool MatchInTitle(const history::URLResult& result) { | 216 static bool MatchInTitle(const history::URLResult& result) { |
| 217 return !result.title_match_positions().empty(); | 217 return !result.title_match_positions().empty(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 AutocompleteMatch HistoryContentsProvider::ResultToMatch( | 220 AutocompleteMatch HistoryContentsProvider::ResultToMatch( |
| 221 const history::URLResult& result, | 221 const history::URLResult& result, |
| 222 int score) { | 222 int score) { |
| 223 // TODO(sky): if matched title highlight matching words in title. | 223 // TODO(sky): if matched title highlight matching words in title. |
| 224 // Also show star in popup. | 224 // Also show star in popup. |
| 225 AutocompleteMatch match(this, score, false, MatchInTitle(result) ? | 225 AutocompleteMatch match(this, score, true, MatchInTitle(result) ? |
| 226 AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY); | 226 AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY); |
| 227 match.contents = StringForURLDisplay(result.url(), true, trim_http_); | 227 match.contents = StringForURLDisplay(result.url(), true, trim_http_); |
| 228 match.fill_into_edit = | 228 match.fill_into_edit = |
| 229 AutocompleteInput::FormattedStringWithEquivalentMeaning(result.url(), | 229 AutocompleteInput::FormattedStringWithEquivalentMeaning(result.url(), |
| 230 match.contents); | 230 match.contents); |
| 231 match.destination_url = result.url(); | 231 match.destination_url = result.url(); |
| 232 match.contents_class.push_back( | 232 match.contents_class.push_back( |
| 233 ACMatchClassification(0, ACMatchClassification::URL)); | 233 ACMatchClassification(0, ACMatchClassification::URL)); |
| 234 match.description = UTF16ToWide(result.title()); | 234 match.description = UTF16ToWide(result.title()); |
| 235 match.starred = | 235 match.starred = |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", | 291 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", |
| 292 TimeTicks::Now() - start_time); | 292 TimeTicks::Now() - start_time); |
| 293 } | 293 } |
| 294 | 294 |
| 295 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( | 295 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( |
| 296 const bookmark_utils::TitleMatch& match) { | 296 const bookmark_utils::TitleMatch& match) { |
| 297 history::URLResult url_result(match.node->GetURL(), match.match_positions); | 297 history::URLResult url_result(match.node->GetURL(), match.match_positions); |
| 298 url_result.set_title(match.node->GetTitle()); | 298 url_result.set_title(match.node->GetTitle()); |
| 299 results_.AppendURLBySwapping(&url_result); | 299 results_.AppendURLBySwapping(&url_result); |
| 300 } | 300 } |
| OLD | NEW |