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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 void set_current_page_url(const GURL& current_page_url) { | 68 void set_current_page_url(const GURL& current_page_url) { |
69 current_page_url_ = current_page_url; | 69 current_page_url_ = current_page_url; |
70 } | 70 } |
71 | 71 |
72 protected: | 72 protected: |
73 virtual ~SearchProvider(); | 73 virtual ~SearchProvider(); |
74 | 74 |
75 private: | 75 private: |
76 friend class SearchProviderTest; | 76 friend class SearchProviderTest; |
77 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, CanSendURL); | 77 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, CanSendURL); |
| 78 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, |
| 79 DontInlineAutocompleteAsynchronously); |
78 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInline); | 80 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInline); |
79 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineDomainClassify); | 81 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineDomainClassify); |
80 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineSchemeSubstring); | 82 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, NavigationInlineSchemeSubstring); |
81 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, RemoveStaleResultsTest); | |
82 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestRelevanceExperiment); | 83 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestRelevanceExperiment); |
83 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, TestDeleteMatch); | 84 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, TestDeleteMatch); |
84 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestQueryUsesToken); | 85 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SuggestQueryUsesToken); |
85 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SessionToken); | 86 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, SessionToken); |
86 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, AnswersCache); | 87 FRIEND_TEST_ALL_PREFIXES(SearchProviderTest, AnswersCache); |
87 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); | 88 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); |
88 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, ClearPrefetchedResults); | 89 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, ClearPrefetchedResults); |
89 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, SetPrefetchQuery); | 90 FRIEND_TEST_ALL_PREFIXES(InstantExtendedPrefetchTest, SetPrefetchQuery); |
90 | 91 |
91 // Manages the providers (TemplateURLs) used by SearchProvider. Two providers | 92 // Manages the providers (TemplateURLs) used by SearchProvider. Two providers |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 base::string16 default_provider_; | 133 base::string16 default_provider_; |
133 base::string16 keyword_provider_; | 134 base::string16 keyword_provider_; |
134 | 135 |
135 DISALLOW_COPY_AND_ASSIGN(Providers); | 136 DISALLOW_COPY_AND_ASSIGN(Providers); |
136 }; | 137 }; |
137 | 138 |
138 class CompareScoredResults; | 139 class CompareScoredResults; |
139 | 140 |
140 typedef std::vector<history::KeywordSearchTermVisit> HistoryResults; | 141 typedef std::vector<history::KeywordSearchTermVisit> HistoryResults; |
141 | 142 |
142 // Removes non-inlineable results until either the top result can inline | |
143 // autocomplete the current input or verbatim outscores the top result. | |
144 static void RemoveStaleResults( | |
145 const base::string16& input, | |
146 int verbatim_relevance, | |
147 SearchSuggestionParser::SuggestResults* suggest_results, | |
148 SearchSuggestionParser::NavigationResults* navigation_results); | |
149 | |
150 // Calculates the relevance score for the keyword verbatim result (if the | 143 // Calculates the relevance score for the keyword verbatim result (if the |
151 // input matches one of the profile's keyword). | 144 // input matches one of the profile's keyword). |
152 static int CalculateRelevanceForKeywordVerbatim( | 145 static int CalculateRelevanceForKeywordVerbatim( |
153 metrics::OmniboxInputType::Type type, | 146 metrics::OmniboxInputType::Type type, |
154 bool prefer_keyword); | 147 bool prefer_keyword); |
155 | 148 |
| 149 // A helper function for UpdateAllOldResults(). |
| 150 static void UpdateOldResults(bool minimal_changes, |
| 151 SearchSuggestionParser::Results* results); |
| 152 |
| 153 // Returns the first match in |matches| which might be chosen as default. |
| 154 static ACMatches::iterator FindTopMatch(ACMatches* matches); |
| 155 |
156 // AutocompleteProvider: | 156 // AutocompleteProvider: |
157 virtual void Start(const AutocompleteInput& input, | 157 virtual void Start(const AutocompleteInput& input, |
158 bool minimal_changes) OVERRIDE; | 158 bool minimal_changes) OVERRIDE; |
159 virtual void Stop(bool clear_cached_results) OVERRIDE; | 159 virtual void Stop(bool clear_cached_results) OVERRIDE; |
160 | 160 |
161 // BaseSearchProvider: | 161 // BaseSearchProvider: |
162 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const OVERRIDE; | 162 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const OVERRIDE; |
163 virtual const AutocompleteInput GetInput(bool is_keyword) const OVERRIDE; | 163 virtual const AutocompleteInput GetInput(bool is_keyword) const OVERRIDE; |
164 virtual bool ShouldAppendExtraParams( | 164 virtual bool ShouldAppendExtraParams( |
165 const SearchSuggestionParser::SuggestResult& result) const OVERRIDE; | 165 const SearchSuggestionParser::SuggestResult& result) const OVERRIDE; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // Determines whether an asynchronous subcomponent query should run for the | 200 // Determines whether an asynchronous subcomponent query should run for the |
201 // current input. If so, starts it if necessary; otherwise stops it. | 201 // current input. If so, starts it if necessary; otherwise stops it. |
202 // NOTE: This function does not update |done_|. Callers must do so. | 202 // NOTE: This function does not update |done_|. Callers must do so. |
203 void StartOrStopSuggestQuery(bool minimal_changes); | 203 void StartOrStopSuggestQuery(bool minimal_changes); |
204 | 204 |
205 // 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. |
206 // 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 |
207 // potentially private data, etc. | 207 // potentially private data, etc. |
208 bool IsQuerySuitableForSuggest() const; | 208 bool IsQuerySuitableForSuggest() const; |
209 | 209 |
210 // 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, |
211 // on RemoveStaleResults(). | 211 // and, if |minimal_changes| is false, revise the existing results to |
212 void RemoveAllStaleResults(); | 212 // indicate they were received before the last keystroke. |
| 213 void UpdateAllOldResults(bool minimal_changes); |
| 214 |
| 215 // Given new asynchronous results, ensure that we don't clobber the current |
| 216 // top results, which were determined synchronously on the last keystroke. |
| 217 void PersistTopSuggestions(SearchSuggestionParser::Results* results); |
213 | 218 |
214 // Apply calculated relevance scores to the current results. | 219 // Apply calculated relevance scores to the current results. |
215 void ApplyCalculatedRelevance(); | |
216 void ApplyCalculatedSuggestRelevance( | 220 void ApplyCalculatedSuggestRelevance( |
217 SearchSuggestionParser::SuggestResults* list); | 221 SearchSuggestionParser::SuggestResults* list); |
218 void ApplyCalculatedNavigationRelevance( | 222 void ApplyCalculatedNavigationRelevance( |
219 SearchSuggestionParser::NavigationResults* list); | 223 SearchSuggestionParser::NavigationResults* list); |
220 | 224 |
221 // Starts a new URLFetcher requesting suggest results from |template_url|; | 225 // Starts a new URLFetcher requesting suggest results from |template_url|; |
222 // callers own the returned URLFetcher, which is NULL for invalid providers. | 226 // callers own the returned URLFetcher, which is NULL for invalid providers. |
223 net::URLFetcher* CreateSuggestFetcher(int id, | 227 net::URLFetcher* CreateSuggestFetcher(int id, |
224 const TemplateURL* template_url, | 228 const TemplateURL* template_url, |
225 const AutocompleteInput& input); | 229 const AutocompleteInput& input); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 base::TimeTicks time_suggest_request_sent_; | 348 base::TimeTicks time_suggest_request_sent_; |
345 | 349 |
346 // Fetchers used to retrieve results for the keyword and default providers. | 350 // Fetchers used to retrieve results for the keyword and default providers. |
347 scoped_ptr<net::URLFetcher> keyword_fetcher_; | 351 scoped_ptr<net::URLFetcher> keyword_fetcher_; |
348 scoped_ptr<net::URLFetcher> default_fetcher_; | 352 scoped_ptr<net::URLFetcher> default_fetcher_; |
349 | 353 |
350 // Results from the default and keyword search providers. | 354 // Results from the default and keyword search providers. |
351 SearchSuggestionParser::Results default_results_; | 355 SearchSuggestionParser::Results default_results_; |
352 SearchSuggestionParser::Results keyword_results_; | 356 SearchSuggestionParser::Results keyword_results_; |
353 | 357 |
| 358 // The top query suggestion, left blank if none. |
| 359 base::string16 top_query_suggestion_match_contents_; |
| 360 // The top navigation suggestion, left blank/invalid if none. |
| 361 GURL top_navigation_suggestion_; |
| 362 |
354 GURL current_page_url_; | 363 GURL current_page_url_; |
355 | 364 |
356 // Session token management. | 365 // Session token management. |
357 std::string current_token_; | 366 std::string current_token_; |
358 base::TimeTicks token_expiration_time_; | 367 base::TimeTicks token_expiration_time_; |
359 | 368 |
360 // Answers prefetch management. | 369 // Answers prefetch management. |
361 AnswersCache answers_cache_; // Cache for last answers seen. | 370 AnswersCache answers_cache_; // Cache for last answers seen. |
362 AnswersQueryData prefetch_data_; // Data to use for query prefetching. | 371 AnswersQueryData prefetch_data_; // Data to use for query prefetching. |
363 | 372 |
364 DISALLOW_COPY_AND_ASSIGN(SearchProvider); | 373 DISALLOW_COPY_AND_ASSIGN(SearchProvider); |
365 }; | 374 }; |
366 | 375 |
367 #endif // COMPONENTS_OMNIBOX_SEARCH_PROVIDER_H_ | 376 #endif // COMPONENTS_OMNIBOX_SEARCH_PROVIDER_H_ |
OLD | NEW |