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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // Start() with some user input, each time expecting to receive an updated | 44 // Start() with some user input, each time expecting to receive an updated |
45 // set of matches. | 45 // set of matches. |
46 // | 46 // |
47 // TODO(jered): Consider deleting this class and building this functionality | 47 // TODO(jered): Consider deleting this class and building this functionality |
48 // into SearchProvider after dogfood and after we break the association between | 48 // into SearchProvider after dogfood and after we break the association between |
49 // omnibox text and suggestions. | 49 // omnibox text and suggestions. |
50 class ZeroSuggestProvider : public BaseSearchProvider { | 50 class ZeroSuggestProvider : public BaseSearchProvider { |
51 public: | 51 public: |
52 // Creates and returns an instance of this provider. | 52 // Creates and returns an instance of this provider. |
53 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener, | 53 static ZeroSuggestProvider* Create(AutocompleteProviderListener* listener, |
| 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 virtual void Start(const AutocompleteInput& input, | 61 virtual void Start(const AutocompleteInput& input, |
61 bool minimal_changes) OVERRIDE; | 62 bool minimal_changes) OVERRIDE; |
62 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; | 63 virtual void DeleteMatch(const AutocompleteMatch& match) OVERRIDE; |
63 | 64 |
64 // Sets |field_trial_triggered_| to false. | 65 // Sets |field_trial_triggered_| to false. |
65 virtual void ResetSession() OVERRIDE; | 66 virtual void ResetSession() OVERRIDE; |
66 | 67 |
67 protected: | 68 protected: |
68 // BaseSearchProvider: | 69 // BaseSearchProvider: |
69 virtual void ModifyProviderInfo( | 70 virtual void ModifyProviderInfo( |
70 metrics::OmniboxEventProto_ProviderInfo* provider_info) const OVERRIDE; | 71 metrics::OmniboxEventProto_ProviderInfo* provider_info) const OVERRIDE; |
71 | 72 |
72 private: | 73 private: |
73 ZeroSuggestProvider(AutocompleteProviderListener* listener, | 74 ZeroSuggestProvider(AutocompleteProviderListener* listener, |
| 75 TemplateURLService* template_url_service, |
74 Profile* profile); | 76 Profile* profile); |
75 | 77 |
76 virtual ~ZeroSuggestProvider(); | 78 virtual ~ZeroSuggestProvider(); |
77 | 79 |
78 // BaseSearchProvider: | 80 // BaseSearchProvider: |
79 virtual bool StoreSuggestionResponse(const std::string& json_data, | 81 virtual bool StoreSuggestionResponse(const std::string& json_data, |
80 const base::Value& parsed_data) OVERRIDE; | 82 const base::Value& parsed_data) OVERRIDE; |
81 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const OVERRIDE; | 83 virtual const TemplateURL* GetTemplateURL(bool is_keyword) const OVERRIDE; |
82 virtual const AutocompleteInput GetInput(bool is_keyword) const OVERRIDE; | 84 virtual const AutocompleteInput GetInput(bool is_keyword) const OVERRIDE; |
83 virtual SearchSuggestionParser::Results* GetResultsToFill( | 85 virtual SearchSuggestionParser::Results* GetResultsToFill( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 127 |
126 // Whether we can show zero suggest on |current_page_url| without | 128 // Whether we can show zero suggest on |current_page_url| without |
127 // sending |current_page_url| as a parameter to the server at |suggest_url|. | 129 // sending |current_page_url| as a parameter to the server at |suggest_url|. |
128 bool CanShowZeroSuggestWithoutSendingURL(const GURL& suggest_url, | 130 bool CanShowZeroSuggestWithoutSendingURL(const GURL& suggest_url, |
129 const GURL& current_page_url) const; | 131 const GURL& current_page_url) const; |
130 | 132 |
131 // Checks whether we have a set of zero suggest results cached, and if so | 133 // Checks whether we have a set of zero suggest results cached, and if so |
132 // populates |matches_| with cached results. | 134 // populates |matches_| with cached results. |
133 void MaybeUseCachedSuggestions(); | 135 void MaybeUseCachedSuggestions(); |
134 | 136 |
135 // Used to build default search engine URLs for suggested queries. | |
136 TemplateURLService* template_url_service_; | |
137 | |
138 // The URL for which a suggestion fetch is pending. | 137 // The URL for which a suggestion fetch is pending. |
139 std::string current_query_; | 138 std::string current_query_; |
140 | 139 |
141 // The type of page the user is viewing (a search results page doing search | 140 // The type of page the user is viewing (a search results page doing search |
142 // term replacement, an arbitrary URL, etc.). | 141 // term replacement, an arbitrary URL, etc.). |
143 metrics::OmniboxEventProto::PageClassification current_page_classification_; | 142 metrics::OmniboxEventProto::PageClassification current_page_classification_; |
144 | 143 |
145 // Copy of OmniboxEditModel::permanent_text_. | 144 // Copy of OmniboxEditModel::permanent_text_. |
146 base::string16 permanent_text_; | 145 base::string16 permanent_text_; |
147 | 146 |
(...skipping 12 matching lines...) Expand all Loading... |
160 | 159 |
161 history::MostVisitedURLList most_visited_urls_; | 160 history::MostVisitedURLList most_visited_urls_; |
162 | 161 |
163 // For callbacks that may be run after destruction. | 162 // For callbacks that may be run after destruction. |
164 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; | 163 base::WeakPtrFactory<ZeroSuggestProvider> weak_ptr_factory_; |
165 | 164 |
166 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); | 165 DISALLOW_COPY_AND_ASSIGN(ZeroSuggestProvider); |
167 }; | 166 }; |
168 | 167 |
169 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ | 168 #endif // CHROME_BROWSER_AUTOCOMPLETE_ZERO_SUGGEST_PROVIDER_H_ |
OLD | NEW |