| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 } | 155 } |
| 154 } | 156 } |
| 155 | 157 |
| 156 } // namespace | 158 } // namespace |
| 157 | 159 |
| 158 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller) | 160 AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller) |
| 159 : controller_(controller), | 161 : controller_(controller), |
| 160 profile_(NULL), | 162 profile_(NULL), |
| 161 model_(NULL), | 163 model_(NULL), |
| 162 is_voice_query_(false), | 164 is_voice_query_(false), |
| 165 template_url_service_observer_(this), |
| 163 scoped_observer_(this) { | 166 scoped_observer_(this) { |
| 164 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. | 167 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. |
| 165 tracked_objects::ScopedTracker tracking_profile( | 168 tracked_objects::ScopedTracker tracking_profile( |
| 166 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 169 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 167 "431326 AppListViewDelegate::AppListViewDelegate")); | 170 "431326 AppListViewDelegate::AppListViewDelegate")); |
| 168 | 171 |
| 169 CHECK(controller_); | 172 CHECK(controller_); |
| 170 // The SigninManagerFactor and the SigninManagers are observed to keep the | 173 // The SigninManagerFactor and the SigninManagers are observed to keep the |
| 171 // profile switcher menu up to date, with the correct list of profiles and the | 174 // profile switcher menu up to date, with the correct list of profiles and the |
| 172 // correct email address (or none for signed out users) for each. | 175 // correct email address (or none for signed out users) for each. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 "431326 AppListViewDelegate::SetProfile2")); | 284 "431326 AppListViewDelegate::SetProfile2")); |
| 282 | 285 |
| 283 speech_ui_->SetSpeechRecognitionState(app_list::SPEECH_RECOGNITION_OFF); | 286 speech_ui_->SetSpeechRecognitionState(app_list::SPEECH_RECOGNITION_OFF); |
| 284 return; | 287 return; |
| 285 } | 288 } |
| 286 | 289 |
| 287 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. | 290 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. |
| 288 tracked_objects::ScopedTracker tracking_profile3( | 291 tracked_objects::ScopedTracker tracking_profile3( |
| 289 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 292 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 290 "431326 AppListViewDelegate::SetProfile3")); | 293 "431326 AppListViewDelegate::SetProfile3")); |
| 294 template_url_service_observer_.RemoveAll(); |
| 295 template_url_service_observer_.Add( |
| 296 TemplateURLServiceFactory::GetForProfile(profile_)); |
| 291 | 297 |
| 292 model_ = | 298 model_ = |
| 293 app_list::AppListSyncableServiceFactory::GetForProfile(profile_)->model(); | 299 app_list::AppListSyncableServiceFactory::GetForProfile(profile_)->model(); |
| 294 | 300 |
| 295 #if defined(USE_ASH) | 301 #if defined(USE_ASH) |
| 296 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, model_)); | 302 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, model_)); |
| 297 #endif | 303 #endif |
| 298 | 304 |
| 299 SetUpSearchUI(); | 305 SetUpSearchUI(); |
| 300 SetUpProfileSwitcher(); | 306 SetUpProfileSwitcher(); |
| 301 SetUpCustomLauncherPages(); | 307 SetUpCustomLauncherPages(); |
| 308 OnTemplateURLServiceChanged(); |
| 302 | 309 |
| 303 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. | 310 // TODO(vadimt): Remove ScopedTracker below once crbug.com/431326 is fixed. |
| 304 tracked_objects::ScopedTracker tracking_profile4( | 311 tracked_objects::ScopedTracker tracking_profile4( |
| 305 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 312 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 306 "431326 AppListViewDelegate::SetProfile4")); | 313 "431326 AppListViewDelegate::SetProfile4")); |
| 307 | 314 |
| 308 // Clear search query. | 315 // Clear search query. |
| 309 model_->search_box()->SetText(base::string16()); | 316 model_->search_box()->SetText(base::string16()); |
| 310 } | 317 } |
| 311 | 318 |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 void AppListViewDelegate::AddObserver( | 783 void AppListViewDelegate::AddObserver( |
| 777 app_list::AppListViewDelegateObserver* observer) { | 784 app_list::AppListViewDelegateObserver* observer) { |
| 778 observers_.AddObserver(observer); | 785 observers_.AddObserver(observer); |
| 779 } | 786 } |
| 780 | 787 |
| 781 void AppListViewDelegate::RemoveObserver( | 788 void AppListViewDelegate::RemoveObserver( |
| 782 app_list::AppListViewDelegateObserver* observer) { | 789 app_list::AppListViewDelegateObserver* observer) { |
| 783 observers_.RemoveObserver(observer); | 790 observers_.RemoveObserver(observer); |
| 784 } | 791 } |
| 785 | 792 |
| 793 void AppListViewDelegate::OnTemplateURLServiceChanged() { |
| 794 TemplateURLService* template_url_service = |
| 795 TemplateURLServiceFactory::GetForProfile(profile_); |
| 796 const TemplateURL* default_provider = |
| 797 template_url_service->GetDefaultSearchProvider(); |
| 798 bool is_google = |
| 799 TemplateURLPrepopulateData::GetEngineType( |
| 800 *default_provider, template_url_service->search_terms_data()) == |
| 801 SEARCH_ENGINE_GOOGLE; |
| 802 |
| 803 model_->SetSearchEngineIsGoogle(is_google); |
| 804 |
| 805 app_list::StartPageService* start_page_service = |
| 806 app_list::StartPageService::Get(profile_); |
| 807 if (start_page_service) |
| 808 start_page_service->set_search_engine_is_google(is_google); |
| 809 } |
| 810 |
| 786 void AppListViewDelegate::Observe(int type, | 811 void AppListViewDelegate::Observe(int type, |
| 787 const content::NotificationSource& source, | 812 const content::NotificationSource& source, |
| 788 const content::NotificationDetails& details) { | 813 const content::NotificationDetails& details) { |
| 789 switch (type) { | 814 switch (type) { |
| 790 case chrome::NOTIFICATION_APP_TERMINATING: | 815 case chrome::NOTIFICATION_APP_TERMINATING: |
| 791 FOR_EACH_OBSERVER( | 816 FOR_EACH_OBSERVER( |
| 792 app_list::AppListViewDelegateObserver, observers_, OnShutdown()); | 817 app_list::AppListViewDelegateObserver, observers_, OnShutdown()); |
| 793 | 818 |
| 794 SetProfile(NULL); // Ensures launcher page web contents are torn down. | 819 SetProfile(NULL); // Ensures launcher page web contents are torn down. |
| 795 | 820 |
| 796 // SigninManagerFactory is not a leaky singleton (unlike this class), and | 821 // SigninManagerFactory is not a leaky singleton (unlike this class), and |
| 797 // its destructor will check that it has no remaining observers. | 822 // its destructor will check that it has no remaining observers. |
| 798 scoped_observer_.RemoveAll(); | 823 scoped_observer_.RemoveAll(); |
| 799 SigninManagerFactory::GetInstance()->RemoveObserver(this); | 824 SigninManagerFactory::GetInstance()->RemoveObserver(this); |
| 800 break; | 825 break; |
| 801 default: | 826 default: |
| 802 NOTREACHED(); | 827 NOTREACHED(); |
| 803 } | 828 } |
| 804 } | 829 } |
| OLD | NEW |