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; |
42 } | 39 } |
43 | 40 |
44 namespace app_list { | 41 namespace app_list { |
45 | 42 |
46 SearchController::SearchController(Profile* profile, | 43 SearchController::SearchController(Profile* profile, |
47 SearchBoxModel* search_box, | 44 SearchBoxModel* search_box, |
48 AppListModel::SearchResults* results, | 45 AppListModel::SearchResults* results, |
49 SpeechUIModel* speech_ui, | 46 SpeechUIModel* speech_ui, |
50 AppListControllerDelegate* list_controller) | 47 AppListControllerDelegate* list_controller) |
51 : profile_(profile), | 48 : profile_(profile), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 it != providers_.end(); | 123 it != providers_.end(); |
127 ++it) { | 124 ++it) { |
128 (*it)->Stop(); | 125 (*it)->Stop(); |
129 } | 126 } |
130 } | 127 } |
131 | 128 |
132 void SearchController::OpenResult(SearchResult* result, int event_flags) { | 129 void SearchController::OpenResult(SearchResult* result, int event_flags) { |
133 // Count AppList.Search here because it is composed of search + action. | 130 // Count AppList.Search here because it is composed of search + action. |
134 content::RecordAction(base::UserMetricsAction("AppList_Search")); | 131 content::RecordAction(base::UserMetricsAction("AppList_Search")); |
135 | 132 |
136 ChromeSearchResult* chrome_result = | 133 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 | 134 |
143 if (history_ && history_->IsReady()) { | 135 if (history_ && history_->IsReady()) { |
144 history_->AddLaunchEvent(base::UTF16ToUTF8(search_box_->text()), | 136 history_->AddLaunchEvent(base::UTF16ToUTF8(search_box_->text()), |
145 chrome_result->id()); | 137 result->id()); |
146 } | 138 } |
147 } | 139 } |
148 | 140 |
149 void SearchController::InvokeResultAction(SearchResult* result, | 141 void SearchController::InvokeResultAction(SearchResult* result, |
150 int action_index, | 142 int action_index, |
151 int event_flags) { | 143 int event_flags) { |
152 // TODO(xiyuan): Hook up with user learning. | 144 // TODO(xiyuan): Hook up with user learning. |
153 static_cast<app_list::ChromeSearchResult*>(result)->InvokeAction( | 145 result->InvokeAction(action_index, event_flags); |
154 action_index, event_flags); | |
155 } | 146 } |
156 | 147 |
157 void SearchController::AddProvider(Mixer::GroupId group, | 148 void SearchController::AddProvider(Mixer::GroupId group, |
158 scoped_ptr<SearchProvider> provider) { | 149 scoped_ptr<SearchProvider> provider) { |
159 provider->set_result_changed_callback(base::Bind( | 150 provider->set_result_changed_callback(base::Bind( |
160 &SearchController::OnResultsChanged, | 151 &SearchController::OnResultsChanged, |
161 base::Unretained(this))); | 152 base::Unretained(this))); |
162 mixer_->AddProviderToGroup(group, provider.get()); | 153 mixer_->AddProviderToGroup(group, provider.get()); |
163 providers_.push_back(provider.release()); // Takes ownership. | 154 providers_.push_back(provider.release()); // Takes ownership. |
164 } | 155 } |
(...skipping 12 matching lines...) Expand all Loading... |
177 } | 168 } |
178 | 169 |
179 void SearchController::OnSpeechRecognitionStateChanged( | 170 void SearchController::OnSpeechRecognitionStateChanged( |
180 SpeechRecognitionState new_state) { | 171 SpeechRecognitionState new_state) { |
181 search_box_->SetHintText(l10n_util::GetStringUTF16( | 172 search_box_->SetHintText(l10n_util::GetStringUTF16( |
182 (new_state == SPEECH_RECOGNITION_HOTWORD_LISTENING) ? | 173 (new_state == SPEECH_RECOGNITION_HOTWORD_LISTENING) ? |
183 IDS_SEARCH_BOX_HOTWORD_HINT : IDS_SEARCH_BOX_HINT)); | 174 IDS_SEARCH_BOX_HOTWORD_HINT : IDS_SEARCH_BOX_HINT)); |
184 } | 175 } |
185 | 176 |
186 } // namespace app_list | 177 } // namespace app_list |
OLD | NEW |