OLD | NEW |
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 Loading... |
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); | |
79 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInline); | 77 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInline); |
80 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineDomainClassify); | 78 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineDomainClassify); |
81 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineSchemeSubstring); | 79 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineSchemeSubstring); |
| 80 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, RemoveStaleResultsTest); |
82 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestRelevanceExperiment); | 81 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestRelevanceExperiment); |
83 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, TestDeleteMatch); | 82 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, TestDeleteMatch); |
84 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestQueryUsesToken); | 83 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestQueryUsesToken); |
85 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SessionToken); | 84 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SessionToken); |
86 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, AnswersCache); | 85 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, AnswersCache); |
87 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); | 86 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); |
88 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, ClearPrefetchedResults); | 87 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, ClearPrefetchedResults); |
89 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, SetPrefetchQuery); | 88 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, SetPrefetchQuery); |
90 | 89 |
91 // Manages the providers (TemplateURLs) used by SearchProvider. Two providers | 90 // Manages the providers (TemplateURLs) used by SearchProvider. Two providers |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 136 |
138 class CompareScoredResults; | 137 class CompareScoredResults; |
139 | 138 |
140 struct AnswersQueryData { | 139 struct AnswersQueryData { |
141 base::string16 full_query_text; | 140 base::string16 full_query_text; |
142 base::string16 query_type; | 141 base::string16 query_type; |
143 }; | 142 }; |
144 | 143 |
145 typedef std::vector<history::KeywordSearchTermVisit> HistoryResults; | 144 typedef std::vector<history::KeywordSearchTermVisit> HistoryResults; |
146 | 145 |
| 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 |
147 // Calculates the relevance score for the keyword verbatim result (if the | 154 // Calculates the relevance score for the keyword verbatim result (if the |
148 // input matches one of the profile's keyword). | 155 // input matches one of the profile's keyword). |
149 static int CalculateRelevanceForKeywordVerbatim( | 156 static int CalculateRelevanceForKeywordVerbatim( |
150 metrics::OmniboxInputType::Type type, | 157 metrics::OmniboxInputType::Type type, |
151 bool prefer_keyword); | 158 bool prefer_keyword); |
152 | 159 |
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 Loading... |
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 // Remove existing keyword results if the user is no longer in keyword mode, | 208 // Removes stale results for both default and keyword providers. See comments |
209 // and, if |minimal_changes| is false, revise the existing results to | 209 // on RemoveStaleResults(). |
210 // indicate they were received before the last keystroke. | 210 void RemoveAllStaleResults(); |
211 void UpdateAllOldResults(bool minimal_changes); | |
212 | |
213 // Given new asynchronous results, ensure that we don't clobber the current | |
214 // top results, which were determined synchronously on the last keystroke. | |
215 void PersistTopSuggestions(SearchSuggestionParser::Results* results); | |
216 | 211 |
217 // Apply calculated relevance scores to the current results. | 212 // Apply calculated relevance scores to the current results. |
| 213 void ApplyCalculatedRelevance(); |
218 void ApplyCalculatedSuggestRelevance( | 214 void ApplyCalculatedSuggestRelevance( |
219 SearchSuggestionParser::SuggestResults* list); | 215 SearchSuggestionParser::SuggestResults* list); |
220 void ApplyCalculatedNavigationRelevance( | 216 void ApplyCalculatedNavigationRelevance( |
221 SearchSuggestionParser::NavigationResults* list); | 217 SearchSuggestionParser::NavigationResults* list); |
222 | 218 |
223 // Starts a new URLFetcher requesting suggest results from |template_url|; | 219 // Starts a new URLFetcher requesting suggest results from |template_url|; |
224 // callers own the returned URLFetcher, which is NULL for invalid providers. | 220 // callers own the returned URLFetcher, which is NULL for invalid providers. |
225 net::URLFetcher* CreateSuggestFetcher(int id, | 221 net::URLFetcher* CreateSuggestFetcher(int id, |
226 const TemplateURL* template_url, | 222 const TemplateURL* template_url, |
227 const AutocompleteInput& input); | 223 const AutocompleteInput& input); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 base::TimeTicks time_suggest_request_sent_; | 342 base::TimeTicks time_suggest_request_sent_; |
347 | 343 |
348 // Fetchers used to retrieve results for the keyword and default providers. | 344 // Fetchers used to retrieve results for the keyword and default providers. |
349 scoped_ptr<net::URLFetcher> keyword_fetcher_; | 345 scoped_ptr<net::URLFetcher> keyword_fetcher_; |
350 scoped_ptr<net::URLFetcher> default_fetcher_; | 346 scoped_ptr<net::URLFetcher> default_fetcher_; |
351 | 347 |
352 // Results from the default and keyword search providers. | 348 // Results from the default and keyword search providers. |
353 SearchSuggestionParser::Results default_results_; | 349 SearchSuggestionParser::Results default_results_; |
354 SearchSuggestionParser::Results keyword_results_; | 350 SearchSuggestionParser::Results keyword_results_; |
355 | 351 |
356 // The top query suggestion, left blank if none. | |
357 base::string16 top_query_suggestion_match_contents_; | |
358 // The top navigation suggestion, left blank/invalid if none. | |
359 GURL top_navigation_suggestion_; | |
360 | |
361 GURL current_page_url_; | 352 GURL current_page_url_; |
362 | 353 |
363 // Session token management. | 354 // Session token management. |
364 std::string current_token_; | 355 std::string current_token_; |
365 base::TimeTicks token_expiration_time_; | 356 base::TimeTicks token_expiration_time_; |
366 | 357 |
367 // Answers prefetch management. | 358 // Answers prefetch management. |
368 AnswersQueryData prefetch_data_; // Data to use for query prefetching. | 359 AnswersQueryData prefetch_data_; // Data to use for query prefetching. |
369 AnswersQueryData last_answer_seen_; // Last answer seen. | 360 AnswersQueryData last_answer_seen_; // Last answer seen. |
370 | 361 |
371 DISALLOW_COPY_AND_ASSIGN(SearchProvider); | 362 DISALLOW_COPY_AND_ASSIGN(SearchProvider); |
372 }; | 363 }; |
373 | 364 |
374 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 365 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
OLD | NEW |