| 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/search_controller.h" | 5 #include "chrome/browser/ui/app_list/search/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" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/metrics/histogram.h" | |
| 14 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 16 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| 18 #include "chrome/browser/ui/app_list/search/app_search_provider.h" | 17 #include "chrome/browser/ui/app_list/search/app_search_provider.h" |
| 19 #include "chrome/browser/ui/app_list/search/chrome_search_result.h" | |
| 20 #include "chrome/browser/ui/app_list/search/history.h" | 18 #include "chrome/browser/ui/app_list/search/history.h" |
| 21 #include "chrome/browser/ui/app_list/search/history_factory.h" | 19 #include "chrome/browser/ui/app_list/search/history_factory.h" |
| 22 #include "chrome/browser/ui/app_list/search/omnibox_provider.h" | 20 #include "chrome/browser/ui/app_list/search/omnibox_provider.h" |
| 23 #include "chrome/browser/ui/app_list/search/people/people_provider.h" | 21 #include "chrome/browser/ui/app_list/search/people/people_provider.h" |
| 24 #include "chrome/browser/ui/app_list/search/webstore/webstore_provider.h" | 22 #include "chrome/browser/ui/app_list/search/webstore/webstore_provider.h" |
| 25 #include "chrome/browser/ui/app_list/start_page_service.h" | 23 #include "chrome/browser/ui/app_list/start_page_service.h" |
| 26 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" |
| 28 #include "content/public/browser/user_metrics.h" | 26 #include "content/public/browser/user_metrics.h" |
| 29 #include "grit/components_scaled_resources.h" | 27 #include "grit/components_scaled_resources.h" |
| 30 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
| 31 #include "ui/app_list/search_box_model.h" | 29 #include "ui/app_list/search_box_model.h" |
| 30 #include "ui/app_list/search_result.h" |
| 32 #include "ui/app_list/speech_ui_model.h" | 31 #include "ui/app_list/speech_ui_model.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/base/resource/resource_bundle.h" | 33 #include "ui/base/resource/resource_bundle.h" |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 37 const char kAppListSearchResultOpenTypeHistogram[] = | |
| 38 "Apps.AppListSearchResultOpenType"; | |
| 39 | 36 |
| 40 // Maximum time (in milliseconds) to wait to the search providers to finish. | 37 // Maximum time (in milliseconds) to wait to the search providers to finish. |
| 41 const int kStopTimeMS = 1500; | 38 const int kStopTimeMS = 1500; |
| 39 |
| 42 } | 40 } |
| 43 | 41 |
| 44 namespace app_list { | 42 namespace app_list { |
| 45 | 43 |
| 46 SearchController::SearchController(Profile* profile, | 44 SearchController::SearchController(Profile* profile, |
| 47 SearchBoxModel* search_box, | 45 SearchBoxModel* search_box, |
| 48 AppListModel::SearchResults* results, | 46 AppListModel::SearchResults* results, |
| 49 SpeechUIModel* speech_ui, | 47 SpeechUIModel* speech_ui, |
| 50 AppListControllerDelegate* list_controller) | 48 AppListControllerDelegate* list_controller) |
| 51 : profile_(profile), | 49 : profile_(profile), |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 it != providers_.end(); | 124 it != providers_.end(); |
| 127 ++it) { | 125 ++it) { |
| 128 (*it)->Stop(); | 126 (*it)->Stop(); |
| 129 } | 127 } |
| 130 } | 128 } |
| 131 | 129 |
| 132 void SearchController::OpenResult(SearchResult* result, int event_flags) { | 130 void SearchController::OpenResult(SearchResult* result, int event_flags) { |
| 133 // Count AppList.Search here because it is composed of search + action. | 131 // Count AppList.Search here because it is composed of search + action. |
| 134 content::RecordAction(base::UserMetricsAction("AppList_Search")); | 132 content::RecordAction(base::UserMetricsAction("AppList_Search")); |
| 135 | 133 |
| 136 ChromeSearchResult* chrome_result = | 134 result->Open(event_flags); |
| 137 static_cast<app_list::ChromeSearchResult*>(result); | |
| 138 UMA_HISTOGRAM_ENUMERATION(kAppListSearchResultOpenTypeHistogram, | |
| 139 chrome_result->GetType(), | |
| 140 SEARCH_RESULT_TYPE_BOUNDARY); | |
| 141 chrome_result->Open(event_flags); | |
| 142 | 135 |
| 143 if (history_ && history_->IsReady()) { | 136 if (history_ && history_->IsReady()) { |
| 144 history_->AddLaunchEvent(base::UTF16ToUTF8(search_box_->text()), | 137 history_->AddLaunchEvent(base::UTF16ToUTF8(search_box_->text()), |
| 145 chrome_result->id()); | 138 result->id()); |
| 146 } | 139 } |
| 147 } | 140 } |
| 148 | 141 |
| 149 void SearchController::InvokeResultAction(SearchResult* result, | 142 void SearchController::InvokeResultAction(SearchResult* result, |
| 150 int action_index, | 143 int action_index, |
| 151 int event_flags) { | 144 int event_flags) { |
| 152 // TODO(xiyuan): Hook up with user learning. | 145 // TODO(xiyuan): Hook up with user learning. |
| 153 static_cast<app_list::ChromeSearchResult*>(result)->InvokeAction( | 146 result->InvokeAction(action_index, event_flags); |
| 154 action_index, event_flags); | |
| 155 } | 147 } |
| 156 | 148 |
| 157 void SearchController::AddProvider(Mixer::GroupId group, | 149 void SearchController::AddProvider(Mixer::GroupId group, |
| 158 scoped_ptr<SearchProvider> provider) { | 150 scoped_ptr<SearchProvider> provider) { |
| 159 provider->set_result_changed_callback(base::Bind( | 151 provider->set_result_changed_callback(base::Bind( |
| 160 &SearchController::OnResultsChanged, | 152 &SearchController::OnResultsChanged, |
| 161 base::Unretained(this))); | 153 base::Unretained(this))); |
| 162 mixer_->AddProviderToGroup(group, provider.get()); | 154 mixer_->AddProviderToGroup(group, provider.get()); |
| 163 providers_.push_back(provider.release()); // Takes ownership. | 155 providers_.push_back(provider.release()); // Takes ownership. |
| 164 } | 156 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 177 } | 169 } |
| 178 | 170 |
| 179 void SearchController::OnSpeechRecognitionStateChanged( | 171 void SearchController::OnSpeechRecognitionStateChanged( |
| 180 SpeechRecognitionState new_state) { | 172 SpeechRecognitionState new_state) { |
| 181 search_box_->SetHintText(l10n_util::GetStringUTF16( | 173 search_box_->SetHintText(l10n_util::GetStringUTF16( |
| 182 (new_state == SPEECH_RECOGNITION_HOTWORD_LISTENING) ? | 174 (new_state == SPEECH_RECOGNITION_HOTWORD_LISTENING) ? |
| 183 IDS_SEARCH_BOX_HOTWORD_HINT : IDS_SEARCH_BOX_HINT)); | 175 IDS_SEARCH_BOX_HOTWORD_HINT : IDS_SEARCH_BOX_HINT)); |
| 184 } | 176 } |
| 185 | 177 |
| 186 } // namespace app_list | 178 } // namespace app_list |
| OLD | NEW |