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

Side by Side 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: more indentation changes 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/command_line.h" 10 #include "base/command_line.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // providers (such as SearchProvider) wait for the user to stop typing before 69 // providers (such as SearchProvider) wait for the user to stop typing before
70 // they initiate a query. 70 // they initiate a query.
71 const int kExpireTimeMS = 500; 71 const int kExpireTimeMS = 500;
72 72
73 } // namespace 73 } // namespace
74 74
75 const int AutocompleteController::kNoItemSelected = -1; 75 const int AutocompleteController::kNoItemSelected = -1;
76 76
77 AutocompleteController::AutocompleteController( 77 AutocompleteController::AutocompleteController(
78 Profile* profile, 78 Profile* profile,
79 AutocompleteControllerDelegate* delegate) 79 AutocompleteControllerDelegate* delegate,
80 int provider_types)
80 : delegate_(delegate), 81 : delegate_(delegate),
81 keyword_provider_(NULL), 82 keyword_provider_(NULL),
83 search_provider_(NULL),
82 zero_suggest_provider_(NULL), 84 zero_suggest_provider_(NULL),
83 done_(true), 85 done_(true),
84 in_start_(false), 86 in_start_(false),
85 in_zero_suggest_(false), 87 in_zero_suggest_(false),
86 profile_(profile) { 88 profile_(profile) {
87 search_provider_ = new SearchProvider(this, profile); 89 if (provider_types & AutocompleteProvider::TYPE_SEARCH) {
Peter Kasting 2012/09/11 00:05:39 Nit: I'd put all these in the same order as the en
Daniel Erat 2012/09/11 00:42:19 Done (had to do a bit of shuffling around since Hi
88 providers_.push_back(search_provider_); 90 search_provider_ = new SearchProvider(this, profile);
89 #if !defined(OS_ANDROID) 91 providers_.push_back(search_provider_);
90 // History quick provider is enabled on all platforms other than Android. 92 }
91 bool hqp_enabled = true; 93
92 providers_.push_back(new HistoryQuickProvider(this, profile)); 94 bool hqp_enabled = false;
93 // Search provider/"tab to search" is enabled on all platforms other than 95 // TODO(mrossetti): Permanently modify the HistoryURLProvider to not search
94 // Android. 96 // titles once HQP is turned on permanently.
95 keyword_provider_ = new KeywordProvider(this, profile);
96 providers_.push_back(keyword_provider_);
97 #else
98 // TODO(mrossetti): Remove the following and permanently modify the
99 // HistoryURLProvider to not search titles once HQP is turned on permanently.
100 // TODO(jcivelli): Enable the History Quick Provider and figure out why it 97 // TODO(jcivelli): Enable the History Quick Provider and figure out why it
101 // reports the wrong results for some pages. 98 // reports the wrong results for some pages.
102 bool hqp_enabled = false; 99 #if !defined(OS_ANDROID)
103 #endif // !OS_ANDROID 100 // History quick provider can be used on all platforms other than Android.
104 providers_.push_back(new HistoryURLProvider(this, profile)); 101 if (provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK) {
105 providers_.push_back(new ShortcutsProvider(this, profile)); 102 hqp_enabled = true;
106 providers_.push_back(new HistoryContentsProvider(this, profile, hqp_enabled)); 103 providers_.push_back(new HistoryQuickProvider(this, profile));
107 providers_.push_back(new BuiltinProvider(this, profile)); 104 }
108 providers_.push_back(new ExtensionAppProvider(this, profile)); 105
109 // Create ZeroSuggest if its switch is present. 106 if (provider_types & AutocompleteProvider::TYPE_KEYWORD) {
107 // Search provider/"tab to search" can be used on all platforms other than
108 // Android.
109 keyword_provider_ = new KeywordProvider(this, profile);
110 providers_.push_back(keyword_provider_);
111 }
112 #endif
113
114 if (provider_types & AutocompleteProvider::TYPE_HISTORY_URL)
115 providers_.push_back(new HistoryURLProvider(this, profile));
116 if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS)
117 providers_.push_back(new ShortcutsProvider(this, profile));
118 if (provider_types & AutocompleteProvider::TYPE_HISTORY_CONTENTS) {
119 providers_.push_back(
120 new HistoryContentsProvider(this, profile, hqp_enabled));
121 }
122 if (provider_types & AutocompleteProvider::TYPE_BUILTIN)
123 providers_.push_back(new BuiltinProvider(this, profile));
124 if (provider_types & AutocompleteProvider::TYPE_EXTENSION_APP)
125 providers_.push_back(new ExtensionAppProvider(this, profile));
126
110 CommandLine* cl = CommandLine::ForCurrentProcess(); 127 CommandLine* cl = CommandLine::ForCurrentProcess();
111 if (cl->HasSwitch(switches::kExperimentalZeroSuggestURLPrefix)) { 128 if ((provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) &&
129 cl->HasSwitch(switches::kExperimentalZeroSuggestURLPrefix)) {
112 zero_suggest_provider_ = new ZeroSuggestProvider(this, profile, 130 zero_suggest_provider_ = new ZeroSuggestProvider(this, profile,
113 cl->GetSwitchValueASCII(switches::kExperimentalZeroSuggestURLPrefix)); 131 cl->GetSwitchValueASCII(switches::kExperimentalZeroSuggestURLPrefix));
114 providers_.push_back(zero_suggest_provider_); 132 providers_.push_back(zero_suggest_provider_);
115 } 133 }
134
116 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) 135 for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i)
117 (*i)->AddRef(); 136 (*i)->AddRef();
118 } 137 }
119 138
120 AutocompleteController::~AutocompleteController() { 139 AutocompleteController::~AutocompleteController() {
121 // The providers may have tasks outstanding that hold refs to them. We need 140 // The providers may have tasks outstanding that hold refs to them. We need
122 // to ensure they won't call us back if they outlive us. (Practically, 141 // to ensure they won't call us back if they outlive us. (Practically,
123 // calling Stop() should also cancel those tasks and make it so that we hold 142 // calling Stop() should also cancel those tasks and make it so that we hold
124 // the only refs.) We also don't want to bother notifying anyone of our 143 // the only refs.) We also don't want to bother notifying anyone of our
125 // result changes here, because the notification observer is in the midst of 144 // result changes here, because the notification observer is in the midst of
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 } 456 }
438 done_ = true; 457 done_ = true;
439 } 458 }
440 459
441 void AutocompleteController::StartExpireTimer() { 460 void AutocompleteController::StartExpireTimer() {
442 if (result_.HasCopiedMatches()) 461 if (result_.HasCopiedMatches())
443 expire_timer_.Start(FROM_HERE, 462 expire_timer_.Start(FROM_HERE,
444 base::TimeDelta::FromMilliseconds(kExpireTimeMS), 463 base::TimeDelta::FromMilliseconds(kExpireTimeMS),
445 this, &AutocompleteController::ExpireCopiedEntries); 464 this, &AutocompleteController::ExpireCopiedEntries);
446 } 465 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698