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