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

Side by Side Diff: chrome/browser/ui/app_list/search_builder.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/ui/app_list/search_builder.h" 5 #include "chrome/browser/ui/app_list/search_builder.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "chrome/browser/autocomplete/autocomplete_classifier.h"
10 #include "chrome/browser/autocomplete/autocomplete_controller.h" 11 #include "chrome/browser/autocomplete/autocomplete_controller.h"
11 #include "chrome/browser/autocomplete/autocomplete_input.h" 12 #include "chrome/browser/autocomplete/autocomplete_input.h"
12 #include "chrome/browser/autocomplete/autocomplete_match.h" 13 #include "chrome/browser/autocomplete/autocomplete_match.h"
14 #include "chrome/browser/autocomplete/autocomplete_provider.h"
13 #include "chrome/browser/autocomplete/autocomplete_result.h" 15 #include "chrome/browser/autocomplete/autocomplete_result.h"
14 #include "chrome/browser/autocomplete/extension_app_provider.h"
15 #include "chrome/browser/event_disposition.h" 16 #include "chrome/browser/event_disposition.h"
16 #include "chrome/browser/extensions/extension_service.h" 17 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/image_loading_tracker.h" 18 #include "chrome/browser/extensions/image_loading_tracker.h"
18 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/app_list/app_list_controller.h" 20 #include "chrome/browser/ui/app_list/app_list_controller.h"
20 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_navigator.h" 22 #include "chrome/browser/ui/browser_navigator.h"
22 #include "chrome/browser/ui/browser_tabstrip.h" 23 #include "chrome/browser/ui/browser_tabstrip.h"
23 #include "chrome/common/extensions/extension.h" 24 #include "chrome/common/extensions/extension.h"
24 #include "chrome/common/extensions/extension_constants.h" 25 #include "chrome/common/extensions/extension_constants.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 AppListController* list_controller) 182 AppListController* list_controller)
182 : profile_(profile), 183 : profile_(profile),
183 search_box_(search_box), 184 search_box_(search_box),
184 results_(results), 185 results_(results),
185 list_controller_(list_controller) { 186 list_controller_(list_controller) {
186 search_box_->SetHintText( 187 search_box_->SetHintText(
187 l10n_util::GetStringUTF16(IDS_SEARCH_BOX_HINT)); 188 l10n_util::GetStringUTF16(IDS_SEARCH_BOX_HINT));
188 search_box_->SetIcon(*ui::ResourceBundle::GetSharedInstance(). 189 search_box_->SetIcon(*ui::ResourceBundle::GetSharedInstance().
189 GetImageSkiaNamed(IDR_OMNIBOX_SEARCH)); 190 GetImageSkiaNamed(IDR_OMNIBOX_SEARCH));
190 191
191 if (CommandLine::ForCurrentProcess()->HasSwitch( 192 int providers =
192 app_list::switches::kAppListShowAppsOnly)) { 193 CommandLine::ForCurrentProcess()->HasSwitch(
193 // ExtensionAppProvider is a synchronous provider and does not really need a 194 app_list::switches::kAppListShowAppsOnly) ?
194 // listener. 195 AutocompleteProvider::TYPE_EXTENSION_APP :
195 apps_provider_ = new ExtensionAppProvider(NULL, profile); 196 AutocompleteClassifier::kDefaultOmniboxProviders;
Peter Kasting 2012/09/07 23:23:02 Nit: You might want at least a TODO about supporti
Daniel Erat 2012/09/08 16:37:36 Done.
196 } else { 197 controller_.reset(new AutocompleteController(profile, this, providers));
197 controller_.reset(new AutocompleteController(profile, this));
198 }
199 } 198 }
200 199
201 SearchBuilder::~SearchBuilder() { 200 SearchBuilder::~SearchBuilder() {
202 } 201 }
203 202
204 void SearchBuilder::StartSearch() { 203 void SearchBuilder::StartSearch() {
205 const string16& user_text = search_box_->text(); 204 // Omnibox features such as keyword selection/accepting and instant query
206 205 // are not implemented.
207 if (controller_.get()) { 206 // TODO(xiyuan): Figure out the features that need to support here.
208 // Omnibox features such as keyword selection/accepting and instant query 207 controller_->Start(search_box_->text(), string16(), false, false, true,
Peter Kasting 2012/09/07 23:23:02 Nice simplification!
209 // are not implemented. 208 AutocompleteInput::ALL_MATCHES);
210 // TODO(xiyuan): Figure out the features that need to support here.
211 controller_->Start(user_text, string16(), false, false, true,
212 AutocompleteInput::ALL_MATCHES);
213 } else {
214 AutocompleteInput input(user_text, string16(), false, false, true,
215 AutocompleteInput::ALL_MATCHES);
216 apps_provider_->Start(input, false);
217
218 // ExtensionAppProvider is a synchronous provider and results are ready
219 // after returning from Start.
220 AutocompleteResult ac_result;
221 ac_result.AppendMatches(apps_provider_->matches());
222 ac_result.SortAndCull(input);
223 PopulateFromACResult(ac_result);
224 }
225 } 209 }
226 210
227 void SearchBuilder::StopSearch() { 211 void SearchBuilder::StopSearch() {
228 if (controller_.get()) 212 controller_->Stop(true);
229 controller_->Stop(true);
230 else
231 apps_provider_->Stop(true);
232 } 213 }
233 214
234 void SearchBuilder::OpenResult(const app_list::SearchResult& result, 215 void SearchBuilder::OpenResult(const app_list::SearchResult& result,
235 int event_flags) { 216 int event_flags) {
236 const SearchBuilderResult* builder_result = 217 const SearchBuilderResult* builder_result =
237 static_cast<const SearchBuilderResult*>(&result); 218 static_cast<const SearchBuilderResult*>(&result);
238 const AutocompleteMatch& match = builder_result->match(); 219 const AutocompleteMatch& match = builder_result->match();
239 220
240 // Count AppList.Search here because it is composed of search + action. 221 // Count AppList.Search here because it is composed of search + action.
241 content::RecordAction(content::UserMetricsAction("AppList_Search")); 222 content::RecordAction(content::UserMetricsAction("AppList_Search"));
(...skipping 29 matching lines...) Expand all
271 ++it) { 252 ++it) {
272 results_->Add(new SearchBuilderResult(profile_, *it)); 253 results_->Add(new SearchBuilderResult(profile_, *it));
273 } 254 }
274 } 255 }
275 256
276 void SearchBuilder::OnResultChanged(bool default_match_changed) { 257 void SearchBuilder::OnResultChanged(bool default_match_changed) {
277 // TODO(xiyuan): Handle default match properly. 258 // TODO(xiyuan): Handle default match properly.
278 const AutocompleteResult& ac_result = controller_->result(); 259 const AutocompleteResult& ac_result = controller_->result();
279 PopulateFromACResult(ac_result); 260 PopulateFromACResult(ac_result);
280 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698