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 if (provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK) |
189 providers_.push_back(new HistoryQuickProvider( | 183 providers_.push_back(new HistoryQuickProvider(provider_client_.get())); |
190 provider_client_.get(), | |
191 InMemoryURLIndexFactory::GetForProfile(profile))); | |
192 } | |
193 if (provider_types & AutocompleteProvider::TYPE_HISTORY_URL) { | 184 if (provider_types & AutocompleteProvider::TYPE_HISTORY_URL) { |
194 history_url_provider_ = | 185 history_url_provider_ = |
195 new HistoryURLProvider(provider_client_.get(), this); | 186 new HistoryURLProvider(provider_client_.get(), this); |
196 providers_.push_back(history_url_provider_); | 187 providers_.push_back(history_url_provider_); |
197 } | 188 } |
198 // "Tab to search" can be used on all platforms other than Android. | 189 // "Tab to search" can be used on all platforms other than Android. |
199 #if !defined(OS_ANDROID) | 190 #if !defined(OS_ANDROID) |
200 if (provider_types & AutocompleteProvider::TYPE_KEYWORD) { | 191 if (provider_types & AutocompleteProvider::TYPE_KEYWORD) { |
201 keyword_provider_ = new KeywordProvider(this, template_url_service); | 192 keyword_provider_ = new KeywordProvider(provider_client_.get(), this); |
202 #if defined(ENABLE_EXTENSIONS) | |
203 keyword_provider_->set_extensions_delegate( | |
204 scoped_ptr<KeywordExtensionsDelegate>( | |
205 new KeywordExtensionsDelegateImpl(profile, keyword_provider_))); | |
206 #endif | |
207 providers_.push_back(keyword_provider_); | 193 providers_.push_back(keyword_provider_); |
208 } | 194 } |
209 #endif | 195 #endif |
210 if (provider_types & AutocompleteProvider::TYPE_SEARCH) { | 196 if (provider_types & AutocompleteProvider::TYPE_SEARCH) { |
211 search_provider_ = new SearchProvider(provider_client_.get(), this); | 197 search_provider_ = new SearchProvider(provider_client_.get(), this); |
212 providers_.push_back(search_provider_); | 198 providers_.push_back(search_provider_); |
213 } | 199 } |
214 if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS) | 200 if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS) |
215 providers_.push_back(new ShortcutsProvider(provider_client_.get())); | 201 providers_.push_back(new ShortcutsProvider(provider_client_.get())); |
216 if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) { | 202 if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) { |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 expire_timer_.Stop(); | 638 expire_timer_.Stop(); |
653 stop_timer_.Stop(); | 639 stop_timer_.Stop(); |
654 done_ = true; | 640 done_ = true; |
655 if (clear_result && !result_.empty()) { | 641 if (clear_result && !result_.empty()) { |
656 result_.Reset(); | 642 result_.Reset(); |
657 // NOTE: We pass in false since we're trying to only clear the popup, not | 643 // NOTE: We pass in false since we're trying to only clear the popup, not |
658 // touch the edit... this is all a mess and should be cleaned up :( | 644 // touch the edit... this is all a mess and should be cleaned up :( |
659 NotifyChanged(false); | 645 NotifyChanged(false); |
660 } | 646 } |
661 } | 647 } |
OLD | NEW |