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

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

Issue 77453007: Omnibox: Make HistoryURL Highlight Titles like HistoryQuick Provider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: highlight exact input title too Created 7 years, 1 month 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) 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 "chrome/browser/autocomplete/autocomplete_match.h" 17 #include "chrome/browser/autocomplete/autocomplete_match.h"
18 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" 18 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h"
19 #include "chrome/browser/history/history_backend.h" 19 #include "chrome/browser/history/history_backend.h"
20 #include "chrome/browser/history/history_database.h" 20 #include "chrome/browser/history/history_database.h"
21 #include "chrome/browser/history/history_service.h" 21 #include "chrome/browser/history/history_service.h"
22 #include "chrome/browser/history/history_service_factory.h" 22 #include "chrome/browser/history/history_service_factory.h"
23 #include "chrome/browser/history/history_types.h" 23 #include "chrome/browser/history/history_types.h"
24 #include "chrome/browser/history/in_memory_url_index_types.h"
25 #include "chrome/browser/history/scored_history_match.h"
24 #include "chrome/browser/omnibox/omnibox_field_trial.h" 26 #include "chrome/browser/omnibox/omnibox_field_trial.h"
25 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/search_engines/template_url_service.h" 28 #include "chrome/browser/search_engines/template_url_service.h"
27 #include "chrome/browser/search_engines/template_url_service_factory.h" 29 #include "chrome/browser/search_engines/template_url_service_factory.h"
28 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/net/url_fixer_upper.h" 31 #include "chrome/common/net/url_fixer_upper.h"
30 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
31 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
32 #include "net/base/net_util.h" 34 #include "net/base/net_util.h"
33 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 35 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 return false; 766 return false;
765 case VisitClassifier::UNVISITED_INTRANET: 767 case VisitClassifier::UNVISITED_INTRANET:
766 type = UNVISITED_INTRANET; 768 type = UNVISITED_INTRANET;
767 break; 769 break;
768 default: 770 default:
769 DCHECK_EQ(VisitClassifier::VISITED, classifier.type()); 771 DCHECK_EQ(VisitClassifier::VISITED, classifier.type());
770 // We have data for this match, use it. 772 // We have data for this match, use it.
771 match->deletable = true; 773 match->deletable = true;
772 match->description = classifier.url_row().title(); 774 match->description = classifier.url_row().title();
773 RecordAdditionalInfoFromUrlRow(classifier.url_row(), match); 775 RecordAdditionalInfoFromUrlRow(classifier.url_row(), match);
774 AutocompleteMatch::ClassifyMatchInString( 776 match->description_class =
775 input.text(), 777 ClassifyDescription(input.text(), match->description);
776 classifier.url_row().title(),
777 ACMatchClassification::NONE, &match->description_class);
778 if (!classifier.url_row().typed_count()) { 778 if (!classifier.url_row().typed_count()) {
779 // If we reach here, we must be in the second pass, and we must not have 779 // If we reach here, we must be in the second pass, and we must not have
780 // this row's data available during the first pass. That means we 780 // this row's data available during the first pass. That means we
781 // either scored it as WHAT_YOU_TYPED or UNVISITED_INTRANET, and to 781 // either scored it as WHAT_YOU_TYPED or UNVISITED_INTRANET, and to
782 // maintain the ordering between passes consistent, we need to score it 782 // maintain the ordering between passes consistent, we need to score it
783 // the same way here. 783 // the same way here.
784 type = CanFindIntranetURL(db, input) ? 784 type = CanFindIntranetURL(db, input) ?
785 UNVISITED_INTRANET : WHAT_YOU_TYPED; 785 UNVISITED_INTRANET : WHAT_YOU_TYPED;
786 } 786 }
787 break; 787 break;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 DCHECK(inline_autocomplete_offset > match_start); 1080 DCHECK(inline_autocomplete_offset > match_start);
1081 AutocompleteMatch::ClassifyLocationInString(match_start, 1081 AutocompleteMatch::ClassifyLocationInString(match_start,
1082 inline_autocomplete_offset - match_start, match.contents.length(), 1082 inline_autocomplete_offset - match_start, match.contents.length(),
1083 ACMatchClassification::URL, &match.contents_class); 1083 ACMatchClassification::URL, &match.contents_class);
1084 } else { 1084 } else {
1085 AutocompleteMatch::ClassifyLocationInString(string16::npos, 0, 1085 AutocompleteMatch::ClassifyLocationInString(string16::npos, 0,
1086 match.contents.length(), ACMatchClassification::URL, 1086 match.contents.length(), ACMatchClassification::URL,
1087 &match.contents_class); 1087 &match.contents_class);
1088 } 1088 }
1089 match.description = info.title(); 1089 match.description = info.title();
1090 AutocompleteMatch::ClassifyMatchInString(params.input.text(), 1090 match.description_class =
1091 info.title(), 1091 ClassifyDescription(params.input.text(), match.description);
1092 ACMatchClassification::NONE,
1093 &match.description_class);
1094 RecordAdditionalInfoFromUrlRow(info, &match); 1092 RecordAdditionalInfoFromUrlRow(info, &match);
1095 return match; 1093 return match;
1096 } 1094 }
1095
1096 // static
1097 ACMatchClassifications HistoryURLProvider::ClassifyDescription(
1098 const string16& input_text,
1099 const string16& description) {
1100 string16 clean_description = history::CleanUpTitleForMatching(description);
1101 // Treat the input as a single term. This probably causes no highlighting
1102 // if it's multiple terms such as mail.g. That seems reasonable.
Peter Kasting 2013/11/23 02:15:36 Wait, does this mean "mail.g" will no longer show
Mark P 2013/11/25 19:59:16 If the "title" of the page is "mail.google.com" (w
Peter Kasting 2013/11/26 02:15:36 That does limit the scope of the damage, but it st
Mark P 2013/11/26 20:08:15 While looking at the code to see how I can make it
1103 history::TermMatches description_matches =
Peter Kasting 2013/11/23 02:15:36 Nit: Consider using () instead of = for non-basic
Mark P 2013/11/25 19:59:16 Okay.
1104 history::MatchTermInString(input_text, clean_description, 0);
1105 description_matches = SortAndDeoverlapMatches(description_matches);
Peter Kasting 2013/11/23 02:15:36 Nit: Combine with previous line
Mark P 2013/11/25 19:59:16 Done.
1106 history::WordStarts description_word_starts;
1107 history::String16VectorFromString16(
1108 clean_description, false, &description_word_starts);
1109 description_matches = history::ScoredHistoryMatch::
Peter Kasting 2013/11/23 02:15:36 Nit: If we break after '=' can we avoid breaking a
Mark P 2013/11/25 19:59:16 Yes. Done.
1110 FilterTermMatchesByWordStarts(
1111 description_matches, description_word_starts, 0);
1112 return SpansFromTermMatch(
1113 description_matches, clean_description.length(), false);
1114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698