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. | 7 // and generates search query suggestions based on the current URL. |
8 | 8 |
9 #ifndef CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ | 9 #ifndef CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ |
10 #define CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ | 10 #define CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // Start() with some user input, each time expecting to receive an updated set | 42 // Start() with some user input, each time expecting to receive an updated set |
43 // of matches. | 43 // of matches. |
44 // | 44 // |
45 // TODO(jered): Consider deleting this class and building this functionality | 45 // TODO(jered): Consider deleting this class and building this functionality |
46 // into SearchProvider after dogfood and after we break the association between | 46 // into SearchProvider after dogfood and after we break the association between |
47 // omnibox text and suggestions. | 47 // omnibox text and suggestions. |
48 class ZeroSuggestProvider : public BaseSearchProvider, | 48 class ZeroSuggestProvider : public BaseSearchProvider, |
49 public net::URLFetcherDelegate { | 49 public net::URLFetcherDelegate { |
50 public: | 50 public: |
51 // Creates and returns an instance of this provider. | 51 // Creates and returns an instance of this provider. |
52 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener, | 52 static ZeroSuggestProvider* Create(AutocompleteProviderClient* client, |
| 53 AutocompleteProviderListener* listener, |
53 TemplateURLService* template_url_service, | 54 TemplateURLService* template_url_service, |
54 Profile* profile); | 55 Profile* profile); |
55 | 56 |
56 // Registers a preference used to cache zero suggest results. | 57 // Registers a preference used to cache zero suggest results. |
57 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 58 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
58 | 59 |
59 // AutocompleteProvider: | 60 // AutocompleteProvider: |
60 void Start(const AutocompleteInput& input, | 61 void Start(const AutocompleteInput& input, |
61 bool minimal_changes, | 62 bool minimal_changes, |
62 bool called_due_to_focus) override; | 63 bool called_due_to_focus) override; |
63 void Stop(bool clear_cached_results, | 64 void Stop(bool clear_cached_results, |
64 bool due_to_user_inactivity) override; | 65 bool due_to_user_inactivity) override; |
65 void DeleteMatch(const AutocompleteMatch& match) override; | 66 void DeleteMatch(const AutocompleteMatch& match) override; |
66 void AddProviderInfo(ProvidersInfo* provider_info) const override; | 67 void AddProviderInfo(ProvidersInfo* provider_info) const override; |
67 | 68 |
68 // Sets |field_trial_triggered_| to false. | 69 // Sets |field_trial_triggered_| to false. |
69 void ResetSession() override; | 70 void ResetSession() override; |
70 | 71 |
71 private: | 72 private: |
72 ZeroSuggestProvider(AutocompleteProviderListener* listener, | 73 ZeroSuggestProvider(AutocompleteProviderClient* client, |
| 74 AutocompleteProviderListener* listener, |
73 TemplateURLService* template_url_service, | 75 TemplateURLService* template_url_service, |
74 Profile* profile); | 76 Profile* profile); |
75 | 77 |
76 ~ZeroSuggestProvider() override; | 78 ~ZeroSuggestProvider() override; |
77 | 79 |
78 // BaseSearchProvider: | 80 // BaseSearchProvider: |
79 const TemplateURL* GetTemplateURL(bool is_keyword) const override; | 81 const TemplateURL* GetTemplateURL(bool is_keyword) const override; |
80 const AutocompleteInput GetInput(bool is_keyword) const override; | 82 const AutocompleteInput GetInput(bool is_keyword) const override; |
81 bool ShouldAppendExtraParams( | 83 bool ShouldAppendExtraParams( |
82 const SearchSuggestionParser::SuggestResult& result) const override; | 84 const SearchSuggestionParser::SuggestResult& result) const override; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // Whether we are waiting for a most visited visited urls callback to run. | 165 // Whether we are waiting for a most visited visited urls callback to run. |
164 bool waiting_for_most_visited_urls_request_; | 166 bool waiting_for_most_visited_urls_request_; |
165 | 167 |
166 // For callbacks that may be run after destruction. | 168 // For callbacks that may be run after destruction. |
167 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; | 169 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; |
168 | 170 |
169 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); | 171 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); |
170 }; | 172 }; |
171 | 173 |
172 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ | 174 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ |
OLD | NEW |