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

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

Issue 397723003: Omnibox: Don't Autocomplete Previously-Issued Search Queries (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: adds test Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 887
888 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults( 888 SearchProvider::SuggestResults SearchProvider::ScoreHistoryResults(
889 const HistoryResults& results, 889 const HistoryResults& results,
890 bool base_prevent_inline_autocomplete, 890 bool base_prevent_inline_autocomplete,
891 bool input_multiple_words, 891 bool input_multiple_words,
892 const base::string16& input_text, 892 const base::string16& input_text,
893 bool is_keyword) { 893 bool is_keyword) {
894 AutocompleteClassifier* classifier = 894 AutocompleteClassifier* classifier =
895 AutocompleteClassifierFactory::GetForProfile(profile_); 895 AutocompleteClassifierFactory::GetForProfile(profile_);
896 SuggestResults scored_results; 896 SuggestResults scored_results;
897 // True if the user has asked this exact query previously.
898 bool found_what_you_typed_match = false;
897 const bool prevent_search_history_inlining = 899 const bool prevent_search_history_inlining =
898 OmniboxFieldTrial::SearchHistoryPreventInlining( 900 OmniboxFieldTrial::SearchHistoryPreventInlining(
899 input_.current_page_classification()); 901 input_.current_page_classification());
900 const base::string16& trimmed_input = 902 const base::string16& trimmed_input =
901 base::CollapseWhitespace(input_text, false); 903 base::CollapseWhitespace(input_text, false);
902 for (HistoryResults::const_iterator i(results.begin()); i != results.end(); 904 for (HistoryResults::const_iterator i(results.begin()); i != results.end();
903 ++i) { 905 ++i) {
904 const base::string16& trimmed_suggestion = 906 const base::string16& trimmed_suggestion =
905 base::CollapseWhitespace(i->term, false); 907 base::CollapseWhitespace(i->term, false);
906 908
(...skipping 21 matching lines...) Expand all
928 AutocompleteMatch match; 930 AutocompleteMatch match;
929 classifier->Classify(trimmed_suggestion, false, false, 931 classifier->Classify(trimmed_suggestion, false, false,
930 input_.current_page_classification(), &match, NULL); 932 input_.current_page_classification(), &match, NULL);
931 prevent_inline_autocomplete = 933 prevent_inline_autocomplete =
932 !AutocompleteMatch::IsSearchType(match.type); 934 !AutocompleteMatch::IsSearchType(match.type);
933 } 935 }
934 936
935 int relevance = CalculateRelevanceForHistory( 937 int relevance = CalculateRelevanceForHistory(
936 i->time, is_keyword, !prevent_inline_autocomplete, 938 i->time, is_keyword, !prevent_inline_autocomplete,
937 prevent_search_history_inlining); 939 prevent_search_history_inlining);
938 scored_results.push_back(SuggestResult( 940 // Add the match to |scored_results| by putting the what-you-typed match
941 // on the front and appending all other matches. We want the what-you-
942 // typed match to always be first.
943 SuggestResults::iterator insertion_position = scored_results.end();
944 if (trimmed_suggestion == trimmed_input) {
945 found_what_you_typed_match = true;
946 insertion_position = scored_results.begin();
947 }
948 scored_results.insert(insertion_position, SuggestResult(
939 trimmed_suggestion, AutocompleteMatchType::SEARCH_HISTORY, 949 trimmed_suggestion, AutocompleteMatchType::SEARCH_HISTORY,
940 trimmed_suggestion, base::string16(), base::string16(), 950 trimmed_suggestion, base::string16(), base::string16(),
941 base::string16(), base::string16(), std::string(), std::string(), 951 base::string16(), base::string16(), std::string(), std::string(),
942 is_keyword, relevance, false, false, trimmed_input)); 952 is_keyword, relevance, false, false, trimmed_input));
943 } 953 }
944 954
945 // History returns results sorted for us. However, we may have docked some 955 // History returns results sorted for us. However, we may have docked some
946 // results' scores, so things are no longer in order. Do a stable sort to get 956 // results' scores, so things are no longer in order. While keeping the
957 // what-you-typed match at the front (if it exists), do a stable sort to get
947 // things back in order without otherwise disturbing results with equal 958 // things back in order without otherwise disturbing results with equal
948 // scores, then force the scores to be unique, so that the order in which 959 // scores, then force the scores to be unique, so that the order in which
949 // they're shown is deterministic. 960 // they're shown is deterministic.
950 std::stable_sort(scored_results.begin(), scored_results.end(), 961 std::stable_sort(scored_results.begin() +
962 (found_what_you_typed_match ? 1 : 0),
963 scored_results.end(),
951 CompareScoredResults()); 964 CompareScoredResults());
952 int last_relevance = 0; 965 int last_relevance = 0;
953 for (SuggestResults::iterator i(scored_results.begin()); 966 for (SuggestResults::iterator i(scored_results.begin());
954 i != scored_results.end(); ++i) { 967 i != scored_results.end(); ++i) {
955 if ((i != scored_results.begin()) && (i->relevance() >= last_relevance)) 968 if ((i != scored_results.begin()) && (i->relevance() >= last_relevance))
956 i->set_relevance(last_relevance - 1); 969 i->set_relevance(last_relevance - 1);
957 last_relevance = i->relevance(); 970 last_relevance = i->relevance();
958 } 971 }
959 972
960 return scored_results; 973 return scored_results;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 // Make the base64 encoded value URL and filename safe(see RFC 3548). 1181 // Make the base64 encoded value URL and filename safe(see RFC 3548).
1169 std::replace(current_token_.begin(), current_token_.end(), '+', '-'); 1182 std::replace(current_token_.begin(), current_token_.end(), '+', '-');
1170 std::replace(current_token_.begin(), current_token_.end(), '/', '_'); 1183 std::replace(current_token_.begin(), current_token_.end(), '/', '_');
1171 } 1184 }
1172 1185
1173 // Extend expiration time another 60 seconds. 1186 // Extend expiration time another 60 seconds.
1174 token_expiration_time_ = current_time + base::TimeDelta::FromSeconds(60); 1187 token_expiration_time_ = current_time + base::TimeDelta::FromSeconds(60);
1175 1188
1176 return current_token_; 1189 return current_token_;
1177 } 1190 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698