OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 18 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
19 #include "chrome/browser/autocomplete/in_memory_url_index_types.h" | 19 #include "chrome/browser/autocomplete/in_memory_url_index_types.h" |
20 #include "chrome/browser/autocomplete/scored_history_match_builder_impl.h" | 20 #include "chrome/browser/autocomplete/scored_history_match.h" |
21 #include "chrome/browser/history/history_service_factory.h" | 21 #include "chrome/browser/history/history_service_factory.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/search_engines/template_url_service_factory.h" | 23 #include "chrome/browser/search_engines/template_url_service_factory.h" |
24 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 24 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
28 #include "components/bookmarks/browser/bookmark_utils.h" | 28 #include "components/bookmarks/browser/bookmark_utils.h" |
29 #include "components/history/core/browser/history_backend.h" | 29 #include "components/history/core/browser/history_backend.h" |
30 #include "components/history/core/browser/history_database.h" | 30 #include "components/history/core/browser/history_database.h" |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 base::string16 clean_description = | 707 base::string16 clean_description = |
708 bookmarks::CleanUpTitleForMatching(description); | 708 bookmarks::CleanUpTitleForMatching(description); |
709 TermMatches description_matches(SortAndDeoverlapMatches( | 709 TermMatches description_matches(SortAndDeoverlapMatches( |
710 MatchTermInString(input_text, clean_description, 0))); | 710 MatchTermInString(input_text, clean_description, 0))); |
711 WordStarts description_word_starts; | 711 WordStarts description_word_starts; |
712 String16VectorFromString16(clean_description, false, | 712 String16VectorFromString16(clean_description, false, |
713 &description_word_starts); | 713 &description_word_starts); |
714 // If HistoryURL retrieves any matches (and hence we reach this code), we | 714 // If HistoryURL retrieves any matches (and hence we reach this code), we |
715 // are guaranteed that the beginning of input_text must be a word break. | 715 // are guaranteed that the beginning of input_text must be a word break. |
716 WordStarts offsets(1, 0u); | 716 WordStarts offsets(1, 0u); |
717 description_matches = | 717 description_matches = ScoredHistoryMatch::FilterTermMatchesByWordStarts( |
718 ScoredHistoryMatchBuilderImpl::FilterTermMatchesByWordStarts( | 718 description_matches, offsets, description_word_starts, 0, |
719 description_matches, offsets, description_word_starts, 0, | 719 std::string::npos); |
720 std::string::npos); | |
721 return SpansFromTermMatch( | 720 return SpansFromTermMatch( |
722 description_matches, clean_description.length(), false); | 721 description_matches, clean_description.length(), false); |
723 } | 722 } |
724 | 723 |
725 void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, | 724 void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, |
726 history::URLDatabase* db, | 725 history::URLDatabase* db, |
727 HistoryURLProviderParams* params) { | 726 HistoryURLProviderParams* params) { |
728 // Get the matching URLs from the DB. | 727 // Get the matching URLs from the DB. |
729 params->matches.clear(); | 728 params->matches.clear(); |
730 history::URLRows url_matches; | 729 history::URLRows url_matches; |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, | 1152 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, |
1154 match.contents.length(), ACMatchClassification::URL, | 1153 match.contents.length(), ACMatchClassification::URL, |
1155 &match.contents_class); | 1154 &match.contents_class); |
1156 } | 1155 } |
1157 match.description = info.title(); | 1156 match.description = info.title(); |
1158 match.description_class = | 1157 match.description_class = |
1159 ClassifyDescription(params.input.text(), match.description); | 1158 ClassifyDescription(params.input.text(), match.description); |
1160 RecordAdditionalInfoFromUrlRow(info, &match); | 1159 RecordAdditionalInfoFromUrlRow(info, &match); |
1161 return match; | 1160 return match; |
1162 } | 1161 } |
OLD | NEW |