| 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 zero-suggest autocomplete provider. This experimental | 5 // This file contains the zero-suggest autocomplete provider. This experimental |
| 6 // provider is invoked when the user focuses in the omnibox prior to editing, | 6 // provider is invoked when the user focuses in the omnibox prior to editing, |
| 7 // and generates search query suggestions based on the current URL. To enable | 7 // and generates search query suggestions based on the current URL. To enable |
| 8 // this provider, point --experimental-zero-suggest-url-prefix at an | 8 // this provider, point --experimental-zero-suggest-url-prefix at an |
| 9 // appropriate suggestion service. | 9 // appropriate suggestion service. |
| 10 // | 10 // |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener, | 56 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener, |
| 57 TemplateURLService* template_url_service, | 57 TemplateURLService* template_url_service, |
| 58 Profile* profile); | 58 Profile* profile); |
| 59 | 59 |
| 60 // Registers a preference used to cache zero suggest results. | 60 // Registers a preference used to cache zero suggest results. |
| 61 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 61 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 62 | 62 |
| 63 // AutocompleteProvider: | 63 // AutocompleteProvider: |
| 64 virtual void Start(const AutocompleteInput& input, | 64 virtual void Start(const AutocompleteInput& input, |
| 65 bool minimal_changes) OVERRIDE; | 65 bool minimal_changes) OVERRIDE; |
| 66 virtual void Stop(bool clear_cached_results) OVERRIDE; |
| 66 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; | 67 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; |
| 68 virtual void AddProviderInfo(ProvidersInfo* provider_info) const OVERRIDE; |
| 67 | 69 |
| 68 // Sets |field_trial_triggered_| to false. | 70 // Sets |field_trial_triggered_| to false. |
| 69 virtual void ResetSession() OVERRIDE; | 71 virtual void ResetSession() OVERRIDE; |
| 70 | 72 |
| 71 protected: | |
| 72 // BaseSearchProvider: | |
| 73 virtual void ModifyProviderInfo( | |
| 74 metrics::OmniboxEventProto_ProviderInfo* provider_info) const OVERRIDE; | |
| 75 | |
| 76 private: | 73 private: |
| 77 ZeroSuggestProvider(AutocompleteProviderListener* listener, | 74 ZeroSuggestProvider(AutocompleteProviderListener* listener, |
| 78 TemplateURLService* template_url_service, | 75 TemplateURLService* template_url_service, |
| 79 Profile* profile); | 76 Profile* profile); |
| 80 | 77 |
| 81 virtual ~ZeroSuggestProvider(); | 78 virtual ~ZeroSuggestProvider(); |
| 82 | 79 |
| 83 // BaseSearchProvider: | |
| 84 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const OVERRIDE; | |
| 85 virtual const AutocompleteInput GetInput(bool is_keyword) const OVERRIDE; | |
| 86 virtual bool ShouldAppendExtraParams( | |
| 87 const SearchSuggestionParser::SuggestResult& result) const OVERRIDE; | |
| 88 virtual void StopSuggest() OVERRIDE; | |
| 89 virtual void ClearAllResults() OVERRIDE; | |
| 90 virtual void RecordDeletionResult(bool success) OVERRIDE; | |
| 91 | |
| 92 // net::URLFetcherDelegate: | 80 // net::URLFetcherDelegate: |
| 93 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 81 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
| 94 | 82 |
| 83 AutocompleteInput GetInput() const; |
| 84 |
| 95 // Optionally, cache the received |json_data| and return true if we want | 85 // Optionally, cache the received |json_data| and return true if we want |
| 96 // to stop processing results at this point. The |parsed_data| is the parsed | 86 // to stop processing results at this point. The |parsed_data| is the parsed |
| 97 // version of |json_data| used to determine if we received an empty result. | 87 // version of |json_data| used to determine if we received an empty result. |
| 98 bool StoreSuggestionResponse(const std::string& json_data, | 88 bool StoreSuggestionResponse(const std::string& json_data, |
| 99 const base::Value& parsed_data); | 89 const base::Value& parsed_data); |
| 100 | 90 |
| 101 // Adds AutocompleteMatches for each of the suggestions in |results| to | 91 // Adds AutocompleteMatches for each of the suggestions in |results| to |
| 102 // |map|. | 92 // |map|. |
| 103 void AddSuggestResultsToMap( | 93 void AddSuggestResultsToMap( |
| 104 const SearchSuggestionParser::SuggestResults& results, | 94 const SearchSuggestionParser::SuggestResults& results, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 155 |
| 166 history::MostVisitedURLList most_visited_urls_; | 156 history::MostVisitedURLList most_visited_urls_; |
| 167 | 157 |
| 168 // For callbacks that may be run after destruction. | 158 // For callbacks that may be run after destruction. |
| 169 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; | 159 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; |
| 170 | 160 |
| 171 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); | 161 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); |
| 172 }; | 162 }; |
| 173 | 163 |
| 174 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ | 164 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ |
| OLD | NEW |