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

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

Issue 481693004: Omnibox: Prevent Asynchronous Suggestions from Changing Default Match (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix interactive test Created 6 years, 3 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
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 // This file contains the Search autocomplete provider. This provider is 5 // This file contains the Search autocomplete provider. This provider is
6 // responsible for all autocomplete entries that start with "Search <engine> 6 // responsible for all autocomplete entries that start with "Search <engine>
7 // for ...", including searching for the current input string, search 7 // for ...", including searching for the current input string, search
8 // history, and search suggestions. An instance of it gets created and 8 // history, and search suggestions. An instance of it gets created and
9 // managed by the autocomplete controller. 9 // managed by the autocomplete controller.
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 void set_current_page_url(const GURL& current_page_url) { 67 void set_current_page_url(const GURL& current_page_url) {
68 current_page_url_ = current_page_url; 68 current_page_url_ = current_page_url;
69 } 69 }
70 70
71 protected: 71 protected:
72 virtual ~SearchProvider(); 72 virtual ~SearchProvider();
73 73
74 private: 74 private:
75 friend class SearchProviderTest; 75 friend class SearchProviderTest;
76 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, CanSendURL); 76 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, CanSendURL);
77 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest,
78 DontInlineAutocompleteAsynchronously);
77 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInline); 79 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInline);
78 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineDomainClassify); 80 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineDomainClassify);
79 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineSchemeSubstring); 81 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineSchemeSubstring);
80 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, RemoveStaleResultsTest);
81 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestRelevanceExperiment); 82 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestRelevanceExperiment);
82 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, TestDeleteMatch); 83 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, TestDeleteMatch);
83 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestQueryUsesToken); 84 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestQueryUsesToken);
84 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SessionToken); 85 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SessionToken);
85 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, AnswersCache); 86 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, AnswersCache);
86 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); 87 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL);
87 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, ClearPrefetchedResults); 88 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, ClearPrefetchedResults);
88 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, SetPrefetchQuery); 89 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, SetPrefetchQuery);
89 90
90 // Manages the providers (TemplateURLs) used by SearchProvider. Two providers 91 // Manages the providers (TemplateURLs) used by SearchProvider. Two providers
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 137
137 class CompareScoredResults; 138 class CompareScoredResults;
138 139
139 struct AnswersQueryData { 140 struct AnswersQueryData {
140 base::string16 full_query_text; 141 base::string16 full_query_text;
141 base::string16 query_type; 142 base::string16 query_type;
142 }; 143 };
143 144
144 typedef std::vector<history::KeywordSearchTermVisit> HistoryResults; 145 typedef std::vector<history::KeywordSearchTermVisit> HistoryResults;
145 146
146 // Removes non-inlineable results until either the top result can inline
147 // autocomplete the current input or verbatim outscores the top result.
148 static void RemoveStaleResults(
149 const base::string16& input,
150 int verbatim_relevance,
151 SearchSuggestionParser::SuggestResults* suggest_results,
152 SearchSuggestionParser::NavigationResults* navigation_results);
153
154 // Calculates the relevance score for the keyword verbatim result (if the 147 // Calculates the relevance score for the keyword verbatim result (if the
155 // input matches one of the profile's keyword). 148 // input matches one of the profile's keyword).
156 static int CalculateRelevanceForKeywordVerbatim( 149 static int CalculateRelevanceForKeywordVerbatim(
157 metrics::OmniboxInputType::Type type, 150 metrics::OmniboxInputType::Type type,
158 bool prefer_keyword); 151 bool prefer_keyword);
159 152
153 // A helper function for UpdateAllOldResults().
154 static void UpdateOldResults(bool minimal_changes,
155 SearchSuggestionParser::Results* results);
156
157 // Returns the first match in |matches| which might be chosen as default.
158 static ACMatches::iterator FindTopMatch(ACMatches* matches);
159
160 // AutocompleteProvider: 160 // AutocompleteProvider:
161 virtual void Start(const AutocompleteInput& input, 161 virtual void Start(const AutocompleteInput& input,
162 bool minimal_changes) OVERRIDE; 162 bool minimal_changes) OVERRIDE;
163 virtual void Stop(bool clear_cached_results) OVERRIDE; 163 virtual void Stop(bool clear_cached_results) OVERRIDE;
164 164
165 // BaseSearchProvider: 165 // BaseSearchProvider:
166 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const OVERRIDE; 166 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const OVERRIDE;
167 virtual const AutocompleteInput GetInput(bool is_keyword) const OVERRIDE; 167 virtual const AutocompleteInput GetInput(bool is_keyword) const OVERRIDE;
168 virtual bool ShouldAppendExtraParams( 168 virtual bool ShouldAppendExtraParams(
169 const SearchSuggestionParser::SuggestResult& result) const OVERRIDE; 169 const SearchSuggestionParser::SuggestResult& result) const OVERRIDE;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // Determines whether an asynchronous subcomponent query should run for the 204 // Determines whether an asynchronous subcomponent query should run for the
205 // current input. If so, starts it if necessary; otherwise stops it. 205 // current input. If so, starts it if necessary; otherwise stops it.
206 // NOTE: This function does not update |done_|. Callers must do so. 206 // NOTE: This function does not update |done_|. Callers must do so.
207 void StartOrStopSuggestQuery(bool minimal_changes); 207 void StartOrStopSuggestQuery(bool minimal_changes);
208 208
209 // Returns true when the current query can be sent to the Suggest service. 209 // Returns true when the current query can be sent to the Suggest service.
210 // This will be false e.g. when Suggest is disabled, the query contains 210 // This will be false e.g. when Suggest is disabled, the query contains
211 // potentially private data, etc. 211 // potentially private data, etc.
212 bool IsQuerySuitableForSuggest() const; 212 bool IsQuerySuitableForSuggest() const;
213 213
214 // Removes stale results for both default and keyword providers. See comments 214 // Remove existing keyword results if the user is no longer in keyword mode,
215 // on RemoveStaleResults(). 215 // and, if |minimal_changes| is false, revise the existing results to
216 void RemoveAllStaleResults(); 216 // indicate they were received before the last keystroke.
217 void UpdateAllOldResults(bool minimal_changes);
218
219 // Given new asynchronous results, ensure that we don't clobber the current
220 // top results, which were determined synchronously on the last keystroke.
221 void PersistTopSuggestions(SearchSuggestionParser::Results* results);
217 222
218 // Apply calculated relevance scores to the current results. 223 // Apply calculated relevance scores to the current results.
219 void ApplyCalculatedRelevance();
220 void ApplyCalculatedSuggestRelevance( 224 void ApplyCalculatedSuggestRelevance(
221 SearchSuggestionParser::SuggestResults* list); 225 SearchSuggestionParser::SuggestResults* list);
222 void ApplyCalculatedNavigationRelevance( 226 void ApplyCalculatedNavigationRelevance(
223 SearchSuggestionParser::NavigationResults* list); 227 SearchSuggestionParser::NavigationResults* list);
224 228
225 // Starts a new URLFetcher requesting suggest results from |template_url|; 229 // Starts a new URLFetcher requesting suggest results from |template_url|;
226 // callers own the returned URLFetcher, which is NULL for invalid providers. 230 // callers own the returned URLFetcher, which is NULL for invalid providers.
227 net::URLFetcher* CreateSuggestFetcher(int id, 231 net::URLFetcher* CreateSuggestFetcher(int id,
228 const TemplateURL* template_url, 232 const TemplateURL* template_url,
229 const AutocompleteInput& input); 233 const AutocompleteInput& input);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 base::TimeTicks time_suggest_request_sent_; 352 base::TimeTicks time_suggest_request_sent_;
349 353
350 // Fetchers used to retrieve results for the keyword and default providers. 354 // Fetchers used to retrieve results for the keyword and default providers.
351 scoped_ptr<net::URLFetcher> keyword_fetcher_; 355 scoped_ptr<net::URLFetcher> keyword_fetcher_;
352 scoped_ptr<net::URLFetcher> default_fetcher_; 356 scoped_ptr<net::URLFetcher> default_fetcher_;
353 357
354 // Results from the default and keyword search providers. 358 // Results from the default and keyword search providers.
355 SearchSuggestionParser::Results default_results_; 359 SearchSuggestionParser::Results default_results_;
356 SearchSuggestionParser::Results keyword_results_; 360 SearchSuggestionParser::Results keyword_results_;
357 361
362 // The top query suggestion, left blank if none.
363 base::string16 top_query_suggestion_match_contents_;
364 // The top navigation suggestion, left blank/invalid if none.
365 GURL top_navigation_suggestion_;
366
358 GURL current_page_url_; 367 GURL current_page_url_;
359 368
360 // Session token management. 369 // Session token management.
361 std::string current_token_; 370 std::string current_token_;
362 base::TimeTicks token_expiration_time_; 371 base::TimeTicks token_expiration_time_;
363 372
364 // Answers prefetch management. 373 // Answers prefetch management.
365 AnswersQueryData prefetch_data_; // Data to use for query prefetching. 374 AnswersQueryData prefetch_data_; // Data to use for query prefetching.
366 AnswersQueryData last_answer_seen_; // Last answer seen. 375 AnswersQueryData last_answer_seen_; // Last answer seen.
367 376
368 DISALLOW_COPY_AND_ASSIGN(SearchProvider); 377 DISALLOW_COPY_AND_ASSIGN(SearchProvider);
369 }; 378 };
370 379
371 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ 380 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698