OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/omnibox_provider.h" | 5 #include "chrome/browser/ui/app_list/search/omnibox_provider.h" |
6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
7 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" | 8 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" |
8 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 9 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/search_engines/template_url_service_factory.h" | 11 #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/app_list_controller_delegate.h" |
12 #include "chrome/browser/ui/app_list/search/omnibox_result.h" | 13 #include "chrome/browser/ui/app_list/search/omnibox_result.h" |
13 #include "components/metrics/proto/omnibox_event.pb.h" | 14 #include "components/metrics/proto/omnibox_event.pb.h" |
14 #include "components/omnibox/browser/autocomplete_classifier.h" | 15 #include "components/omnibox/browser/autocomplete_classifier.h" |
15 #include "components/omnibox/browser/autocomplete_controller.h" | 16 #include "components/omnibox/browser/autocomplete_controller.h" |
16 #include "components/omnibox/browser/autocomplete_input.h" | 17 #include "components/omnibox/browser/autocomplete_input.h" |
17 #include "ui/app_list/search_result.h" | 18 #include "ui/app_list/search_result.h" |
18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
19 | 20 |
20 namespace app_list { | 21 namespace app_list { |
21 | 22 |
22 OmniboxProvider::OmniboxProvider(Profile* profile, | 23 OmniboxProvider::OmniboxProvider(Profile* profile, |
23 AppListControllerDelegate* list_controller) | 24 AppListControllerDelegate* list_controller) |
24 : profile_(profile), | 25 : profile_(profile), |
25 list_controller_(list_controller), | 26 list_controller_(list_controller), |
26 controller_(new AutocompleteController( | 27 controller_(new AutocompleteController( |
27 make_scoped_ptr(new ChromeAutocompleteProviderClient(profile)), | 28 base::WrapUnique(new ChromeAutocompleteProviderClient(profile)), |
28 this, | 29 this, |
29 AutocompleteClassifier::kDefaultOmniboxProviders & | 30 AutocompleteClassifier::kDefaultOmniboxProviders & |
30 ~AutocompleteProvider::TYPE_ZERO_SUGGEST)), | 31 ~AutocompleteProvider::TYPE_ZERO_SUGGEST)), |
31 is_voice_query_(false) { | 32 is_voice_query_(false) {} |
32 } | |
33 | 33 |
34 OmniboxProvider::~OmniboxProvider() {} | 34 OmniboxProvider::~OmniboxProvider() {} |
35 | 35 |
36 void OmniboxProvider::Start(bool is_voice_query, const base::string16& query) { | 36 void OmniboxProvider::Start(bool is_voice_query, const base::string16& query) { |
37 is_voice_query_ = is_voice_query; | 37 is_voice_query_ = is_voice_query; |
38 controller_->Start(AutocompleteInput( | 38 controller_->Start(AutocompleteInput( |
39 query, base::string16::npos, std::string(), GURL(), | 39 query, base::string16::npos, std::string(), GURL(), |
40 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, | 40 metrics::OmniboxEventProto::INVALID_SPEC, false, false, true, true, false, |
41 ChromeAutocompleteSchemeClassifier(profile_))); | 41 ChromeAutocompleteSchemeClassifier(profile_))); |
42 } | 42 } |
43 | 43 |
44 void OmniboxProvider::Stop() { | 44 void OmniboxProvider::Stop() { |
45 controller_->Stop(false); | 45 controller_->Stop(false); |
46 is_voice_query_ = false; | 46 is_voice_query_ = false; |
47 } | 47 } |
48 | 48 |
49 void OmniboxProvider::PopulateFromACResult(const AutocompleteResult& result) { | 49 void OmniboxProvider::PopulateFromACResult(const AutocompleteResult& result) { |
50 ClearResults(); | 50 ClearResults(); |
51 for (ACMatches::const_iterator it = result.begin(); | 51 for (ACMatches::const_iterator it = result.begin(); |
52 it != result.end(); | 52 it != result.end(); |
53 ++it) { | 53 ++it) { |
54 if (!it->destination_url.is_valid()) | 54 if (!it->destination_url.is_valid()) |
55 continue; | 55 continue; |
56 | 56 |
57 Add(scoped_ptr<SearchResult>(new OmniboxResult( | 57 Add(std::unique_ptr<SearchResult>(new OmniboxResult( |
58 profile_, list_controller_, controller_.get(), is_voice_query_, *it))); | 58 profile_, list_controller_, controller_.get(), is_voice_query_, *it))); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 void OmniboxProvider::OnResultChanged(bool default_match_changed) { | 62 void OmniboxProvider::OnResultChanged(bool default_match_changed) { |
63 const AutocompleteResult& result = controller_->result(); | 63 const AutocompleteResult& result = controller_->result(); |
64 PopulateFromACResult(result); | 64 PopulateFromACResult(result); |
65 } | 65 } |
66 | 66 |
67 } // namespace app_list | 67 } // namespace app_list |
OLD | NEW |