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 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 5 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" | 16 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" |
17 #include "chrome/browser/autocomplete/builtin_provider.h" | 17 #include "chrome/browser/autocomplete/builtin_provider.h" |
18 #include "chrome/browser/autocomplete/in_memory_url_index_factory.h" | |
19 #include "chrome/browser/autocomplete/zero_suggest_provider.h" | 18 #include "chrome/browser/autocomplete/zero_suggest_provider.h" |
20 #include "components/omnibox/bookmark_provider.h" | 19 #include "components/omnibox/bookmark_provider.h" |
21 #include "components/omnibox/history_quick_provider.h" | 20 #include "components/omnibox/history_quick_provider.h" |
22 #include "components/omnibox/history_url_provider.h" | 21 #include "components/omnibox/history_url_provider.h" |
23 #include "components/omnibox/keyword_provider.h" | 22 #include "components/omnibox/keyword_provider.h" |
24 #include "components/omnibox/omnibox_field_trial.h" | 23 #include "components/omnibox/omnibox_field_trial.h" |
25 #include "components/omnibox/search_provider.h" | 24 #include "components/omnibox/search_provider.h" |
26 #include "components/omnibox/shortcuts_provider.h" | 25 #include "components/omnibox/shortcuts_provider.h" |
27 #include "components/search_engines/template_url.h" | 26 #include "components/search_engines/template_url.h" |
28 #include "components/search_engines/template_url_service.h" | 27 #include "components/search_engines/template_url_service.h" |
29 #include "grit/components_strings.h" | 28 #include "grit/components_strings.h" |
30 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
31 | 30 |
32 #if defined(ENABLE_EXTENSIONS) | |
33 #include "chrome/browser/autocomplete/keyword_extensions_delegate_impl.h" | |
34 #endif | |
35 | |
36 namespace { | 31 namespace { |
37 | 32 |
38 // Converts the given match to a type (and possibly subtype) based on the AQS | 33 // Converts the given match to a type (and possibly subtype) based on the AQS |
39 // specification. For more details, see | 34 // specification. For more details, see |
40 // http://goto.google.com/binary-clients-logging. | 35 // http://goto.google.com/binary-clients-logging. |
41 void AutocompleteMatchToAssistedQuery( | 36 void AutocompleteMatchToAssistedQuery( |
42 const AutocompleteMatch::Type& match, | 37 const AutocompleteMatch::Type& match, |
43 const AutocompleteProvider* provider, | 38 const AutocompleteProvider* provider, |
44 size_t* type, | 39 size_t* type, |
45 size_t* subtype) { | 40 size_t* subtype) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
159 | 154 |
160 // Whether this autocomplete match type supports custom descriptions. | 155 // Whether this autocomplete match type supports custom descriptions. |
161 bool AutocompleteMatchHasCustomDescription(const AutocompleteMatch& match) { | 156 bool AutocompleteMatchHasCustomDescription(const AutocompleteMatch& match) { |
162 return match.type == AutocompleteMatchType::SEARCH_SUGGEST_ENTITY || | 157 return match.type == AutocompleteMatchType::SEARCH_SUGGEST_ENTITY || |
163 match.type == AutocompleteMatchType::SEARCH_SUGGEST_PROFILE; | 158 match.type == AutocompleteMatchType::SEARCH_SUGGEST_PROFILE; |
164 } | 159 } |
165 | 160 |
166 } // namespace | 161 } // namespace |
167 | 162 |
168 AutocompleteController::AutocompleteController( | 163 AutocompleteController::AutocompleteController( |
169 Profile* profile, | 164 scoped_ptr<AutocompleteProviderClient> provider_client, |
170 TemplateURLService* template_url_service, | |
171 AutocompleteControllerDelegate* delegate, | 165 AutocompleteControllerDelegate* delegate, |
172 int provider_types) | 166 int provider_types) |
173 : delegate_(delegate), | 167 : delegate_(delegate), |
174 provider_client_(new ChromeAutocompleteProviderClient(profile)), | 168 provider_client_(provider_client.Pass()), |
175 history_url_provider_(NULL), | 169 history_url_provider_(NULL), |
176 keyword_provider_(NULL), | 170 keyword_provider_(NULL), |
177 search_provider_(NULL), | 171 search_provider_(NULL), |
178 zero_suggest_provider_(NULL), | 172 zero_suggest_provider_(NULL), |
179 stop_timer_duration_(OmniboxFieldTrial::StopTimerFieldTrialDuration()), | 173 stop_timer_duration_(OmniboxFieldTrial::StopTimerFieldTrialDuration()), |
180 done_(true), | 174 done_(true), |
181 in_start_(false), | 175 in_start_(false), |
182 template_url_service_(template_url_service) { | 176 template_url_service_(provider_client_->GetTemplateURLService()) { |
183 provider_types &= ~OmniboxFieldTrial::GetDisabledProviderTypes(); | 177 provider_types &= ~OmniboxFieldTrial::GetDisabledProviderTypes(); |
184 if (provider_types & AutocompleteProvider::TYPE_BOOKMARK) | 178 if (provider_types & AutocompleteProvider::TYPE_BOOKMARK) |
185 providers_.push_back(new BookmarkProvider(provider_client_.get())); | 179 providers_.push_back(new BookmarkProvider(provider_client_.get())); |
186 if (provider_types & AutocompleteProvider::TYPE_BUILTIN) | 180 if (provider_types & AutocompleteProvider::TYPE_BUILTIN) |
187 providers_.push_back(new BuiltinProvider()); | 181 providers_.push_back(new BuiltinProvider()); |
188 if (provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK) { | 182 |
189 providers_.push_back(new HistoryQuickProvider( | 183 if (provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK) |
Peter Kasting
2015/06/19 19:19:21
Nit: Why blank lines above and below this particul
blundell
2015/06/22 09:01:36
Done.
| |
190 provider_client_.get(), | 184 providers_.push_back(new HistoryQuickProvider(provider_client_.get())); |
191 InMemoryURLIndexFactory::GetForProfile(profile))); | 185 |
192 } | |
193 if (provider_types & AutocompleteProvider::TYPE_HISTORY_URL) { | 186 if (provider_types & AutocompleteProvider::TYPE_HISTORY_URL) { |
194 history_url_provider_ = | 187 history_url_provider_ = |
195 new HistoryURLProvider(provider_client_.get(), this); | 188 new HistoryURLProvider(provider_client_.get(), this); |
196 providers_.push_back(history_url_provider_); | 189 providers_.push_back(history_url_provider_); |
197 } | 190 } |
198 // "Tab to search" can be used on all platforms other than Android. | 191 // "Tab to search" can be used on all platforms other than Android. |
199 #if !defined(OS_ANDROID) | 192 #if !defined(OS_ANDROID) |
200 if (provider_types & AutocompleteProvider::TYPE_KEYWORD) { | 193 if (provider_types & AutocompleteProvider::TYPE_KEYWORD) { |
201 keyword_provider_ = new KeywordProvider(this, template_url_service); | 194 keyword_provider_ = new KeywordProvider(this, template_url_service_); |
202 #if defined(ENABLE_EXTENSIONS) | 195 provider_client_->ConfigureKeywordProvider(keyword_provider_); |
203 keyword_provider_->set_extensions_delegate( | |
204 scoped_ptr<KeywordExtensionsDelegate>( | |
205 new KeywordExtensionsDelegateImpl(profile, keyword_provider_))); | |
206 #endif | |
207 providers_.push_back(keyword_provider_); | 196 providers_.push_back(keyword_provider_); |
208 } | 197 } |
209 #endif | 198 #endif |
210 if (provider_types & AutocompleteProvider::TYPE_SEARCH) { | 199 if (provider_types & AutocompleteProvider::TYPE_SEARCH) { |
211 search_provider_ = | 200 search_provider_ = |
212 new SearchProvider(provider_client_.get(), this, template_url_service); | 201 new SearchProvider(provider_client_.get(), this, template_url_service_); |
213 providers_.push_back(search_provider_); | 202 providers_.push_back(search_provider_); |
214 } | 203 } |
215 if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS) | 204 if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS) |
216 providers_.push_back(new ShortcutsProvider(provider_client_.get())); | 205 providers_.push_back(new ShortcutsProvider(provider_client_.get())); |
217 if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) { | 206 if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) { |
218 zero_suggest_provider_ = ZeroSuggestProvider::Create( | 207 zero_suggest_provider_ = ZeroSuggestProvider::Create( |
219 provider_client_.get(), this, template_url_service); | 208 provider_client_.get(), this, template_url_service_); |
220 if (zero_suggest_provider_) | 209 if (zero_suggest_provider_) |
221 providers_.push_back(zero_suggest_provider_); | 210 providers_.push_back(zero_suggest_provider_); |
222 } | 211 } |
223 } | 212 } |
224 | 213 |
225 AutocompleteController::~AutocompleteController() { | 214 AutocompleteController::~AutocompleteController() { |
226 // The providers may have tasks outstanding that hold refs to them. We need | 215 // The providers may have tasks outstanding that hold refs to them. We need |
227 // to ensure they won't call us back if they outlive us. (Practically, | 216 // to ensure they won't call us back if they outlive us. (Practically, |
228 // calling Stop() should also cancel those tasks and make it so that we hold | 217 // calling Stop() should also cancel those tasks and make it so that we hold |
229 // the only refs.) We also don't want to bother notifying anyone of our | 218 // the only refs.) We also don't want to bother notifying anyone of our |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 expire_timer_.Stop(); | 642 expire_timer_.Stop(); |
654 stop_timer_.Stop(); | 643 stop_timer_.Stop(); |
655 done_ = true; | 644 done_ = true; |
656 if (clear_result && !result_.empty()) { | 645 if (clear_result && !result_.empty()) { |
657 result_.Reset(); | 646 result_.Reset(); |
658 // NOTE: We pass in false since we're trying to only clear the popup, not | 647 // NOTE: We pass in false since we're trying to only clear the popup, not |
659 // touch the edit... this is all a mess and should be cleaned up :( | 648 // touch the edit... this is all a mess and should be cleaned up :( |
660 NotifyChanged(false); | 649 NotifyChanged(false); |
661 } | 650 } |
662 } | 651 } |
OLD | NEW |