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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 // AutocompleteProvider: | 70 // AutocompleteProvider: |
71 virtual void Stop(bool clear_cached_results) OVERRIDE; | 71 virtual void Stop(bool clear_cached_results) OVERRIDE; |
72 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; | 72 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; |
73 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; | 73 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; |
74 | 74 |
75 bool field_trial_triggered_in_session() const { | 75 bool field_trial_triggered_in_session() const { |
76 return field_trial_triggered_in_session_; | 76 return field_trial_triggered_in_session_; |
77 } | 77 } |
78 | 78 |
79 void set_in_app_list() { in_app_list_ = true; } | |
80 | |
81 protected: | 79 protected: |
82 // The following keys are used to record additional information on matches. | 80 // The following keys are used to record additional information on matches. |
83 | 81 |
84 // We annotate our AutocompleteMatches with whether their relevance scores | 82 // We annotate our AutocompleteMatches with whether their relevance scores |
85 // were server-provided using this key in the |additional_info| field. | 83 // were server-provided using this key in the |additional_info| field. |
86 static const char kRelevanceFromServerKey[]; | 84 static const char kRelevanceFromServerKey[]; |
87 | 85 |
88 // Indicates whether the server said a match should be prefetched. | 86 // Indicates whether the server said a match should be prefetched. |
89 static const char kShouldPrefetchKey[]; | 87 static const char kShouldPrefetchKey[]; |
90 | 88 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 // portions of the match contents to distinguish locally-typed text from | 332 // portions of the match contents to distinguish locally-typed text from |
335 // suggested text. | 333 // suggested text. |
336 // | 334 // |
337 // |input| is also necessary for various other details, like whether we should | 335 // |input| is also necessary for various other details, like whether we should |
338 // allow inline autocompletion and what the transition type should be. | 336 // allow inline autocompletion and what the transition type should be. |
339 // |accepted_suggestion| and |omnibox_start_margin| are used to generate | 337 // |accepted_suggestion| and |omnibox_start_margin| are used to generate |
340 // Assisted Query Stats. | 338 // Assisted Query Stats. |
341 // |append_extra_query_params| should be set if |template_url| is the default | 339 // |append_extra_query_params| should be set if |template_url| is the default |
342 // search engine, so the destination URL will contain any | 340 // search engine, so the destination URL will contain any |
343 // command-line-specified query params. | 341 // command-line-specified query params. |
344 // |from_app_list| should be set if the search was made from the app list. | |
345 static AutocompleteMatch CreateSearchSuggestion( | 342 static AutocompleteMatch CreateSearchSuggestion( |
346 AutocompleteProvider* autocomplete_provider, | 343 AutocompleteProvider* autocomplete_provider, |
347 const AutocompleteInput& input, | 344 const AutocompleteInput& input, |
348 const SuggestResult& suggestion, | 345 const SuggestResult& suggestion, |
349 const TemplateURL* template_url, | 346 const TemplateURL* template_url, |
350 const SearchTermsData& search_terms_data, | 347 const SearchTermsData& search_terms_data, |
351 int accepted_suggestion, | 348 int accepted_suggestion, |
352 int omnibox_start_margin, | 349 int omnibox_start_margin, |
353 bool append_extra_query_params, | 350 bool append_extra_query_params); |
354 bool from_app_list); | |
355 | 351 |
356 // Parses JSON response received from the provider, stripping XSSI | 352 // Parses JSON response received from the provider, stripping XSSI |
357 // protection if needed. Returns the parsed data if successful, NULL | 353 // protection if needed. Returns the parsed data if successful, NULL |
358 // otherwise. | 354 // otherwise. |
359 static scoped_ptr<base::Value> DeserializeJsonData(std::string json_data); | 355 static scoped_ptr<base::Value> DeserializeJsonData(std::string json_data); |
360 | 356 |
361 // Returns whether the requirements for requesting zero suggest results | 357 // Returns whether the requirements for requesting zero suggest results |
362 // are met. The requirements are | 358 // are met. The requirements are |
363 // * The user is enrolled in a zero suggest experiment. | 359 // * The user is enrolled in a zero suggest experiment. |
364 // * The user is not on the NTP. | 360 // * The user is not on the NTP. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 // server to handle the results of the deletion. It will be called after the | 508 // server to handle the results of the deletion. It will be called after the |
513 // deletion request completes. | 509 // deletion request completes. |
514 void OnDeletionComplete(bool success, | 510 void OnDeletionComplete(bool success, |
515 SuggestionDeletionHandler* handler); | 511 SuggestionDeletionHandler* handler); |
516 | 512 |
517 // Each deletion handler in this vector corresponds to an outstanding request | 513 // Each deletion handler in this vector corresponds to an outstanding request |
518 // that a server delete a personalized suggestion. Making this a ScopedVector | 514 // that a server delete a personalized suggestion. Making this a ScopedVector |
519 // causes us to auto-cancel all such requests on shutdown. | 515 // causes us to auto-cancel all such requests on shutdown. |
520 SuggestionDeletionHandlers deletion_handlers_; | 516 SuggestionDeletionHandlers deletion_handlers_; |
521 | 517 |
522 // True if this provider's results are being displayed in the app list. By | |
523 // default this is false, meaning that the results will be shown in the | |
524 // omnibox. | |
525 bool in_app_list_; | |
526 | |
527 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); | 518 DISALLOW_COPY_AND_ASSIGN(BaseSearchProvider); |
528 }; | 519 }; |
529 | 520 |
530 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ | 521 #endif // CHROME_BROWSER_AUTOCOMPLETE_BASE_SEARCH_PROVIDER_H_ |
OLD | NEW |