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

Side by Side Diff: components/omnibox/browser/history_url_provider.cc

Issue 1841653003: Drop |languages| from {Format,Elide}Url* and IDNToUnicode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo in elide_url.cc Created 4 years, 8 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) 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 "components/omnibox/browser/history_url_provider.h" 5 #include "components/omnibox/browser/history_url_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 // different port and/or path) before. 416 // different port and/or path) before.
417 url_row_ = history::URLRow(url); 417 url_row_ = history::URLRow(url);
418 type_ = UNVISITED_INTRANET; 418 type_ = UNVISITED_INTRANET;
419 } 419 }
420 } 420 }
421 421
422 HistoryURLProviderParams::HistoryURLProviderParams( 422 HistoryURLProviderParams::HistoryURLProviderParams(
423 const AutocompleteInput& input, 423 const AutocompleteInput& input,
424 bool trim_http, 424 bool trim_http,
425 const AutocompleteMatch& what_you_typed_match, 425 const AutocompleteMatch& what_you_typed_match,
426 const std::string& languages,
427 TemplateURL* default_search_provider, 426 TemplateURL* default_search_provider,
428 const SearchTermsData& search_terms_data) 427 const SearchTermsData& search_terms_data)
429 : message_loop(base::MessageLoop::current()), 428 : message_loop(base::MessageLoop::current()),
430 input(input), 429 input(input),
431 prevent_inline_autocomplete(input.prevent_inline_autocomplete()), 430 prevent_inline_autocomplete(input.prevent_inline_autocomplete()),
432 trim_http(trim_http), 431 trim_http(trim_http),
433 what_you_typed_match(what_you_typed_match), 432 what_you_typed_match(what_you_typed_match),
434 failed(false), 433 failed(false),
435 exact_suggestion_is_in_history(false), 434 exact_suggestion_is_in_history(false),
436 promote_type(NEITHER), 435 promote_type(NEITHER),
437 languages(languages),
438 default_search_provider(default_search_provider ? 436 default_search_provider(default_search_provider ?
439 new TemplateURL(default_search_provider->data()) : NULL), 437 new TemplateURL(default_search_provider->data()) : NULL),
440 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) { 438 search_terms_data(new SearchTermsDataSnapshot(search_terms_data)) {
441 } 439 }
442 440
443 HistoryURLProviderParams::~HistoryURLProviderParams() { 441 HistoryURLProviderParams::~HistoryURLProviderParams() {
444 } 442 }
445 443
446 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client, 444 HistoryURLProvider::HistoryURLProvider(AutocompleteProviderClient* client,
447 AutocompleteProviderListener* listener) 445 AutocompleteProviderListener* listener)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 // thread. |template_url_service| can be NULL when testing. 509 // thread. |template_url_service| can be NULL when testing.
512 TemplateURLService* template_url_service = client()->GetTemplateURLService(); 510 TemplateURLService* template_url_service = client()->GetTemplateURLService();
513 TemplateURL* default_search_provider = template_url_service ? 511 TemplateURL* default_search_provider = template_url_service ?
514 template_url_service->GetDefaultSearchProvider() : NULL; 512 template_url_service->GetDefaultSearchProvider() : NULL;
515 513
516 // Create the data structure for the autocomplete passes. We'll save this off 514 // Create the data structure for the autocomplete passes. We'll save this off
517 // onto the |params_| member for later deletion below if we need to run pass 515 // onto the |params_| member for later deletion below if we need to run pass
518 // 2. 516 // 2.
519 scoped_ptr<HistoryURLProviderParams> params(new HistoryURLProviderParams( 517 scoped_ptr<HistoryURLProviderParams> params(new HistoryURLProviderParams(
520 fixed_up_input, trim_http, what_you_typed_match, 518 fixed_up_input, trim_http, what_you_typed_match,
521 client()->GetAcceptLanguages(), default_search_provider, 519 default_search_provider, client()->GetSearchTermsData()));
522 client()->GetSearchTermsData()));
523 // Note that we use the non-fixed-up input here, since fixup may strip 520 // Note that we use the non-fixed-up input here, since fixup may strip
524 // trailing whitespace. 521 // trailing whitespace.
525 params->prevent_inline_autocomplete = PreventInlineAutocomplete(input); 522 params->prevent_inline_autocomplete = PreventInlineAutocomplete(input);
526 523
527 // Pass 1: Get the in-memory URL database, and use it to find and promote 524 // Pass 1: Get the in-memory URL database, and use it to find and promote
528 // the inline autocomplete match, if any. 525 // the inline autocomplete match, if any.
529 history::URLDatabase* url_db = history_service->InMemoryDatabase(); 526 history::URLDatabase* url_db = history_service->InMemoryDatabase();
530 // url_db can be NULL if it hasn't finished initializing (or failed to 527 // url_db can be NULL if it hasn't finished initializing (or failed to
531 // initialize). In this case all we can do is fall back on the second 528 // initialize). In this case all we can do is fall back on the second
532 // pass. 529 // pass.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 AutocompleteMatch match(this, 0, false, 570 AutocompleteMatch match(this, 0, false,
574 AutocompleteMatchType::URL_WHAT_YOU_TYPED); 571 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
575 572
576 if (destination_url.is_valid()) { 573 if (destination_url.is_valid()) {
577 match.destination_url = destination_url; 574 match.destination_url = destination_url;
578 575
579 // Trim off "http://" if the user didn't type it. 576 // Trim off "http://" if the user didn't type it.
580 DCHECK(!trim_http || 577 DCHECK(!trim_http ||
581 !AutocompleteInput::HasHTTPScheme(input.text())); 578 !AutocompleteInput::HasHTTPScheme(input.text()));
582 base::string16 display_string(url_formatter::FormatUrl( 579 base::string16 display_string(url_formatter::FormatUrl(
583 destination_url, std::string(), 580 destination_url,
584 url_formatter::kFormatUrlOmitAll & ~url_formatter::kFormatUrlOmitHTTP, 581 url_formatter::kFormatUrlOmitAll & ~url_formatter::kFormatUrlOmitHTTP,
585 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr)); 582 net::UnescapeRule::SPACES, nullptr, nullptr, nullptr));
586 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0; 583 const size_t offset = trim_http ? TrimHttpPrefix(&display_string) : 0;
587 match.fill_into_edit = 584 match.fill_into_edit =
588 AutocompleteInput::FormattedStringWithEquivalentMeaning( 585 AutocompleteInput::FormattedStringWithEquivalentMeaning(
589 destination_url, display_string, client()->GetSchemeClassifier()); 586 destination_url, display_string, client()->GetSchemeClassifier());
590 // The what-you-typed match is generally only allowed to be default for 587 // The what-you-typed match is generally only allowed to be default for
591 // URL inputs. (It's also allowed to be default for UNKNOWN inputs 588 // URL inputs. (It's also allowed to be default for UNKNOWN inputs
592 // where the destination is a known intranet site. In this case, 589 // where the destination is a known intranet site. In this case,
593 // |allowed_to_be_default_match| is revised in FixupExactSuggestion().) 590 // |allowed_to_be_default_match| is revised in FixupExactSuggestion().)
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 params->matches.resize(max_results); 808 params->matches.resize(max_results);
812 } 809 }
813 } 810 }
814 811
815 void HistoryURLProvider::PromoteMatchesIfNecessary( 812 void HistoryURLProvider::PromoteMatchesIfNecessary(
816 const HistoryURLProviderParams& params) { 813 const HistoryURLProviderParams& params) {
817 if (params.promote_type == HistoryURLProviderParams::NEITHER) 814 if (params.promote_type == HistoryURLProviderParams::NEITHER)
818 return; 815 return;
819 if (params.promote_type == HistoryURLProviderParams::FRONT_HISTORY_MATCH) { 816 if (params.promote_type == HistoryURLProviderParams::FRONT_HISTORY_MATCH) {
820 matches_.push_back( 817 matches_.push_back(
821 HistoryMatchToACMatch(params, 0, INLINE_AUTOCOMPLETE, 818 HistoryMatchToACMatch(params, 0,
822 CalculateRelevance(INLINE_AUTOCOMPLETE, 0))); 819 CalculateRelevance(INLINE_AUTOCOMPLETE, 0)));
823 } 820 }
824 // There are two cases where we need to add the what-you-typed-match: 821 // There are two cases where we need to add the what-you-typed-match:
825 // * If params.promote_type is WHAT_YOU_TYPED_MATCH, we're being explicitly 822 // * If params.promote_type is WHAT_YOU_TYPED_MATCH, we're being explicitly
826 // directed to. 823 // directed to.
827 // * If params.have_what_you_typed_match is true, then params.promote_type 824 // * If params.have_what_you_typed_match is true, then params.promote_type
828 // can't be NEITHER (see code near the end of DoAutocomplete()), so if 825 // can't be NEITHER (see code near the end of DoAutocomplete()), so if
829 // it's not WHAT_YOU_TYPED_MATCH, it must be FRONT_HISTORY_MATCH, and 826 // it's not WHAT_YOU_TYPED_MATCH, it must be FRONT_HISTORY_MATCH, and
830 // we'll have promoted the history match above. If 827 // we'll have promoted the history match above. If
831 // params.prevent_inline_autocomplete is also true, then this match 828 // params.prevent_inline_autocomplete is also true, then this match
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 (params->promote_type == 872 (params->promote_type ==
876 HistoryURLProviderParams::FRONT_HISTORY_MATCH)) ? 1 : 0; 873 HistoryURLProviderParams::FRONT_HISTORY_MATCH)) ? 1 : 0;
877 for (size_t i = first_match; i < params->matches.size(); ++i) { 874 for (size_t i = first_match; i < params->matches.size(); ++i) {
878 // All matches score one less than the previous match. 875 // All matches score one less than the previous match.
879 --relevance; 876 --relevance;
880 // The experimental scoring must not change the top result's score. 877 // The experimental scoring must not change the top result's score.
881 if (!matches_.empty()) { 878 if (!matches_.empty()) {
882 relevance = CalculateRelevanceScoreUsingScoringParams( 879 relevance = CalculateRelevanceScoreUsingScoringParams(
883 params->matches[i], relevance, scoring_params_); 880 params->matches[i], relevance, scoring_params_);
884 } 881 }
885 matches_.push_back(HistoryMatchToACMatch(*params, i, NORMAL, relevance)); 882 matches_.push_back(HistoryMatchToACMatch(*params, i, relevance));
886 } 883 }
887 } 884 }
888 885
889 done_ = true; 886 done_ = true;
890 listener_->OnProviderUpdate(true); 887 listener_->OnProviderUpdate(true);
891 } 888 }
892 889
893 bool HistoryURLProvider::FixupExactSuggestion( 890 bool HistoryURLProvider::FixupExactSuggestion(
894 history::URLDatabase* db, 891 history::URLDatabase* db,
895 const VisitClassifier& classifier, 892 const VisitClassifier& classifier,
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 next = matches->erase(next); 1126 next = matches->erase(next);
1130 if (static_cast<size_t>(next - matches->begin()) < next_index) 1127 if (static_cast<size_t>(next - matches->begin()) < next_index)
1131 --next_index; 1128 --next_index;
1132 } 1129 }
1133 return next_index; 1130 return next_index;
1134 } 1131 }
1135 1132
1136 AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch( 1133 AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch(
1137 const HistoryURLProviderParams& params, 1134 const HistoryURLProviderParams& params,
1138 size_t match_number, 1135 size_t match_number,
1139 MatchType match_type,
1140 int relevance) { 1136 int relevance) {
1141 // The FormattedStringWithEquivalentMeaning() call below requires callers to 1137 // The FormattedStringWithEquivalentMeaning() call below requires callers to
1142 // be on the main thread. 1138 // be on the main thread.
1143 DCHECK(thread_checker_.CalledOnValidThread()); 1139 DCHECK(thread_checker_.CalledOnValidThread());
1144 1140
1145 const history::HistoryMatch& history_match = params.matches[match_number]; 1141 const history::HistoryMatch& history_match = params.matches[match_number];
1146 const history::URLRow& info = history_match.url_info; 1142 const history::URLRow& info = history_match.url_info;
1147 AutocompleteMatch match(this, relevance, 1143 AutocompleteMatch match(this, relevance,
1148 !!info.visit_count(), AutocompleteMatchType::HISTORY_URL); 1144 !!info.visit_count(), AutocompleteMatchType::HISTORY_URL);
1149 match.typed_count = info.typed_count(); 1145 match.typed_count = info.typed_count();
1150 match.destination_url = info.url(); 1146 match.destination_url = info.url();
1151 DCHECK(match.destination_url.is_valid()); 1147 DCHECK(match.destination_url.is_valid());
1152 size_t inline_autocomplete_offset = 1148 size_t inline_autocomplete_offset =
1153 history_match.input_location + params.input.text().length(); 1149 history_match.input_location + params.input.text().length();
1154 std::string languages = (match_type == WHAT_YOU_TYPED) ?
1155 std::string() : params.languages;
1156 const url_formatter::FormatUrlTypes format_types = 1150 const url_formatter::FormatUrlTypes format_types =
1157 url_formatter::kFormatUrlOmitAll & 1151 url_formatter::kFormatUrlOmitAll &
1158 ~((params.trim_http && !history_match.match_in_scheme) 1152 ~((params.trim_http && !history_match.match_in_scheme)
1159 ? 0 1153 ? 0
1160 : url_formatter::kFormatUrlOmitHTTP); 1154 : url_formatter::kFormatUrlOmitHTTP);
1161 match.fill_into_edit = 1155 match.fill_into_edit =
1162 AutocompleteInput::FormattedStringWithEquivalentMeaning( 1156 AutocompleteInput::FormattedStringWithEquivalentMeaning(
1163 info.url(), 1157 info.url(),
1164 url_formatter::FormatUrl(info.url(), languages, format_types, 1158 url_formatter::FormatUrl(info.url(), format_types,
1165 net::UnescapeRule::SPACES, nullptr, nullptr, 1159 net::UnescapeRule::SPACES, nullptr, nullptr,
1166 &inline_autocomplete_offset), 1160 &inline_autocomplete_offset),
1167 client()->GetSchemeClassifier()); 1161 client()->GetSchemeClassifier());
1168 // |inline_autocomplete_offset| was guaranteed not to be npos before the call 1162 // |inline_autocomplete_offset| was guaranteed not to be npos before the call
1169 // to FormatUrl(). If it is npos now, that means the represented location no 1163 // to FormatUrl(). If it is npos now, that means the represented location no
1170 // longer exists as such in the formatted string, e.g. if the offset pointed 1164 // longer exists as such in the formatted string, e.g. if the offset pointed
1171 // into the middle of a punycode sequence fixed up to Unicode. In this case, 1165 // into the middle of a punycode sequence fixed up to Unicode. In this case,
1172 // there can be no inline autocompletion, and the match must not be allowed to 1166 // there can be no inline autocompletion, and the match must not be allowed to
1173 // be default. 1167 // be default.
1174 const bool autocomplete_offset_valid = 1168 const bool autocomplete_offset_valid =
1175 inline_autocomplete_offset != base::string16::npos; 1169 inline_autocomplete_offset != base::string16::npos;
1176 if (!params.prevent_inline_autocomplete && autocomplete_offset_valid) { 1170 if (!params.prevent_inline_autocomplete && autocomplete_offset_valid) {
1177 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); 1171 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length());
1178 match.inline_autocompletion = 1172 match.inline_autocompletion =
1179 match.fill_into_edit.substr(inline_autocomplete_offset); 1173 match.fill_into_edit.substr(inline_autocomplete_offset);
1180 } 1174 }
1181 // The latter part of the test effectively asks "is the inline completion 1175 // The latter part of the test effectively asks "is the inline completion
1182 // empty?" (i.e., is this match effectively the what-you-typed match?). 1176 // empty?" (i.e., is this match effectively the what-you-typed match?).
1183 match.allowed_to_be_default_match = autocomplete_offset_valid && 1177 match.allowed_to_be_default_match = autocomplete_offset_valid &&
1184 (!params.prevent_inline_autocomplete || 1178 (!params.prevent_inline_autocomplete ||
1185 (inline_autocomplete_offset >= match.fill_into_edit.length())); 1179 (inline_autocomplete_offset >= match.fill_into_edit.length()));
1186 1180
1187 size_t match_start = history_match.input_location; 1181 size_t match_start = history_match.input_location;
1188 match.contents = url_formatter::FormatUrl(info.url(), languages, format_types, 1182 match.contents = url_formatter::FormatUrl(info.url(), format_types,
1189 net::UnescapeRule::SPACES, nullptr, 1183 net::UnescapeRule::SPACES, nullptr,
1190 nullptr, &match_start); 1184 nullptr, &match_start);
1191 if ((match_start != base::string16::npos) && autocomplete_offset_valid && 1185 if ((match_start != base::string16::npos) && autocomplete_offset_valid &&
1192 (inline_autocomplete_offset != match_start)) { 1186 (inline_autocomplete_offset != match_start)) {
1193 DCHECK(inline_autocomplete_offset > match_start); 1187 DCHECK(inline_autocomplete_offset > match_start);
1194 AutocompleteMatch::ClassifyLocationInString(match_start, 1188 AutocompleteMatch::ClassifyLocationInString(match_start,
1195 inline_autocomplete_offset - match_start, match.contents.length(), 1189 inline_autocomplete_offset - match_start, match.contents.length(),
1196 ACMatchClassification::URL, &match.contents_class); 1190 ACMatchClassification::URL, &match.contents_class);
1197 } else { 1191 } else {
1198 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0, 1192 AutocompleteMatch::ClassifyLocationInString(base::string16::npos, 0,
1199 match.contents.length(), ACMatchClassification::URL, 1193 match.contents.length(), ACMatchClassification::URL,
1200 &match.contents_class); 1194 &match.contents_class);
1201 } 1195 }
1202 match.description = info.title(); 1196 match.description = info.title();
1203 match.description_class = 1197 match.description_class =
1204 ClassifyDescription(params.input.text(), match.description); 1198 ClassifyDescription(params.input.text(), match.description);
1205 RecordAdditionalInfoFromUrlRow(info, &match); 1199 RecordAdditionalInfoFromUrlRow(info, &match);
1206 return match; 1200 return match;
1207 } 1201 }
OLDNEW
« no previous file with comments | « components/omnibox/browser/history_url_provider.h ('k') | components/omnibox/browser/history_url_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698