| 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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 // Maximum time (in milliseconds) to wait to the search providers to finish. | 22 // Maximum time (in milliseconds) to wait to the search providers to finish. |
| 23 const int kStopTimeMS = 1500; | 23 const int kStopTimeMS = 1500; |
| 24 } | 24 } |
| 25 | 25 |
| 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 mixer_->Init(); | 36 mixer_->Init(); |
| 36 } | 37 } |
| 37 | 38 |
| 38 SearchController::~SearchController() { | 39 SearchController::~SearchController() { |
| 39 } | 40 } |
| 40 | 41 |
| 41 void SearchController::Start() { | 42 void SearchController::Start(bool is_voice_query) { |
| 42 Stop(); | 43 Stop(); |
| 43 | 44 |
| 44 base::string16 query; | 45 base::string16 query; |
| 45 base::TrimWhitespace(search_box_->text(), base::TRIM_ALL, &query); | 46 base::TrimWhitespace(search_box_->text(), base::TRIM_ALL, &query); |
| 46 | 47 |
| 47 dispatching_query_ = true; | 48 dispatching_query_ = true; |
| 48 for (Providers::iterator it = providers_.begin(); | 49 for (Providers::iterator it = providers_.begin(); |
| 49 it != providers_.end(); | 50 it != providers_.end(); |
| 50 ++it) { | 51 ++it) { |
| 51 (*it)->Start(query); | 52 (*it)->Start(query); |
| 52 } | 53 } |
| 53 dispatching_query_ = false; | 54 dispatching_query_ = false; |
| 54 | 55 |
| 56 is_voice_query_ = is_voice_query; |
| 57 |
| 55 OnResultsChanged(); | 58 OnResultsChanged(); |
| 56 | 59 |
| 57 stop_timer_.Start(FROM_HERE, | 60 stop_timer_.Start(FROM_HERE, |
| 58 base::TimeDelta::FromMilliseconds(kStopTimeMS), | 61 base::TimeDelta::FromMilliseconds(kStopTimeMS), |
| 59 base::Bind(&SearchController::Stop, | 62 base::Bind(&SearchController::Stop, |
| 60 base::Unretained(this))); | 63 base::Unretained(this))); |
| 61 } | 64 } |
| 62 | 65 |
| 63 void SearchController::Stop() { | 66 void SearchController::Stop() { |
| 64 stop_timer_.Stop(); | 67 stop_timer_.Stop(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 void SearchController::OnResultsChanged() { | 104 void SearchController::OnResultsChanged() { |
| 102 if (dispatching_query_) | 105 if (dispatching_query_) |
| 103 return; | 106 return; |
| 104 | 107 |
| 105 KnownResults known_results; | 108 KnownResults known_results; |
| 106 if (history_ && history_->IsReady()) { | 109 if (history_ && history_->IsReady()) { |
| 107 history_->GetKnownResults(base::UTF16ToUTF8(search_box_->text())) | 110 history_->GetKnownResults(base::UTF16ToUTF8(search_box_->text())) |
| 108 ->swap(known_results); | 111 ->swap(known_results); |
| 109 } | 112 } |
| 110 | 113 |
| 111 mixer_->MixAndPublish(known_results); | 114 mixer_->MixAndPublish(is_voice_query_, known_results); |
| 112 } | 115 } |
| 113 | 116 |
| 114 } // namespace app_list | 117 } // namespace app_list |
| OLD | NEW |