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

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: update comments 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),
82 zero_suggest_provider_(NULL), 83 zero_suggest_provider_(NULL),
83 done_(true), 84 done_(true),
84 in_start_(false), 85 in_start_(false),
85 in_zero_suggest_(false), 86 in_zero_suggest_(false),
86 profile_(profile) { 87 profile_(profile) {
87 search_provider_ = new SearchProvider(this, profile); 88 if (provider_types & AutocompleteProvider::TYPE_SEARCH) {
88 providers_.push_back(search_provider_); 89 search_provider_ = new SearchProvider(this, profile);
89 #if !defined(OS_ANDROID) 90 providers_.push_back(search_provider_);
90 // History quick provider is enabled on all platforms other than Android. 91 }
91 bool hqp_enabled = true; 92
92 providers_.push_back(new HistoryQuickProvider(this, profile)); 93 bool hqp_enabled = false;
93 // Search provider/"tab to search" is enabled on all platforms other than 94 // TODO(mrossetti): Permanently modify the HistoryURLProvider to not search
94 // Android. 95 // 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 96 // TODO(jcivelli): Enable the History Quick Provider and figure out why it
101 // reports the wrong results for some pages. 97 // reports the wrong results for some pages.
102 bool hqp_enabled = false; 98 #if !defined(OS_ANDROID)
103 #endif // !OS_ANDROID 99 // History quick provider can be used on all platforms other than Android.
104 providers_.push_back(new HistoryURLProvider(this, profile)); 100 if (provider_types & AutocompleteProvider::TYPE_HISTORY_QUICK) {
105 providers_.push_back(new ShortcutsProvider(this, profile)); 101 hqp_enabled = true;
106 providers_.push_back(new HistoryContentsProvider(this, profile, hqp_enabled)); 102 providers_.push_back(new HistoryQuickProvider(this, profile));
107 providers_.push_back(new BuiltinProvider(this, profile));
108 providers_.push_back(new ExtensionAppProvider(this, profile));
109 // Create ZeroSuggest if its switch is present.
110 CommandLine* cl = CommandLine::ForCurrentProcess();
111 if (cl->HasSwitch(switches::kExperimentalZeroSuggestURLPrefix)) {
112 zero_suggest_provider_ = new ZeroSuggestProvider(this, profile,
113 cl->GetSwitchValueASCII(switches::kExperimentalZeroSuggestURLPrefix));
114 providers_.push_back(zero_suggest_provider_);
115 } 103 }
104
105 if (provider_types & AutocompleteProvider::TYPE_KEYWORD) {
106 // Search provider/"tab to search" can be used on all platforms other than
107 // Android.
108 keyword_provider_ = new KeywordProvider(this, profile);
109 providers_.push_back(keyword_provider_);
110 }
111 #endif
112
113 if (provider_types & AutocompleteProvider::TYPE_HISTORY_URL)
114 providers_.push_back(new HistoryURLProvider(this, profile));
115 if (provider_types & AutocompleteProvider::TYPE_SHORTCUTS)
116 providers_.push_back(new ShortcutsProvider(this, profile));
117 if (provider_types & AutocompleteProvider::TYPE_HISTORY_CONTENTS)
Peter Kasting 2012/09/07 23:23:02 Nit: {}
Daniel Erat 2012/09/08 16:37:36 Done.
118 providers_.push_back(
119 new HistoryContentsProvider(this, profile, hqp_enabled));
120 if (provider_types & AutocompleteProvider::TYPE_BUILTIN)
121 providers_.push_back(new BuiltinProvider(this, profile));
122 if (provider_types & AutocompleteProvider::TYPE_EXTENSION_APP)
123 providers_.push_back(new ExtensionAppProvider(this, profile));
124
125 if (provider_types & AutocompleteProvider::TYPE_ZERO_SUGGEST) {
126 // Create ZeroSuggest if its switch is present.
127 CommandLine* cl = CommandLine::ForCurrentProcess();
Peter Kasting 2012/09/07 23:23:02 Nit: If you inline this into the conditional, you
Daniel Erat 2012/09/08 16:37:36 Done (combining the conditionals; kept the |cl| va
128 if (cl->HasSwitch(switches::kExperimentalZeroSuggestURLPrefix)) {
129 zero_suggest_provider_ = new ZeroSuggestProvider(this, profile,
130 cl->GetSwitchValueASCII(switches::kExperimentalZeroSuggestURLPrefix));
131 providers_.push_back(zero_suggest_provider_);
132 }
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