Chromium Code Reviews| 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 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 const TemplateURL& default_provider() const { | 112 const TemplateURL& default_provider() const { |
| 113 DCHECK(valid_default_provider()); | 113 DCHECK(valid_default_provider()); |
| 114 return cached_default_provider_; | 114 return cached_default_provider_; |
| 115 } | 115 } |
| 116 | 116 |
| 117 const TemplateURL& keyword_provider() const { | 117 const TemplateURL& keyword_provider() const { |
| 118 DCHECK(valid_keyword_provider()); | 118 DCHECK(valid_keyword_provider()); |
| 119 return cached_keyword_provider_; | 119 return cached_keyword_provider_; |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Returns true of the keyword provider is valid. | 122 // Returns true if the default provider is valid. |
| 123 bool valid_default_provider() const { return !!default_provider_; } | |
|
sky
2012/04/10 16:16:22
nit: !! is obscure.
Peter Kasting
2012/04/10 17:53:44
It is, but I'm just moving this code up from below
| |
| 124 | |
| 125 // Returns true if the default provider is valid and has a valid suggest | |
| 126 // url. | |
| 127 bool valid_suggest_for_default_provider() const { | |
| 128 return default_provider_ && | |
| 129 !cached_default_provider_.suggestions_url().empty(); | |
| 130 } | |
| 131 | |
| 132 // Returns true if the keyword provider is valid. | |
| 123 bool valid_keyword_provider() const { return !!keyword_provider_; } | 133 bool valid_keyword_provider() const { return !!keyword_provider_; } |
| 124 | 134 |
| 125 // Returns true if the keyword provider is valid and has a valid suggest | 135 // Returns true if the keyword provider is valid and has a valid suggest |
| 126 // url. | 136 // url. |
| 127 bool valid_suggest_for_keyword_provider() const { | 137 bool valid_suggest_for_keyword_provider() const { |
| 128 return keyword_provider_ && | 138 return keyword_provider_ && |
| 129 !cached_keyword_provider_.suggestions_url().empty(); | 139 !cached_keyword_provider_.suggestions_url().empty(); |
| 130 } | 140 } |
| 131 | 141 |
| 132 // Returns true of the default provider is valid. | |
| 133 bool valid_default_provider() const { return !!default_provider_; } | |
| 134 | |
| 135 // Returns true if the default provider is valid and has a valid suggest | |
| 136 // url. | |
| 137 bool valid_suggest_for_default_provider() const { | |
| 138 return default_provider_ && | |
| 139 !cached_default_provider_.suggestions_url().empty(); | |
| 140 } | |
| 141 | |
| 142 // Returns true if |from_keyword_provider| is true, or | 142 // Returns true if |from_keyword_provider| is true, or |
| 143 // the keyword provider is not valid. | 143 // the keyword provider is not valid. |
| 144 bool is_primary_provider(bool from_keyword_provider) const { | 144 bool is_primary_provider(bool from_keyword_provider) const { |
| 145 return from_keyword_provider || !valid_keyword_provider(); | 145 return from_keyword_provider || !valid_keyword_provider(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 private: | 148 private: |
| 149 // Cached across the life of a query so we behave consistently even if the | 149 // Cached across the life of a query so we behave consistently even if the |
| 150 // user changes their default while the query is running. | 150 // user changes their default while the query is running. |
| 151 TemplateURL cached_default_provider_; | 151 TemplateURL cached_default_provider_; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 // Returns true when the current query can be sent to the Suggest service. | 195 // Returns true when the current query can be sent to the Suggest service. |
| 196 // This will be false e.g. when Suggest is disabled, the query contains | 196 // This will be false e.g. when Suggest is disabled, the query contains |
| 197 // potentially private data, etc. | 197 // potentially private data, etc. |
| 198 bool IsQuerySuitableForSuggest() const; | 198 bool IsQuerySuitableForSuggest() const; |
| 199 | 199 |
| 200 // Stops the suggest query. | 200 // Stops the suggest query. |
| 201 // NOTE: This does not update |done_|. Callers must do so. | 201 // NOTE: This does not update |done_|. Callers must do so. |
| 202 void StopSuggest(); | 202 void StopSuggest(); |
| 203 | 203 |
| 204 // Creates a URLFetcher requesting suggest results from the specified | 204 // Creates a URLFetcher requesting suggest results from the specified |
| 205 // |provider|. The caller owns the returned URLFetcher. | 205 // |suggestions_url|. The caller owns the returned URLFetcher. |
| 206 content::URLFetcher* CreateSuggestFetcher(int id, | 206 content::URLFetcher* CreateSuggestFetcher( |
| 207 const TemplateURL& provider, | 207 int id, |
| 208 const string16& text); | 208 const TemplateURLRef& suggestions_url, |
| 209 const string16& text); | |
| 209 | 210 |
| 210 // Parses the results from the Suggest server and stores up to kMaxMatches of | 211 // Parses the results from the Suggest server and stores up to kMaxMatches of |
| 211 // them in server_results_. Returns whether parsing succeeded. | 212 // them in server_results_. Returns whether parsing succeeded. |
| 212 bool ParseSuggestResults(base::Value* root_val, | 213 bool ParseSuggestResults(base::Value* root_val, |
| 213 bool is_keyword, | 214 bool is_keyword, |
| 214 const string16& input_text, | 215 const string16& input_text, |
| 215 SuggestResults* suggest_results); | 216 SuggestResults* suggest_results); |
| 216 | 217 |
| 217 // Converts the parsed server results in server_results_ to a set of | 218 // Converts the parsed server results in server_results_ to a set of |
| 218 // AutocompleteMatches and adds them to |matches_|. This also sets |done_| | 219 // AutocompleteMatches and adds them to |matches_|. This also sets |done_| |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 // Has FinalizeInstantQuery been invoked since the last |Start|? | 336 // Has FinalizeInstantQuery been invoked since the last |Start|? |
| 336 bool instant_finalized_; | 337 bool instant_finalized_; |
| 337 | 338 |
| 338 // The |suggest_text| parameter passed to FinalizeInstantQuery. | 339 // The |suggest_text| parameter passed to FinalizeInstantQuery. |
| 339 string16 default_provider_suggest_text_; | 340 string16 default_provider_suggest_text_; |
| 340 | 341 |
| 341 DISALLOW_COPY_AND_ASSIGN(SearchProvider); | 342 DISALLOW_COPY_AND_ASSIGN(SearchProvider); |
| 342 }; | 343 }; |
| 343 | 344 |
| 344 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ | 345 #endif // CHROME_BROWSER_AUTOCOMPLETE_SEARCH_PROVIDER_H_ |
| OLD | NEW |