| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 class contains common functionality for search-based autocomplete | 5 // This class contains common functionality for search-based autocomplete |
| 6 // providers. Search provider and zero suggest provider both use it for common | 6 // providers. Search provider and zero suggest provider both use it for common |
| 7 // functionality. | 7 // functionality. |
| 8 | 8 |
| 9 #ifndef CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 9 #ifndef CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
| 10 #define CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 10 #define CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // command-line-specified query params. | 120 // command-line-specified query params. |
| 121 static AutocompleteMatch CreateSearchSuggestion( | 121 static AutocompleteMatch CreateSearchSuggestion( |
| 122 AutocompleteProvider* autocomplete_provider, | 122 AutocompleteProvider* autocomplete_provider, |
| 123 const AutocompleteInput& input, | 123 const AutocompleteInput& input, |
| 124 const SearchSuggestionParser::SuggestResult& suggestion, | 124 const SearchSuggestionParser::SuggestResult& suggestion, |
| 125 const TemplateURL* template_url, | 125 const TemplateURL* template_url, |
| 126 const SearchTermsData& search_terms_data, | 126 const SearchTermsData& search_terms_data, |
| 127 int accepted_suggestion, | 127 int accepted_suggestion, |
| 128 bool append_extra_query_params); | 128 bool append_extra_query_params); |
| 129 | 129 |
| 130 // Parses JSON response received from the provider, stripping XSSI | |
| 131 // protection if needed. Returns the parsed data if successful, NULL | |
| 132 // otherwise. | |
| 133 static scoped_ptr<base::Value> DeserializeJsonData(std::string json_data); | |
| 134 | |
| 135 // Returns whether the requirements for requesting zero suggest results | 130 // Returns whether the requirements for requesting zero suggest results |
| 136 // are met. The requirements are | 131 // are met. The requirements are |
| 137 // * The user is enrolled in a zero suggest experiment. | 132 // * The user is enrolled in a zero suggest experiment. |
| 138 // * The user is not on the NTP. | 133 // * The user is not on the NTP. |
| 139 // * The suggest request is sent over HTTPS. This avoids leaking the current | 134 // * The suggest request is sent over HTTPS. This avoids leaking the current |
| 140 // page URL or personal data in unencrypted network traffic. | 135 // page URL or personal data in unencrypted network traffic. |
| 141 // * The user has suggest enabled in their settings and is not in incognito | 136 // * The user has suggest enabled in their settings and is not in incognito |
| 142 // mode. (Incognito disables suggest entirely.) | 137 // mode. (Incognito disables suggest entirely.) |
| 143 // * The user's suggest provider is Google. We might want to allow other | 138 // * The user's suggest provider is Google. We might want to allow other |
| 144 // providers to see this data someday, but for now this has only been | 139 // providers to see this data someday, but for now this has only been |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // Parses results from the suggest server and updates the appropriate suggest | 192 // Parses results from the suggest server and updates the appropriate suggest |
| 198 // and navigation result lists in |results|. |is_keyword_result| indicates | 193 // and navigation result lists in |results|. |is_keyword_result| indicates |
| 199 // whether the response was received from the keyword provider. | 194 // whether the response was received from the keyword provider. |
| 200 // Returns whether the appropriate result list members were updated. | 195 // Returns whether the appropriate result list members were updated. |
| 201 bool ParseSuggestResults(const base::Value& root_val, | 196 bool ParseSuggestResults(const base::Value& root_val, |
| 202 bool is_keyword_result, | 197 bool is_keyword_result, |
| 203 SearchSuggestionParser::Results* results); | 198 SearchSuggestionParser::Results* results); |
| 204 | 199 |
| 205 // Called at the end of ParseSuggestResults to rank the |results|. | 200 // Called at the end of ParseSuggestResults to rank the |results|. |
| 206 virtual void SortResults(bool is_keyword, | 201 virtual void SortResults(bool is_keyword, |
| 207 bool relevances_from_server, | |
| 208 SearchSuggestionParser::Results* results); | 202 SearchSuggestionParser::Results* results); |
| 209 | 203 |
| 210 // Optionally, cache the received |json_data| and return true if we want | 204 // Optionally, cache the received |json_data| and return true if we want |
| 211 // to stop processing results at this point. The |parsed_data| is the parsed | 205 // to stop processing results at this point. The |parsed_data| is the parsed |
| 212 // version of |json_data| used to determine if we received an empty result. | 206 // version of |json_data| used to determine if we received an empty result. |
| 213 virtual bool StoreSuggestionResponse(const std::string& json_data, | 207 virtual bool StoreSuggestionResponse(const std::string& json_data, |
| 214 const base::Value& parsed_data); | 208 const base::Value& parsed_data); |
| 215 | 209 |
| 216 // Returns the TemplateURL corresponding to the keyword or default | 210 // Returns the TemplateURL corresponding to the keyword or default |
| 217 // provider based on the value of |is_keyword|. | 211 // provider based on the value of |is_keyword|. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 283 |
| 290 // Each deletion handler in this vector corresponds to an outstanding request | 284 // Each deletion handler in this vector corresponds to an outstanding request |
| 291 // that a server delete a personalized suggestion. Making this a ScopedVector | 285 // that a server delete a personalized suggestion. Making this a ScopedVector |
| 292 // causes us to auto-cancel all such requests on shutdown. | 286 // causes us to auto-cancel all such requests on shutdown. |
| 293 SuggestionDeletionHandlers deletion_handlers_; | 287 SuggestionDeletionHandlers deletion_handlers_; |
| 294 | 288 |
| 295 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); | 289 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); |
| 296 }; | 290 }; |
| 297 | 291 |
| 298 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 292 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
| OLD | NEW |