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 "ui/app_list/search_controller.h" | 5 #include "ui/app_list/search_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 namespace app_list { | 26 namespace app_list { |
27 | 27 |
28 SearchController::SearchController(SearchBoxModel* search_box, | 28 SearchController::SearchController(SearchBoxModel* search_box, |
29 AppListModel::SearchResults* results, | 29 AppListModel::SearchResults* results, |
30 History* history) | 30 History* history) |
31 : search_box_(search_box), | 31 : search_box_(search_box), |
32 dispatching_query_(false), | 32 dispatching_query_(false), |
33 mixer_(new Mixer(results)), | 33 mixer_(new Mixer(results)), |
34 history_(history), | 34 history_(history), |
35 is_voice_query_(false) { | 35 is_voice_query_(false) { |
36 mixer_->Init(); | |
37 } | 36 } |
38 | 37 |
39 SearchController::~SearchController() { | 38 SearchController::~SearchController() { |
40 } | 39 } |
41 | 40 |
42 void SearchController::Start(bool is_voice_query) { | 41 void SearchController::Start(bool is_voice_query) { |
43 Stop(); | 42 Stop(); |
44 | 43 |
45 base::string16 query; | 44 base::string16 query; |
46 base::TrimWhitespace(search_box_->text(), base::TRIM_ALL, &query); | 45 base::TrimWhitespace(search_box_->text(), base::TRIM_ALL, &query); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 84 } |
86 } | 85 } |
87 | 86 |
88 void SearchController::InvokeResultAction(SearchResult* result, | 87 void SearchController::InvokeResultAction(SearchResult* result, |
89 int action_index, | 88 int action_index, |
90 int event_flags) { | 89 int event_flags) { |
91 // TODO(xiyuan): Hook up with user learning. | 90 // TODO(xiyuan): Hook up with user learning. |
92 result->InvokeAction(action_index, event_flags); | 91 result->InvokeAction(action_index, event_flags); |
93 } | 92 } |
94 | 93 |
95 void SearchController::AddProvider(Mixer::GroupId group, | 94 size_t SearchController::AddGroup(size_t max_results, double boost) { |
| 95 return mixer_->AddGroup(max_results, boost); |
| 96 } |
| 97 |
| 98 void SearchController::AddProvider(size_t group_id, |
96 scoped_ptr<SearchProvider> provider) { | 99 scoped_ptr<SearchProvider> provider) { |
97 provider->set_result_changed_callback(base::Bind( | 100 provider->set_result_changed_callback(base::Bind( |
98 &SearchController::OnResultsChanged, | 101 &SearchController::OnResultsChanged, |
99 base::Unretained(this))); | 102 base::Unretained(this))); |
100 mixer_->AddProviderToGroup(group, provider.get()); | 103 mixer_->AddProviderToGroup(group_id, provider.get()); |
101 providers_.push_back(provider.release()); // Takes ownership. | 104 providers_.push_back(provider.release()); // Takes ownership. |
102 } | 105 } |
103 | 106 |
104 void SearchController::OnResultsChanged() { | 107 void SearchController::OnResultsChanged() { |
105 if (dispatching_query_) | 108 if (dispatching_query_) |
106 return; | 109 return; |
107 | 110 |
108 KnownResults known_results; | 111 KnownResults known_results; |
109 if (history_ && history_->IsReady()) { | 112 if (history_ && history_->IsReady()) { |
110 history_->GetKnownResults(base::UTF16ToUTF8(search_box_->text())) | 113 history_->GetKnownResults(base::UTF16ToUTF8(search_box_->text())) |
111 ->swap(known_results); | 114 ->swap(known_results); |
112 } | 115 } |
113 | 116 |
114 mixer_->MixAndPublish(is_voice_query_, known_results); | 117 mixer_->MixAndPublish(is_voice_query_, known_results); |
115 } | 118 } |
116 | 119 |
117 } // namespace app_list | 120 } // namespace app_list |
OLD | NEW |