OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/app_list_view_delegate.h" | 5 #include "chrome/browser/ui/app_list/app_list_view_delegate.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "apps/custom_launcher_page_contents.h" | 9 #include "apps/custom_launcher_page_contents.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/metrics/user_metrics.h" | 13 #include "base/metrics/user_metrics.h" |
14 #include "base/profiler/scoped_tracker.h" | 14 #include "base/profiler/scoped_tracker.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "chrome/browser/apps/scoped_keep_alive.h" | 16 #include "chrome/browser/apps/scoped_keep_alive.h" |
17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
19 #include "chrome/browser/profiles/profile_info_cache.h" | 19 #include "chrome/browser/profiles/profile_info_cache.h" |
20 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
21 #include "chrome/browser/search/hotword_service.h" | 21 #include "chrome/browser/search/hotword_service.h" |
22 #include "chrome/browser/search/hotword_service_factory.h" | 22 #include "chrome/browser/search/hotword_service_factory.h" |
| 23 #include "chrome/browser/search_engines/template_url_service_factory.h" |
23 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 24 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
24 #include "chrome/browser/ui/app_list/app_list_service.h" | 25 #include "chrome/browser/ui/app_list/app_list_service.h" |
25 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 26 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
26 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 27 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
27 #include "chrome/browser/ui/app_list/launcher_page_event_dispatcher.h" | 28 #include "chrome/browser/ui/app_list/launcher_page_event_dispatcher.h" |
28 #include "chrome/browser/ui/app_list/search/search_controller_factory.h" | 29 #include "chrome/browser/ui/app_list/search/search_controller_factory.h" |
29 #include "chrome/browser/ui/app_list/search/search_resource_manager.h" | 30 #include "chrome/browser/ui/app_list/search/search_resource_manager.h" |
30 #include "chrome/browser/ui/app_list/start_page_service.h" | 31 #include "chrome/browser/ui/app_list/start_page_service.h" |
31 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 32 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
32 #include "chrome/browser/ui/browser_finder.h" | 33 #include "chrome/browser/ui/browser_finder.h" |
33 #include "chrome/browser/ui/chrome_pages.h" | 34 #include "chrome/browser/ui/chrome_pages.h" |
34 #include "chrome/browser/ui/host_desktop.h" | 35 #include "chrome/browser/ui/host_desktop.h" |
35 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 36 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
36 #include "chrome/browser/web_applications/web_app.h" | 37 #include "chrome/browser/web_applications/web_app.h" |
37 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
38 #include "chrome/common/extensions/extension_constants.h" | 39 #include "chrome/common/extensions/extension_constants.h" |
39 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 41 #include "components/search_engines/template_url_prepopulate_data.h" |
40 #include "components/signin/core/browser/signin_manager.h" | 42 #include "components/signin/core/browser/signin_manager.h" |
41 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
42 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
43 #include "content/public/browser/page_navigator.h" | 45 #include "content/public/browser/page_navigator.h" |
44 #include "content/public/browser/render_view_host.h" | 46 #include "content/public/browser/render_view_host.h" |
45 #include "content/public/browser/render_widget_host_view.h" | 47 #include "content/public/browser/render_widget_host_view.h" |
46 #include "content/public/browser/speech_recognition_session_preamble.h" | 48 #include "content/public/browser/speech_recognition_session_preamble.h" |
47 #include "content/public/browser/user_metrics.h" | 49 #include "content/public/browser/user_metrics.h" |
48 #include "content/public/browser/web_contents.h" | 50 #include "content/public/browser/web_contents.h" |
49 #include "extensions/browser/extension_registry.h" | 51 #include "extensions/browser/extension_registry.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 } | 153 } |
152 } | 154 } |
153 | 155 |
154 } // namespace | 156 } // namespace |
155 | 157 |
156 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller) | 158 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller) |
157 : controller_(controller), | 159 : controller_(controller), |
158 profile_(NULL), | 160 profile_(NULL), |
159 model_(NULL), | 161 model_(NULL), |
160 is_voice_query_(false), | 162 is_voice_query_(false), |
| 163 template_url_service_observer_(this), |
161 scoped_observer_(this) { | 164 scoped_observer_(this) { |
162 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. | 165 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. |
163 tracked_objects::ScopedTracker tracking_profile( | 166 tracked_objects::ScopedTracker tracking_profile( |
164 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 167 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
165 "431326 AppListViewDelegate::AppListViewDelegate")); | 168 "431326 AppListViewDelegate::AppListViewDelegate")); |
166 | 169 |
167 CHECK(controller_); | 170 CHECK(controller_); |
168 // The SigninManagerFactor and the SigninManagers are observed to keep the | 171 // The SigninManagerFactor and the SigninManagers are observed to keep the |
169 // profile switcher menu up to date, with the correct list of profiles and the | 172 // profile switcher menu up to date, with the correct list of profiles and the |
170 // correct email address (or none for signed out users) for each. | 173 // correct email address (or none for signed out users) for each. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 "431326 AppListViewDelegate::SetProfile2")); | 282 "431326 AppListViewDelegate::SetProfile2")); |
280 | 283 |
281 speech_ui_->SetSpeechRecognitionState(app_list::SPEECH_RECOGNITION_OFF); | 284 speech_ui_->SetSpeechRecognitionState(app_list::SPEECH_RECOGNITION_OFF); |
282 return; | 285 return; |
283 } | 286 } |
284 | 287 |
285 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. | 288 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. |
286 tracked_objects::ScopedTracker tracking_profile3( | 289 tracked_objects::ScopedTracker tracking_profile3( |
287 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 290 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
288 "431326 AppListViewDelegate::SetProfile3")); | 291 "431326 AppListViewDelegate::SetProfile3")); |
| 292 template_url_service_observer_.RemoveAll(); |
| 293 template_url_service_observer_.Add( |
| 294 TemplateURLServiceFactory::GetForProfile(profile_)); |
289 | 295 |
290 model_ = | 296 model_ = |
291 app_list::AppListSyncableServiceFactory::GetForProfile(profile_)->model(); | 297 app_list::AppListSyncableServiceFactory::GetForProfile(profile_)->model(); |
292 | 298 |
293 #if defined(USE_ASH) | 299 #if defined(USE_ASH) |
294 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, model_)); | 300 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, model_)); |
295 #endif | 301 #endif |
296 | 302 |
297 SetUpSearchUI(); | 303 SetUpSearchUI(); |
298 SetUpProfileSwitcher(); | 304 SetUpProfileSwitcher(); |
299 SetUpCustomLauncherPages(); | 305 SetUpCustomLauncherPages(); |
| 306 OnTemplateURLServiceChanged(); |
300 | 307 |
301 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. | 308 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. |
302 tracked_objects::ScopedTracker tracking_profile4( | 309 tracked_objects::ScopedTracker tracking_profile4( |
303 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 310 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
304 "431326 AppListViewDelegate::SetProfile4")); | 311 "431326 AppListViewDelegate::SetProfile4")); |
305 | 312 |
306 // Clear search query. | 313 // Clear search query. |
307 model_->search_box()->SetText(base::string16()); | 314 model_->search_box()->SetText(base::string16()); |
308 } | 315 } |
309 | 316 |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 void AppListViewDelegate::AddObserver( | 773 void AppListViewDelegate::AddObserver( |
767 app_list::AppListViewDelegateObserver* observer) { | 774 app_list::AppListViewDelegateObserver* observer) { |
768 observers_.AddObserver(observer); | 775 observers_.AddObserver(observer); |
769 } | 776 } |
770 | 777 |
771 void AppListViewDelegate::RemoveObserver( | 778 void AppListViewDelegate::RemoveObserver( |
772 app_list::AppListViewDelegateObserver* observer) { | 779 app_list::AppListViewDelegateObserver* observer) { |
773 observers_.RemoveObserver(observer); | 780 observers_.RemoveObserver(observer); |
774 } | 781 } |
775 | 782 |
| 783 void AppListViewDelegate::OnTemplateURLServiceChanged() { |
| 784 TemplateURLService* template_url_service = |
| 785 TemplateURLServiceFactory::GetForProfile(profile_); |
| 786 const TemplateURL* default_provider = |
| 787 template_url_service->GetDefaultSearchProvider(); |
| 788 bool is_google = |
| 789 TemplateURLPrepopulateData::GetEngineType( |
| 790 *default_provider, template_url_service->search_terms_data()) == |
| 791 SEARCH_ENGINE_GOOGLE; |
| 792 |
| 793 model_->SetSearchEngineIsGoogle(is_google); |
| 794 |
| 795 app_list::StartPageService* start_page_service = |
| 796 app_list::StartPageService::Get(profile_); |
| 797 if (start_page_service) |
| 798 start_page_service->set_search_engine_is_google(is_google); |
| 799 } |
| 800 |
776 void AppListViewDelegate::Observe(int type, | 801 void AppListViewDelegate::Observe(int type, |
777 const content::NotificationSource& source, | 802 const content::NotificationSource& source, |
778 const content::NotificationDetails& details) { | 803 const content::NotificationDetails& details) { |
779 switch (type) { | 804 switch (type) { |
780 case chrome::NOTIFICATION_APP_TERMINATING: | 805 case chrome::NOTIFICATION_APP_TERMINATING: |
781 FOR_EACH_OBSERVER( | 806 FOR_EACH_OBSERVER( |
782 app_list::AppListViewDelegateObserver, observers_, OnShutdown()); | 807 app_list::AppListViewDelegateObserver, observers_, OnShutdown()); |
783 | 808 |
784 SetProfile(NULL); // Ensures launcher page web contents are torn down. | 809 SetProfile(NULL); // Ensures launcher page web contents are torn down. |
785 | 810 |
786 // SigninManagerFactory is not a leaky singleton (unlike this class), and | 811 // SigninManagerFactory is not a leaky singleton (unlike this class), and |
787 // its destructor will check that it has no remaining observers. | 812 // its destructor will check that it has no remaining observers. |
788 scoped_observer_.RemoveAll(); | 813 scoped_observer_.RemoveAll(); |
789 SigninManagerFactory::GetInstance()->RemoveObserver(this); | 814 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
790 break; | 815 break; |
791 default: | 816 default: |
792 NOTREACHED(); | 817 NOTREACHED(); |
793 } | 818 } |
794 } | 819 } |
OLD | NEW |