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

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: better resolve rebase 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(
Mark P 2014/08/15 20:04:38 This function implementation was clobbered a long
msw 2014/08/15 21:04:38 Acknowledged.
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 RemoveOrReviseOldResults() that acts only on results
msw 2014/08/15 21:04:38 nit: remove "that acts only on results from one pr
Mark P 2014/08/15 22:09:22 Done.
154 // from one provider.
155 static void RemoveOrReviseOldResultsForOneProvider(
msw 2014/08/15 21:04:38 Consider UpdateOldResults, CleanupStaleResults, Pr
Mark P 2014/08/15 22:09:21 Chose your first suggestion. Done.
156 bool minimal_changes, SearchSuggestionParser::Results* results);
msw 2014/08/15 21:04:39 nit: one param per line
Mark P 2014/08/15 22:09:22 Now moot.
157
158 // Returns an iterator to the first match in |matches| which might
msw 2014/08/15 21:04:38 nit: remove "an iterator to " for a one-liner.
Mark P 2014/08/15 22:09:21 Done.
159 // be chosen as default.
160 static ACMatches::iterator FindTopMatch(ACMatches* matches);
161
160 // AutocompleteProvider: 162 // AutocompleteProvider:
161 virtual void Start(const AutocompleteInput& input, 163 virtual void Start(const AutocompleteInput& input,
162 bool minimal_changes) OVERRIDE; 164 bool minimal_changes) OVERRIDE;
163 165
164 // BaseSearchProvider: 166 // BaseSearchProvider:
165 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const OVERRIDE; 167 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const OVERRIDE;
166 virtual const AutocompleteInput GetInput(bool is_keyword) const OVERRIDE; 168 virtual const AutocompleteInput GetInput(bool is_keyword) const OVERRIDE;
167 virtual bool ShouldAppendExtraParams( 169 virtual bool ShouldAppendExtraParams(
168 const SearchSuggestionParser::SuggestResult& result) const OVERRIDE; 170 const SearchSuggestionParser::SuggestResult& result) const OVERRIDE;
169 virtual void StopSuggest() OVERRIDE; 171 virtual void StopSuggest() OVERRIDE;
(...skipping 28 matching lines...) Expand all
198 // Determines whether an asynchronous subcomponent query should run for the 200 // Determines whether an asynchronous subcomponent query should run for the
199 // current input. If so, starts it if necessary; otherwise stops it. 201 // current input. If so, starts it if necessary; otherwise stops it.
200 // NOTE: This function does not update |done_|. Callers must do so. 202 // NOTE: This function does not update |done_|. Callers must do so.
201 void StartOrStopSuggestQuery(bool minimal_changes); 203 void StartOrStopSuggestQuery(bool minimal_changes);
202 204
203 // Returns true when the current query can be sent to the Suggest service. 205 // 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 206 // This will be false e.g. when Suggest is disabled, the query contains
205 // potentially private data, etc. 207 // potentially private data, etc.
206 bool IsQuerySuitableForSuggest() const; 208 bool IsQuerySuitableForSuggest() const;
207 209
208 // Removes stale results for both default and keyword providers. See comments 210 // Remove existing keyword results if the user is no longer in keyword mode,
209 // on RemoveStaleResults(). 211 // and, if |minimal_changes| is false, revise the existing results to
210 void RemoveAllStaleResults(); 212 // indicate they were received before the last keystroke.
Mark P 2014/08/15 20:04:38 RemoveOrReviseOldResults() remained to RemoveOrRev
msw 2014/08/15 21:04:38 Acknowledged.
213 void RemoveOrReviseOldResults(bool minimal_changes);
msw 2014/08/15 21:04:38 The name here could probably better match the oper
Mark P 2014/08/15 22:09:21 Named it UpdateAllOldResults(), to make it paralle
214
215 // Loops through all results and marks those that were the previous inline
216 // autocompletion that they were received on a previous keystroke (and
217 // hence can remain as the inline autocompletion).
218 void PersistGoodResultsForOneProvider(
219 SearchSuggestionParser::Results* results);
211 220
212 // Apply calculated relevance scores to the current results. 221 // Apply calculated relevance scores to the current results.
213 void ApplyCalculatedRelevance();
Mark P 2014/08/15 20:04:38 No longer called in the .cc file after this change
msw 2014/08/15 21:04:38 Acknowledged.
214 void ApplyCalculatedSuggestRelevance( 222 void ApplyCalculatedSuggestRelevance(
215 SearchSuggestionParser::SuggestResults* list); 223 SearchSuggestionParser::SuggestResults* list);
216 void ApplyCalculatedNavigationRelevance( 224 void ApplyCalculatedNavigationRelevance(
217 SearchSuggestionParser::NavigationResults* list); 225 SearchSuggestionParser::NavigationResults* list);
218 226
219 // Starts a new URLFetcher requesting suggest results from |template_url|; 227 // Starts a new URLFetcher requesting suggest results from |template_url|;
220 // callers own the returned URLFetcher, which is NULL for invalid providers. 228 // callers own the returned URLFetcher, which is NULL for invalid providers.
221 net::URLFetcher* CreateSuggestFetcher(int id, 229 net::URLFetcher* CreateSuggestFetcher(int id,
222 const TemplateURL* template_url, 230 const TemplateURL* template_url,
223 const AutocompleteInput& input); 231 const AutocompleteInput& input);
224 232
225 // Converts the parsed results to a set of AutocompleteMatches, |matches_|. 233 // Converts the parsed results to a set of AutocompleteMatches, |matches_|.
226 void ConvertResultsToAutocompleteMatches(); 234 void ConvertResultsToAutocompleteMatches();
227 235
228 // Returns an iterator to the first match in |matches_| which might 236 // Returns an iterator to the first match in |matches_| which might
229 // be chosen as default. 237 // be chosen as default.
230 ACMatches::const_iterator FindTopMatch() const; 238 ACMatches::const_iterator FindTopMatch() const;
231 239
232 // Checks if suggested relevances violate certain expected constraints. 240 // Checks if suggested relevances violate an expected constraint.
233 // See UpdateMatches() for the use and explanation of these constraints. 241 // See UpdateMatches() for the use and explanation of this constraint
234 bool HasKeywordDefaultMatchInKeywordMode() const; 242 // and other constraints enforced without the use of helper functions.
235 bool IsTopMatchSearchWithURLInput() const; 243 bool IsTopMatchSearchWithURLInput() const;
236 244
237 // Converts an appropriate number of navigation results in 245 // Converts an appropriate number of navigation results in
238 // |navigation_results| to matches and adds them to |matches|. 246 // |navigation_results| to matches and adds them to |matches|.
239 void AddNavigationResultsToMatches( 247 void AddNavigationResultsToMatches(
240 const SearchSuggestionParser::NavigationResults& navigation_results, 248 const SearchSuggestionParser::NavigationResults& navigation_results,
241 ACMatches* matches); 249 ACMatches* matches);
242 250
243 // Adds a match for each result in |results| to |map|. |is_keyword| indicates 251 // Adds a match for each result in |results| to |map|. |is_keyword| indicates
244 // whether the results correspond to the keyword provider or default provider. 252 // whether the results correspond to the keyword provider or default provider.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 base::TimeTicks time_suggest_request_sent_; 350 base::TimeTicks time_suggest_request_sent_;
343 351
344 // Fetchers used to retrieve results for the keyword and default providers. 352 // Fetchers used to retrieve results for the keyword and default providers.
345 scoped_ptr<net::URLFetcher> keyword_fetcher_; 353 scoped_ptr<net::URLFetcher> keyword_fetcher_;
346 scoped_ptr<net::URLFetcher> default_fetcher_; 354 scoped_ptr<net::URLFetcher> default_fetcher_;
347 355
348 // Results from the default and keyword search providers. 356 // Results from the default and keyword search providers.
349 SearchSuggestionParser::Results default_results_; 357 SearchSuggestionParser::Results default_results_;
350 SearchSuggestionParser::Results keyword_results_; 358 SearchSuggestionParser::Results keyword_results_;
351 359
360 // The inlined query suggestion (if any), left blank if none.
msw 2014/08/15 21:04:38 nit: remove "(if any)" here and below; "left blank
msw 2014/08/15 21:04:38 nit: should this be "inline" instead of "inlined"
Mark P 2014/08/15 22:09:22 I think "inlined" is better. This result is actua
Mark P 2014/08/15 22:09:22 Done in both locations.
msw 2014/08/15 23:31:10 Acknowledged.
361 base::string16 inlined_query_suggestion_match_contents_;
362 // The inlined navsuggestion (if any), left blank/invalid if none.
msw 2014/08/15 21:04:38 nit: "navigation suggestion"
Mark P 2014/08/15 22:09:22 Done.
363 GURL inlined_navsuggestion_;
msw 2014/08/15 21:04:38 nit: inline_navigation_suggestion_match_contents_
Mark P 2014/08/15 22:09:22 Switched to inlined_navigation_suggestion. Left in
msw 2014/08/15 23:31:10 Acknowledged.
364
352 GURL current_page_url_; 365 GURL current_page_url_;
353 366
354 // Session token management. 367 // Session token management.
355 std::string current_token_; 368 std::string current_token_;
356 base::TimeTicks token_expiration_time_; 369 base::TimeTicks token_expiration_time_;
357 370
358 // Answers prefetch management. 371 // Answers prefetch management.
359 AnswersQueryData prefetch_data_; // Data to use for query prefetching. 372 AnswersQueryData prefetch_data_; // Data to use for query prefetching.
360 AnswersQueryData last_answer_seen_; // Last answer seen. 373 AnswersQueryData last_answer_seen_; // Last answer seen.
361 374
362 DISALLOW_COPY_AND_ASSIGN(SearchProvider); 375 DISALLOW_COPY_AND_ASSIGN(SearchProvider);
363 }; 376 };
364 377
365 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ 378 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698