1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/app_list/search/omnibox_provider.h"
7 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
8 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search_engines/template_url_service_factory.h"
11 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
12 #include "chrome/browser/ui/app_list/search/omnibox_result.h"
13 #include "components/metrics/proto/omnibox_event.pb.h"
14 #include "components/omnibox/browser/autocomplete_classifier.h"
15 #include "components/omnibox/browser/autocomplete_controller.h"
16 #include "components/omnibox/browser/autocomplete_input.h"
17 #include "ui/app_list/search_result.h"
22 OmniboxProvider::OmniboxProvider(Profile
* profile
,
23 AppListControllerDelegate
* list_controller
)
25 list_controller_(list_controller
),
26 controller_(new AutocompleteController(
27 make_scoped_ptr(new ChromeAutocompleteProviderClient(profile
)),
29 AutocompleteClassifier::kDefaultOmniboxProviders
&
30 ~AutocompleteProvider::TYPE_ZERO_SUGGEST
)),
31 is_voice_query_(false) {
34 OmniboxProvider::~OmniboxProvider() {}
36 void OmniboxProvider::Start(bool is_voice_query
, const base::string16
& query
) {
37 is_voice_query_
= is_voice_query
;
38 controller_
->Start(AutocompleteInput(
39 query
, base::string16::npos
, std::string(), GURL(),
40 metrics::OmniboxEventProto::INVALID_SPEC
, false, false, true, true, false,
41 ChromeAutocompleteSchemeClassifier(profile_
)));
44 void OmniboxProvider::Stop() {
45 controller_
->Stop(false);
46 is_voice_query_
= false;
49 void OmniboxProvider::PopulateFromACResult(const AutocompleteResult
& result
) {
51 for (ACMatches::const_iterator it
= result
.begin();
54 if (!it
->destination_url
.is_valid())
57 Add(scoped_ptr
<SearchResult
>(new OmniboxResult(
58 profile_
, list_controller_
, controller_
.get(), is_voice_query_
, *it
)));
62 void OmniboxProvider::OnResultChanged(bool default_match_changed
) {
63 const AutocompleteResult
& result
= controller_
->result();
64 PopulateFromACResult(result
);
67 } // namespace app_list