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

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: add !! for windows 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 // TODO(xiyuan): Consider requesting fewer providers in the non-apps-only
192 app_list::switches::kAppListShowAppsOnly)) { 193 // case.
193 // ExtensionAppProvider is a synchronous provider and does not really need a 194 int providers =
194 // listener. 195 CommandLine::ForCurrentProcess()->HasSwitch(
195 apps_provider_ = new ExtensionAppProvider(NULL, profile); 196 app_list::switches::kAppListShowAppsOnly) ?
196 } else { 197 AutocompleteProvider::TYPE_EXTENSION_APP :
197 controller_.reset(new AutocompleteController(profile, this)); 198 AutocompleteClassifier::kDefaultOmniboxProviders;
198 } 199 controller_.reset(new AutocompleteController(profile, this, providers));
199 } 200 }
200 201
201 SearchBuilder::~SearchBuilder() { 202 SearchBuilder::~SearchBuilder() {
202 } 203 }
203 204
204 void SearchBuilder::StartSearch() { 205 void SearchBuilder::StartSearch() {
205 const string16& user_text = search_box_->text(); 206 // Omnibox features such as keyword selection/accepting and instant query
206 207 // are not implemented.
207 if (controller_.get()) { 208 // TODO(xiyuan): Figure out the features that need to support here.
208 // Omnibox features such as keyword selection/accepting and instant query 209 controller_->Start(search_box_->text(), string16(), false, false, true,
209 // are not implemented. 210 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 } 211 }
226 212
227 void SearchBuilder::StopSearch() { 213 void SearchBuilder::StopSearch() {
228 if (controller_.get()) 214 controller_->Stop(true);
229 controller_->Stop(true);
230 else
231 apps_provider_->Stop(true);
232 } 215 }
233 216
234 void SearchBuilder::OpenResult(const app_list::SearchResult& result, 217 void SearchBuilder::OpenResult(const app_list::SearchResult& result,
235 int event_flags) { 218 int event_flags) {
236 const SearchBuilderResult* builder_result = 219 const SearchBuilderResult* builder_result =
237 static_cast<const SearchBuilderResult*>(&result); 220 static_cast<const SearchBuilderResult*>(&result);
238 const AutocompleteMatch& match = builder_result->match(); 221 const AutocompleteMatch& match = builder_result->match();
239 222
240 // Count AppList.Search here because it is composed of search + action. 223 // Count AppList.Search here because it is composed of search + action.
241 content::RecordAction(content::UserMetricsAction("AppList_Search")); 224 content::RecordAction(content::UserMetricsAction("AppList_Search"));
(...skipping 29 matching lines...) Expand all
271 ++it) { 254 ++it) {
272 results_->Add(new SearchBuilderResult(profile_, *it)); 255 results_->Add(new SearchBuilderResult(profile_, *it));
273 } 256 }
274 } 257 }
275 258
276 void SearchBuilder::OnResultChanged(bool default_match_changed) { 259 void SearchBuilder::OnResultChanged(bool default_match_changed) {
277 // TODO(xiyuan): Handle default match properly. 260 // TODO(xiyuan): Handle default match properly.
278 const AutocompleteResult& ac_result = controller_->result(); 261 const AutocompleteResult& ac_result = controller_->result();
279 PopulateFromACResult(ac_result); 262 PopulateFromACResult(ac_result);
280 } 263 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/search_builder.h ('k') | chrome/browser/ui/omnibox/omnibox_edit_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698