OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 non-keyword autocomplete entries that start with | 6 // responsible for all non-keyword autocomplete entries that start with |
7 // "Search <engine> for ...", including searching for the current input string, | 7 // "Search <engine> for ...", including searching for the current input string, |
8 // search history, and search suggestions. An instance of it gets created and | 8 // search 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 // the instant result. | 64 // the instant result. |
65 void FinalizeInstantQuery(const string16& input_text, | 65 void FinalizeInstantQuery(const string16& input_text, |
66 const string16& suggest_text); | 66 const string16& suggest_text); |
67 | 67 |
68 // AutocompleteProvider | 68 // AutocompleteProvider |
69 virtual void Start(const AutocompleteInput& input, | 69 virtual void Start(const AutocompleteInput& input, |
70 bool minimal_changes) OVERRIDE; | 70 bool minimal_changes) OVERRIDE; |
71 virtual void Stop() OVERRIDE; | 71 virtual void Stop() OVERRIDE; |
72 | 72 |
73 // content::URLFetcherDelegate | 73 // content::URLFetcherDelegate |
74 virtual void OnURLFetchComplete(const URLFetcher* source); | 74 virtual void OnURLFetchComplete(const content::URLFetcher* source); |
75 | 75 |
76 // ID used in creating URLFetcher for default provider's suggest results. | 76 // ID used in creating URLFetcher for default provider's suggest results. |
77 static const int kDefaultProviderURLFetcherID; | 77 static const int kDefaultProviderURLFetcherID; |
78 | 78 |
79 // ID used in creating URLFetcher for keyword provider's suggest results. | 79 // ID used in creating URLFetcher for keyword provider's suggest results. |
80 static const int kKeywordProviderURLFetcherID; | 80 static const int kKeywordProviderURLFetcherID; |
81 | 81 |
82 private: | 82 private: |
83 virtual ~SearchProvider(); | 83 virtual ~SearchProvider(); |
84 | 84 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 // This will be false e.g. when Suggest is disabled, the query contains | 187 // This will be false e.g. when Suggest is disabled, the query contains |
188 // potentially private data, etc. | 188 // potentially private data, etc. |
189 bool IsQuerySuitableForSuggest() const; | 189 bool IsQuerySuitableForSuggest() const; |
190 | 190 |
191 // Stops the suggest query. | 191 // Stops the suggest query. |
192 // NOTE: This does not update |done_|. Callers must do so. | 192 // NOTE: This does not update |done_|. Callers must do so. |
193 void StopSuggest(); | 193 void StopSuggest(); |
194 | 194 |
195 // Creates a URLFetcher requesting suggest results for the specified | 195 // Creates a URLFetcher requesting suggest results for the specified |
196 // TemplateURL. Ownership of the returned URLFetchet passes to the caller. | 196 // TemplateURL. Ownership of the returned URLFetchet passes to the caller. |
197 URLFetcher* CreateSuggestFetcher(int id, | 197 content::URLFetcher* CreateSuggestFetcher(int id, |
198 const TemplateURL& provider, | 198 const TemplateURL& provider, |
199 const string16& text); | 199 const string16& text); |
200 | 200 |
201 // Parses the results from the Suggest server and stores up to kMaxMatches of | 201 // Parses the results from the Suggest server and stores up to kMaxMatches of |
202 // them in server_results_. Returns whether parsing succeeded. | 202 // them in server_results_. Returns whether parsing succeeded. |
203 bool ParseSuggestResults(base::Value* root_val, | 203 bool ParseSuggestResults(base::Value* root_val, |
204 bool is_keyword, | 204 bool is_keyword, |
205 const string16& input_text, | 205 const string16& input_text, |
206 SuggestResults* suggest_results); | 206 SuggestResults* suggest_results); |
207 | 207 |
208 // Converts the parsed server results in server_results_ to a set of | 208 // Converts the parsed server results in server_results_ to a set of |
209 // AutocompleteMatches and adds them to |matches_|. This also sets |done_| | 209 // AutocompleteMatches and adds them to |matches_|. This also sets |done_| |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 | 299 |
300 // Number of suggest results that haven't yet arrived. If greater than 0 it | 300 // Number of suggest results that haven't yet arrived. If greater than 0 it |
301 // indicates either |timer_| or one of the URLFetchers is still running. | 301 // indicates either |timer_| or one of the URLFetchers is still running. |
302 int suggest_results_pending_; | 302 int suggest_results_pending_; |
303 | 303 |
304 // A timer to start a query to the suggest server after the user has stopped | 304 // A timer to start a query to the suggest server after the user has stopped |
305 // typing for long enough. | 305 // typing for long enough. |
306 base::OneShotTimer<SearchProvider> timer_; | 306 base::OneShotTimer<SearchProvider> timer_; |
307 | 307 |
308 // The fetcher that retrieves suggest results for the keyword from the server. | 308 // The fetcher that retrieves suggest results for the keyword from the server. |
309 scoped_ptr<URLFetcher> keyword_fetcher_; | 309 scoped_ptr<content::URLFetcher> keyword_fetcher_; |
310 | 310 |
311 // The fetcher that retrieves suggest results for the default engine from the | 311 // The fetcher that retrieves suggest results for the default engine from the |
312 // server. | 312 // server. |
313 scoped_ptr<URLFetcher> default_fetcher_; | 313 scoped_ptr<content::URLFetcher> default_fetcher_; |
314 | 314 |
315 // Suggestions returned by the Suggest server for the input text. | 315 // Suggestions returned by the Suggest server for the input text. |
316 SuggestResults keyword_suggest_results_; | 316 SuggestResults keyword_suggest_results_; |
317 SuggestResults default_suggest_results_; | 317 SuggestResults default_suggest_results_; |
318 | 318 |
319 // Navigational suggestions returned by the server. | 319 // Navigational suggestions returned by the server. |
320 NavigationResults keyword_navigation_results_; | 320 NavigationResults keyword_navigation_results_; |
321 NavigationResults default_navigation_results_; | 321 NavigationResults default_navigation_results_; |
322 | 322 |
323 // Whether suggest_results_ is valid. | 323 // Whether suggest_results_ is valid. |
324 bool have_suggest_results_; | 324 bool have_suggest_results_; |
325 | 325 |
326 // Has FinalizeInstantQuery been invoked since the last |Start|? | 326 // Has FinalizeInstantQuery been invoked since the last |Start|? |
327 bool instant_finalized_; | 327 bool instant_finalized_; |
328 | 328 |
329 // The |suggest_text| parameter passed to FinalizeInstantQuery. | 329 // The |suggest_text| parameter passed to FinalizeInstantQuery. |
330 string16 default_provider_suggest_text_; | 330 string16 default_provider_suggest_text_; |
331 | 331 |
332 DISALLOW_COPY_AND_ASSIGN(SearchProvider); | 332 DISALLOW_COPY_AND_ASSIGN(SearchProvider); |
333 }; | 333 }; |
334 | 334 |
335 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 335 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
OLD | NEW |