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

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

Issue 471673002: Omnibox: Prevent Asynchronous Suggestions from Changing Default Match (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added comment by PersistInlineSuggestions() Created 6 years, 4 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 163
164 // BaseSearchProvider: 164 // BaseSearchProvider:
165 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const OVERRIDE; 165 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const OVERRIDE;
166 virtual const AutocompleteInput GetInput(bool is_keyword) const OVERRIDE; 166 virtual const AutocompleteInput GetInput(bool is_keyword) const OVERRIDE;
167 virtual bool ShouldAppendExtraParams( 167 virtual bool ShouldAppendExtraParams(
168 const SearchSuggestionParser::SuggestResult& result) const OVERRIDE; 168 const SearchSuggestionParser::SuggestResult& result) const OVERRIDE;
169 virtual void StopSuggest() OVERRIDE; 169 virtual void StopSuggest() OVERRIDE;
(...skipping 28 matching lines...) Expand all
198 // Determines whether an asynchronous subcomponent query should run for the 198 // Determines whether an asynchronous subcomponent query should run for the
199 // current input. If so, starts it if necessary; otherwise stops it. 199 // current input. If so, starts it if necessary; otherwise stops it.
200 // NOTE: This function does not update |done_|. Callers must do so. 200 // NOTE: This function does not update |done_|. Callers must do so.
201 void StartOrStopSuggestQuery(bool minimal_changes); 201 void StartOrStopSuggestQuery(bool minimal_changes);
202 202
203 // Returns true when the current query can be sent to the Suggest service. 203 // Returns true when the current query can be sent to the Suggest service.
204 // This will be false e.g. when Suggest is disabled, the query contains 204 // This will be false e.g. when Suggest is disabled, the query contains
205 // potentially private data, etc. 205 // potentially private data, etc.
206 bool IsQuerySuitableForSuggest() const; 206 bool IsQuerySuitableForSuggest() const;
207 207
208 // Removes stale results for both default and keyword providers. See comments 208 // Remove existing keyword results if the user is no longer in keyword mode,
209 // on RemoveStaleResults(). 209 // and, if |minimal_changes| is false, revise the existing results to
210 void RemoveAllStaleResults(); 210 // indicate they were received before the last keystroke.
211 void UpdateAllOldResults(bool minimal_changes);
212
213 // Loops through all results and marks those that were the previous inline
214 // autocompletion that they were received on a previous keystroke (and
215 // hence can remain as the inline autocompletion). All other results
Mark P 2014/08/15 23:01:06 I just expanded this comment. This seems like the
msw 2014/08/15 23:31:11 I'd prefer "PersistTopSuggestions", matching my me
Mark P 2014/08/15 23:50:16 Done. Nice comments.
216 // are left marked |received_after_last_keystroke| even if that isn't
217 // strictly true. (These other results may have been received before the
218 // last keystroke. When we processed the last keystroke synchronously,
219 // we decided not to inline them because we had better-scoring results.
220 // Upon receiving a new server reply, we leave the old non-inlined results
221 // marked (incorrectly) as |received_after_last_keystroke| because inlining
222 // them asychronously would be surprising.)
223 void PersistInlineSuggestions(SearchSuggestionParser::Results* results);
211 224
212 // Apply calculated relevance scores to the current results. 225 // Apply calculated relevance scores to the current results.
213 void ApplyCalculatedRelevance();
214 void ApplyCalculatedSuggestRelevance( 226 void ApplyCalculatedSuggestRelevance(
215 SearchSuggestionParser::SuggestResults* list); 227 SearchSuggestionParser::SuggestResults* list);
216 void ApplyCalculatedNavigationRelevance( 228 void ApplyCalculatedNavigationRelevance(
217 SearchSuggestionParser::NavigationResults* list); 229 SearchSuggestionParser::NavigationResults* list);
218 230
219 // Starts a new URLFetcher requesting suggest results from |template_url|; 231 // Starts a new URLFetcher requesting suggest results from |template_url|;
220 // callers own the returned URLFetcher, which is NULL for invalid providers. 232 // callers own the returned URLFetcher, which is NULL for invalid providers.
221 net::URLFetcher* CreateSuggestFetcher(int id, 233 net::URLFetcher* CreateSuggestFetcher(int id,
222 const TemplateURL* template_url, 234 const TemplateURL* template_url,
223 const AutocompleteInput& input); 235 const AutocompleteInput& input);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 base::TimeTicks time_suggest_request_sent_; 354 base::TimeTicks time_suggest_request_sent_;
343 355
344 // Fetchers used to retrieve results for the keyword and default providers. 356 // Fetchers used to retrieve results for the keyword and default providers.
345 scoped_ptr<net::URLFetcher> keyword_fetcher_; 357 scoped_ptr<net::URLFetcher> keyword_fetcher_;
346 scoped_ptr<net::URLFetcher> default_fetcher_; 358 scoped_ptr<net::URLFetcher> default_fetcher_;
347 359
348 // Results from the default and keyword search providers. 360 // Results from the default and keyword search providers.
349 SearchSuggestionParser::Results default_results_; 361 SearchSuggestionParser::Results default_results_;
350 SearchSuggestionParser::Results keyword_results_; 362 SearchSuggestionParser::Results keyword_results_;
351 363
364 // The inlined query suggestion, left blank if none.
msw 2014/08/15 23:31:11 nit: consider s/inlined/top/ for comments and iden
Mark P 2014/08/15 23:50:16 Done.
365 base::string16 inlined_query_suggestion_match_contents_;
366 // The inlined navigation suggestion, left blank/invalid if none.
367 GURL inlined_navigation_suggestion_;
368
352 GURL current_page_url_; 369 GURL current_page_url_;
353 370
354 // Session token management. 371 // Session token management.
355 std::string current_token_; 372 std::string current_token_;
356 base::TimeTicks token_expiration_time_; 373 base::TimeTicks token_expiration_time_;
357 374
358 // Answers prefetch management. 375 // Answers prefetch management.
359 AnswersQueryData prefetch_data_; // Data to use for query prefetching. 376 AnswersQueryData prefetch_data_; // Data to use for query prefetching.
360 AnswersQueryData last_answer_seen_; // Last answer seen. 377 AnswersQueryData last_answer_seen_; // Last answer seen.
361 378
362 DISALLOW_COPY_AND_ASSIGN(SearchProvider); 379 DISALLOW_COPY_AND_ASSIGN(SearchProvider);
363 }; 380 };
364 381
365 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ 382 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698