Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1291)

Unified Diff: chrome/browser/autocomplete/autocomplete_controller.cc

Issue 10909130: autocomplete: Add AutocompleteProvider::Type enum. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix inadvertently-change parameter in test Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autocomplete/autocomplete_controller.cc
diff --git a/chrome/browser/autocomplete/autocomplete_controller.cc b/chrome/browser/autocomplete/autocomplete_controller.cc
index 5c8d7720f41461dc2b406da4d9ddaec52302ece1..fff3d6b6df9a49057158ba8c08328622ed829f60 100644
--- a/chrome/browser/autocomplete/autocomplete_controller.cc
+++ b/chrome/browser/autocomplete/autocomplete_controller.cc
@@ -20,8 +20,6 @@
#include "chrome/browser/autocomplete/history_contents_provider.h"
#include "chrome/browser/autocomplete/history_quick_provider.h"
#include "chrome/browser/autocomplete/history_url_provider.h"
-#include "chrome/browser/autocomplete/keyword_provider.h"
-#include "chrome/browser/autocomplete/search_provider.h"
#include "chrome/browser/autocomplete/shortcuts_provider.h"
#include "chrome/browser/autocomplete/zero_suggest_provider.h"
#include "chrome/browser/profiles/profile.h"
@@ -76,43 +74,62 @@ const int AutocompleteController::kNoItemSelected = -1;
AutocompleteController::AutocompleteController(
Profile* profile,
- AutocompleteControllerDelegate* delegate)
+ AutocompleteControllerDelegate* delegate,
+ int provider_types)
: delegate_(delegate),
keyword_provider_(NULL),
+ search_provider_(NULL),
zero_suggest_provider_(NULL),
done_(true),
in_start_(false),
in_zero_suggest_(false),
profile_(profile) {
- search_provider_ = new SearchProvider(this, profile);
- providers_.push_back(search_provider_);
-#if !defined(OS_ANDROID)
- // History quick provider is enabled on all platforms other than Android.
- bool hqp_enabled = true;
- providers_.push_back(new HistoryQuickProvider(this, profile));
- // Search provider/"tab to search" is enabled on all platforms other than
- // Android.
- keyword_provider_ = new KeywordProvider(this, profile);
- providers_.push_back(keyword_provider_);
-#else
- // TODO(mrossetti): Remove the following and permanently modify the
- // HistoryURLProvider to not search titles once HQP is turned on permanently.
+ // TODO(mrossetti): Permanently modify the HistoryURLProvider to not search
+ // titles once HQP is turned on permanently.
// TODO(jcivelli): Enable the History Quick Provider and figure out why it
// reports the wrong results for some pages.
- bool hqp_enabled = false;
-#endif // !OS_ANDROID
- providers_.push_back(new HistoryURLProvider(this, profile));
- providers_.push_back(new ShortcutsProvider(this, profile));
- providers_.push_back(new HistoryContentsProvider(this, profile, hqp_enabled));
- providers_.push_back(new BuiltinProvider(this, profile));
- providers_.push_back(new ExtensionAppProvider(this, profile));
- // Create ZeroSuggest if its switch is present.
+ bool use_hqp = false;
+#if !defined(OS_ANDROID)
+ // History quick provider can be used on all platforms other than Android.
Peter Kasting 2012/09/11 01:38:42 Nit: I'd move this comment to just below the other
Daniel Erat 2012/09/11 02:09:22 Done.
+ if (provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK)
Peter Kasting 2012/09/11 01:38:42 Nit: Simpler: use_hqp = (provider_types & Autoc
Daniel Erat 2012/09/11 02:09:22 Done.
+ use_hqp = true;
+#endif
+
+ if (provider_types & AutocompleteProvider::TYPE_BUILTIN)
+ providers_.push_back(new BuiltinProvider(this, profile));
+ if (provider_types & AutocompleteProvider::TYPE_EXTENSION_APP)
+ providers_.push_back(new ExtensionAppProvider(this, profile));
+ if (provider_types & AutocompleteProvider::TYPE_HISTORY_CONTENTS)
+ providers_.push_back(new HistoryContentsProvider(this, profile, use_hqp));
+#if !defined(OS_ANDROID)
Peter Kasting 2012/09/11 01:38:42 Nit: No need for this #ifdef (handled above)
Daniel Erat 2012/09/11 02:09:22 Ah. I was thinking that we might not be compiling
+ if (use_hqp)
+ providers_.push_back(new HistoryQuickProvider(this, profile));
+#endif
+ if (provider_types & AutocompleteProvider::TYPE_HISTORY_URL)
+ providers_.push_back(new HistoryURLProvider(this, profile));
+#if !defined(OS_ANDROID)
+ if (provider_types & AutocompleteProvider::TYPE_KEYWORD) {
+ // Search provider/"tab to search" can be used on all platforms other than
Peter Kasting 2012/09/11 01:38:42 Nit: I'd move this comment to just above the #ifde
Daniel Erat 2012/09/11 02:09:22 Done.
+ // Android.
+ keyword_provider_ = new KeywordProvider(this, profile);
+ providers_.push_back(keyword_provider_);
+ }
+#endif
+ if (provider_types & AutocompleteProvider::TYPE_SEARCH) {
+ search_provider_ = new SearchProvider(this, profile);
+ providers_.push_back(search_provider_);
+ }
+ if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS)
+ providers_.push_back(new ShortcutsProvider(this, profile));
+
CommandLine* cl = CommandLine::ForCurrentProcess();
- if (cl->HasSwitch(switches::kExperimentalZeroSuggestURLPrefix)) {
+ if ((provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) &&
+ cl->HasSwitch(switches::kExperimentalZeroSuggestURLPrefix)) {
zero_suggest_provider_ = new ZeroSuggestProvider(this, profile,
cl->GetSwitchValueASCII(switches::kExperimentalZeroSuggestURLPrefix));
providers_.push_back(zero_suggest_provider_);
}
+
for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i)
(*i)->AddRef();
}
@@ -393,8 +410,9 @@ void AutocompleteController::UpdateKeywordDescriptions(
string16 last_keyword;
for (AutocompleteResult::iterator i(result->begin()); i != result->end();
++i) {
- if ((i->provider == keyword_provider_ && !i->keyword.empty()) ||
- (i->provider == search_provider_ &&
+ if ((i->provider->type() == AutocompleteProvider::TYPE_KEYWORD &&
+ !i->keyword.empty()) ||
+ (i->provider->type() == AutocompleteProvider::TYPE_SEARCH &&
AutocompleteMatch::IsSearchType(i->type))) {
i->description.clear();
i->description_class.clear();

Powered by Google App Engine
This is Rietveld 408576698