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/bookmark_provider.h" | 17 #include "chrome/browser/autocomplete/bookmark_provider.h" |
18 #include "chrome/browser/autocomplete/builtin_provider.h" | 18 #include "chrome/browser/autocomplete/builtin_provider.h" |
19 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" | |
20 #include "chrome/browser/autocomplete/history_quick_provider.h" | 19 #include "chrome/browser/autocomplete/history_quick_provider.h" |
21 #include "chrome/browser/autocomplete/history_url_provider.h" | 20 #include "chrome/browser/autocomplete/history_url_provider.h" |
22 #include "chrome/browser/autocomplete/in_memory_url_index_factory.h" | 21 #include "chrome/browser/autocomplete/in_memory_url_index_factory.h" |
23 #include "chrome/browser/autocomplete/shortcuts_provider.h" | 22 #include "chrome/browser/autocomplete/shortcuts_provider.h" |
24 #include "chrome/browser/autocomplete/zero_suggest_provider.h" | 23 #include "chrome/browser/autocomplete/zero_suggest_provider.h" |
25 #include "chrome/browser/chrome_notification_types.h" | 24 #include "chrome/browser/chrome_notification_types.h" |
26 #include "components/omnibox/keyword_provider.h" | 25 #include "components/omnibox/keyword_provider.h" |
27 #include "components/omnibox/omnibox_field_trial.h" | 26 #include "components/omnibox/omnibox_field_trial.h" |
28 #include "components/omnibox/search_provider.h" | 27 #include "components/omnibox/search_provider.h" |
29 #include "components/search_engines/template_url.h" | 28 #include "components/search_engines/template_url.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 AutocompleteController::AutocompleteController( | 170 AutocompleteController::AutocompleteController( |
172 Profile* profile, | 171 Profile* profile, |
173 TemplateURLService* template_url_service, | 172 TemplateURLService* template_url_service, |
174 AutocompleteControllerDelegate* delegate, | 173 AutocompleteControllerDelegate* delegate, |
175 int provider_types) | 174 int provider_types) |
176 : delegate_(delegate), | 175 : delegate_(delegate), |
177 history_url_provider_(NULL), | 176 history_url_provider_(NULL), |
178 keyword_provider_(NULL), | 177 keyword_provider_(NULL), |
179 search_provider_(NULL), | 178 search_provider_(NULL), |
180 zero_suggest_provider_(NULL), | 179 zero_suggest_provider_(NULL), |
180 provider_client_(new ChromeAutocompleteProviderClient(profile)), | |
181 stop_timer_duration_(OmniboxFieldTrial::StopTimerFieldTrialDuration()), | 181 stop_timer_duration_(OmniboxFieldTrial::StopTimerFieldTrialDuration()), |
182 done_(true), | 182 done_(true), |
183 in_start_(false), | 183 in_start_(false), |
184 template_url_service_(template_url_service) { | 184 template_url_service_(template_url_service) { |
185 provider_types &= ~OmniboxFieldTrial::GetDisabledProviderTypes(); | 185 provider_types &= ~OmniboxFieldTrial::GetDisabledProviderTypes(); |
186 if (provider_types & AutocompleteProvider::TYPE_BOOKMARK) | 186 if (provider_types & AutocompleteProvider::TYPE_BOOKMARK) |
187 providers_.push_back(new BookmarkProvider(profile)); | 187 providers_.push_back(new BookmarkProvider(profile)); |
188 if (provider_types & AutocompleteProvider::TYPE_BUILTIN) | 188 if (provider_types & AutocompleteProvider::TYPE_BUILTIN) |
189 providers_.push_back(new BuiltinProvider()); | 189 providers_.push_back(new BuiltinProvider()); |
190 if (provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK) { | 190 if (provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK) { |
191 providers_.push_back(new HistoryQuickProvider( | 191 providers_.push_back(new HistoryQuickProvider( |
192 profile, InMemoryURLIndexFactory::GetForProfile(profile))); | 192 provider_client_.get(), profile, |
193 InMemoryURLIndexFactory::GetForProfile(profile))); | |
193 } | 194 } |
194 if (provider_types & AutocompleteProvider::TYPE_HISTORY_URL) { | 195 if (provider_types & AutocompleteProvider::TYPE_HISTORY_URL) { |
195 history_url_provider_ = new HistoryURLProvider(this, profile); | 196 history_url_provider_ = |
197 new HistoryURLProvider(provider_client_.get(), this, profile); | |
196 providers_.push_back(history_url_provider_); | 198 providers_.push_back(history_url_provider_); |
197 } | 199 } |
198 // "Tab to search" can be used on all platforms other than Android. | 200 // "Tab to search" can be used on all platforms other than Android. |
199 #if !defined(OS_ANDROID) | 201 #if !defined(OS_ANDROID) |
200 if (provider_types & AutocompleteProvider::TYPE_KEYWORD) { | 202 if (provider_types & AutocompleteProvider::TYPE_KEYWORD) { |
201 keyword_provider_ = new KeywordProvider(this, template_url_service); | 203 keyword_provider_ = new KeywordProvider(this, template_url_service); |
202 #if defined(ENABLE_EXTENSIONS) | 204 #if defined(ENABLE_EXTENSIONS) |
203 keyword_provider_->set_extensions_delegate( | 205 keyword_provider_->set_extensions_delegate( |
204 scoped_ptr<KeywordExtensionsDelegate>( | 206 scoped_ptr<KeywordExtensionsDelegate>( |
205 new KeywordExtensionsDelegateImpl(profile, keyword_provider_))); | 207 new KeywordExtensionsDelegateImpl(profile, keyword_provider_))); |
206 #endif | 208 #endif |
207 providers_.push_back(keyword_provider_); | 209 providers_.push_back(keyword_provider_); |
208 } | 210 } |
209 #endif | 211 #endif |
210 if (provider_types & AutocompleteProvider::TYPE_SEARCH) { | 212 if (provider_types & AutocompleteProvider::TYPE_SEARCH) { |
211 search_provider_ = new SearchProvider( | 213 search_provider_ = |
212 this, template_url_service, scoped_ptr<AutocompleteProviderClient>( | 214 new SearchProvider(this, template_url_service, provider_client_.get()); |
Peter Kasting
2015/06/16 00:03:42
Nit: If you're going to do it in the history provi
blundell
2015/06/16 07:21:25
Done.
| |
213 new ChromeAutocompleteProviderClient(profile))); | |
214 providers_.push_back(search_provider_); | 215 providers_.push_back(search_provider_); |
215 } | 216 } |
216 if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS) | 217 if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS) |
217 providers_.push_back(new ShortcutsProvider(profile)); | 218 providers_.push_back(new ShortcutsProvider(profile)); |
218 if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) { | 219 if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) { |
219 zero_suggest_provider_ = ZeroSuggestProvider::Create( | 220 zero_suggest_provider_ = ZeroSuggestProvider::Create( |
220 this, template_url_service, profile); | 221 this, template_url_service, profile, provider_client_.get()); |
221 if (zero_suggest_provider_) | 222 if (zero_suggest_provider_) |
222 providers_.push_back(zero_suggest_provider_); | 223 providers_.push_back(zero_suggest_provider_); |
223 } | 224 } |
224 } | 225 } |
225 | 226 |
226 AutocompleteController::~AutocompleteController() { | 227 AutocompleteController::~AutocompleteController() { |
227 // The providers may have tasks outstanding that hold refs to them. We need | 228 // The providers may have tasks outstanding that hold refs to them. We need |
228 // to ensure they won't call us back if they outlive us. (Practically, | 229 // to ensure they won't call us back if they outlive us. (Practically, |
229 // calling Stop() should also cancel those tasks and make it so that we hold | 230 // calling Stop() should also cancel those tasks and make it so that we hold |
230 // the only refs.) We also don't want to bother notifying anyone of our | 231 // the only refs.) We also don't want to bother notifying anyone of our |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
667 expire_timer_.Stop(); | 668 expire_timer_.Stop(); |
668 stop_timer_.Stop(); | 669 stop_timer_.Stop(); |
669 done_ = true; | 670 done_ = true; |
670 if (clear_result && !result_.empty()) { | 671 if (clear_result && !result_.empty()) { |
671 result_.Reset(); | 672 result_.Reset(); |
672 // NOTE: We pass in false since we're trying to only clear the popup, not | 673 // NOTE: We pass in false since we're trying to only clear the popup, not |
673 // touch the edit... this is all a mess and should be cleaned up :( | 674 // touch the edit... this is all a mess and should be cleaned up :( |
674 NotifyChanged(false); | 675 NotifyChanged(false); |
675 } | 676 } |
676 } | 677 } |
OLD | NEW |