| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/common/wm_shell.h" | 5 #include "ash/common/wm_shell.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/accelerators/accelerator_controller.h" | 9 #include "ash/common/accelerators/accelerator_controller.h" |
| 10 #include "ash/common/cast_config_controller.h" | 10 #include "ash/common/cast_config_controller.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "ash/common/system/brightness_control_delegate.h" | 24 #include "ash/common/system/brightness_control_delegate.h" |
| 25 #include "ash/common/system/chromeos/brightness/brightness_controller_chromeos.h
" | 25 #include "ash/common/system/chromeos/brightness/brightness_controller_chromeos.h
" |
| 26 #include "ash/common/system/chromeos/keyboard_brightness_controller.h" | 26 #include "ash/common/system/chromeos/keyboard_brightness_controller.h" |
| 27 #include "ash/common/system/chromeos/network/vpn_list.h" | 27 #include "ash/common/system/chromeos/network/vpn_list.h" |
| 28 #include "ash/common/system/chromeos/session/logout_confirmation_controller.h" | 28 #include "ash/common/system/chromeos/session/logout_confirmation_controller.h" |
| 29 #include "ash/common/system/keyboard_brightness_control_delegate.h" | 29 #include "ash/common/system/keyboard_brightness_control_delegate.h" |
| 30 #include "ash/common/system/locale/locale_notification_controller.h" | 30 #include "ash/common/system/locale/locale_notification_controller.h" |
| 31 #include "ash/common/system/tray/system_tray_controller.h" | 31 #include "ash/common/system/tray/system_tray_controller.h" |
| 32 #include "ash/common/system/tray/system_tray_delegate.h" | 32 #include "ash/common/system/tray/system_tray_delegate.h" |
| 33 #include "ash/common/system/tray/system_tray_notifier.h" | 33 #include "ash/common/system/tray/system_tray_notifier.h" |
| 34 #include "ash/common/wallpaper/wallpaper_delegate.h" | |
| 35 #include "ash/common/wm/immersive_context_ash.h" | 34 #include "ash/common/wm/immersive_context_ash.h" |
| 36 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 35 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 37 #include "ash/common/wm/mru_window_tracker.h" | 36 #include "ash/common/wm/mru_window_tracker.h" |
| 38 #include "ash/common/wm/overview/window_selector_controller.h" | 37 #include "ash/common/wm/overview/window_selector_controller.h" |
| 39 #include "ash/common/wm/root_window_finder.h" | 38 #include "ash/common/wm/root_window_finder.h" |
| 40 #include "ash/common/wm/system_modal_container_layout_manager.h" | 39 #include "ash/common/wm/system_modal_container_layout_manager.h" |
| 41 #include "ash/common/wm/window_cycle_controller.h" | 40 #include "ash/common/wm/window_cycle_controller.h" |
| 42 #include "ash/common/wm_window.h" | 41 #include "ash/common/wm_window.h" |
| 43 #include "ash/public/cpp/shell_window_ids.h" | 42 #include "ash/public/cpp/shell_window_ids.h" |
| 44 #include "ash/root_window_controller.h" | 43 #include "ash/root_window_controller.h" |
| 45 #include "ash/shell.h" | 44 #include "ash/shell.h" |
| 46 #include "base/bind.h" | 45 #include "base/bind.h" |
| 47 #include "base/logging.h" | 46 #include "base/logging.h" |
| 48 #include "base/memory/ptr_util.h" | 47 #include "base/memory/ptr_util.h" |
| 49 #include "services/preferences/public/cpp/pref_client_store.h" | |
| 50 #include "services/preferences/public/interfaces/preferences.mojom.h" | |
| 51 #include "services/service_manager/public/cpp/connector.h" | |
| 52 #include "ui/app_list/presenter/app_list.h" | 48 #include "ui/app_list/presenter/app_list.h" |
| 53 #include "ui/display/display.h" | 49 #include "ui/display/display.h" |
| 54 | 50 |
| 55 namespace ash { | 51 namespace ash { |
| 56 | 52 |
| 57 // static | 53 // static |
| 58 WmShell* WmShell::instance_ = nullptr; | 54 WmShell* WmShell::instance_ = nullptr; |
| 59 | 55 |
| 60 WmShell::~WmShell() { | 56 WmShell::~WmShell() { |
| 57 DCHECK_EQ(this, instance_); |
| 58 instance_ = nullptr; |
| 61 session_controller_->RemoveSessionStateObserver(this); | 59 session_controller_->RemoveSessionStateObserver(this); |
| 62 } | 60 } |
| 63 | 61 |
| 64 // static | 62 // static |
| 65 void WmShell::Set(WmShell* instance) { | |
| 66 instance_ = instance; | |
| 67 } | |
| 68 | |
| 69 // static | |
| 70 WmShell* WmShell::Get() { | 63 WmShell* WmShell::Get() { |
| 71 return instance_; | 64 return instance_; |
| 72 } | 65 } |
| 73 | 66 |
| 74 void WmShell::Shutdown() { | 67 void WmShell::Shutdown() { |
| 75 // ShelfWindowWatcher has window observers and a pointer to the shelf model. | 68 // ShelfWindowWatcher has window observers and a pointer to the shelf model. |
| 76 shelf_window_watcher_.reset(); | 69 shelf_window_watcher_.reset(); |
| 77 // ShelfItemDelegate subclasses it owns have complex cleanup to run (e.g. ARC | 70 // ShelfItemDelegate subclasses it owns have complex cleanup to run (e.g. ARC |
| 78 // shelf items in Chrome) so explicitly shutdown early. | 71 // shelf items in Chrome) so explicitly shutdown early. |
| 79 shelf_model()->DestroyItemDelegates(); | 72 shelf_model()->DestroyItemDelegates(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 106 |
| 114 void WmShell::CreateShelfDelegate() { | 107 void WmShell::CreateShelfDelegate() { |
| 115 // May be called multiple times as shelves are created and destroyed. | 108 // May be called multiple times as shelves are created and destroyed. |
| 116 if (shelf_delegate_) | 109 if (shelf_delegate_) |
| 117 return; | 110 return; |
| 118 // Must occur after SessionStateDelegate creation and user login because | 111 // Must occur after SessionStateDelegate creation and user login because |
| 119 // Chrome's implementation of ShelfDelegate assumes it can get information | 112 // Chrome's implementation of ShelfDelegate assumes it can get information |
| 120 // about multi-profile login state. | 113 // about multi-profile login state. |
| 121 DCHECK(GetSessionStateDelegate()); | 114 DCHECK(GetSessionStateDelegate()); |
| 122 DCHECK_GT(GetSessionStateDelegate()->NumberOfLoggedInUsers(), 0); | 115 DCHECK_GT(GetSessionStateDelegate()->NumberOfLoggedInUsers(), 0); |
| 123 shelf_delegate_.reset(delegate_->CreateShelfDelegate(shelf_model())); | 116 shelf_delegate_.reset( |
| 117 Shell::Get()->shell_delegate()->CreateShelfDelegate(shelf_model())); |
| 124 shelf_window_watcher_.reset(new ShelfWindowWatcher(shelf_model())); | 118 shelf_window_watcher_.reset(new ShelfWindowWatcher(shelf_model())); |
| 125 } | 119 } |
| 126 | 120 |
| 127 void WmShell::UpdateAfterLoginStatusChange(LoginStatus status) { | 121 void WmShell::UpdateAfterLoginStatusChange(LoginStatus status) { |
| 128 for (WmWindow* root_window : GetAllRootWindows()) { | 122 for (WmWindow* root_window : GetAllRootWindows()) { |
| 129 root_window->GetRootWindowController()->UpdateAfterLoginStatusChange( | 123 root_window->GetRootWindowController()->UpdateAfterLoginStatusChange( |
| 130 status); | 124 status); |
| 131 } | 125 } |
| 132 } | 126 } |
| 133 | 127 |
| 134 void WmShell::OnLockStateEvent(LockStateObserver::EventType event) { | 128 void WmShell::OnLockStateEvent(LockStateObserver::EventType event) { |
| 135 for (auto& observer : lock_state_observers_) | 129 for (auto& observer : lock_state_observers_) |
| 136 observer.OnLockStateEvent(event); | 130 observer.OnLockStateEvent(event); |
| 137 } | 131 } |
| 138 | 132 |
| 139 void WmShell::AddLockStateObserver(LockStateObserver* observer) { | 133 void WmShell::AddLockStateObserver(LockStateObserver* observer) { |
| 140 lock_state_observers_.AddObserver(observer); | 134 lock_state_observers_.AddObserver(observer); |
| 141 } | 135 } |
| 142 | 136 |
| 143 void WmShell::RemoveLockStateObserver(LockStateObserver* observer) { | 137 void WmShell::RemoveLockStateObserver(LockStateObserver* observer) { |
| 144 lock_state_observers_.RemoveObserver(observer); | 138 lock_state_observers_.RemoveObserver(observer); |
| 145 } | 139 } |
| 146 | 140 |
| 147 void WmShell::SetShelfDelegateForTesting( | 141 void WmShell::SetShelfDelegateForTesting( |
| 148 std::unique_ptr<ShelfDelegate> test_delegate) { | 142 std::unique_ptr<ShelfDelegate> test_delegate) { |
| 149 shelf_delegate_ = std::move(test_delegate); | 143 shelf_delegate_ = std::move(test_delegate); |
| 150 } | 144 } |
| 151 | 145 |
| 152 WmShell::WmShell(std::unique_ptr<ShellDelegate> shell_delegate) | 146 WmShell::WmShell() |
| 153 : delegate_(std::move(shell_delegate)), | 147 : app_list_(base::MakeUnique<app_list::AppList>()), |
| 154 app_list_(base::MakeUnique<app_list::AppList>()), | |
| 155 brightness_control_delegate_( | 148 brightness_control_delegate_( |
| 156 base::MakeUnique<system::BrightnessControllerChromeos>()), | 149 base::MakeUnique<system::BrightnessControllerChromeos>()), |
| 157 cast_config_(base::MakeUnique<CastConfigController>()), | 150 cast_config_(base::MakeUnique<CastConfigController>()), |
| 158 focus_cycler_(base::MakeUnique<FocusCycler>()), | 151 focus_cycler_(base::MakeUnique<FocusCycler>()), |
| 159 immersive_context_(base::MakeUnique<ImmersiveContextAsh>()), | 152 immersive_context_(base::MakeUnique<ImmersiveContextAsh>()), |
| 160 keyboard_brightness_control_delegate_( | 153 keyboard_brightness_control_delegate_( |
| 161 base::MakeUnique<KeyboardBrightnessController>()), | 154 base::MakeUnique<KeyboardBrightnessController>()), |
| 162 locale_notification_controller_( | 155 locale_notification_controller_( |
| 163 base::MakeUnique<LocaleNotificationController>()), | 156 base::MakeUnique<LocaleNotificationController>()), |
| 164 media_controller_(base::MakeUnique<MediaController>()), | 157 media_controller_(base::MakeUnique<MediaController>()), |
| 165 new_window_controller_(base::MakeUnique<NewWindowController>()), | 158 new_window_controller_(base::MakeUnique<NewWindowController>()), |
| 166 session_controller_(base::MakeUnique<SessionController>()), | 159 session_controller_(base::MakeUnique<SessionController>()), |
| 167 shelf_controller_(base::MakeUnique<ShelfController>()), | 160 shelf_controller_(base::MakeUnique<ShelfController>()), |
| 168 shutdown_controller_(base::MakeUnique<ShutdownController>()), | 161 shutdown_controller_(base::MakeUnique<ShutdownController>()), |
| 169 system_tray_controller_(base::MakeUnique<SystemTrayController>()), | 162 system_tray_controller_(base::MakeUnique<SystemTrayController>()), |
| 170 system_tray_notifier_(base::MakeUnique<SystemTrayNotifier>()), | 163 system_tray_notifier_(base::MakeUnique<SystemTrayNotifier>()), |
| 171 vpn_list_(base::MakeUnique<VpnList>()), | 164 vpn_list_(base::MakeUnique<VpnList>()), |
| 172 wallpaper_delegate_(delegate_->CreateWallpaperDelegate()), | |
| 173 window_cycle_controller_(base::MakeUnique<WindowCycleController>()), | 165 window_cycle_controller_(base::MakeUnique<WindowCycleController>()), |
| 174 window_selector_controller_( | 166 window_selector_controller_( |
| 175 base::MakeUnique<WindowSelectorController>()) { | 167 base::MakeUnique<WindowSelectorController>()) { |
| 168 DCHECK(!instance_); |
| 169 instance_ = this; |
| 176 session_controller_->AddSessionStateObserver(this); | 170 session_controller_->AddSessionStateObserver(this); |
| 177 | 171 |
| 178 prefs::mojom::PreferencesServiceFactoryPtr pref_factory_ptr; | |
| 179 // Can be null in tests. | |
| 180 if (!delegate_->GetShellConnector()) | |
| 181 return; | |
| 182 delegate_->GetShellConnector()->BindInterface(prefs::mojom::kServiceName, | |
| 183 &pref_factory_ptr); | |
| 184 pref_store_ = new preferences::PrefClientStore(std::move(pref_factory_ptr)); | |
| 185 } | 172 } |
| 186 | 173 |
| 187 RootWindowController* WmShell::GetPrimaryRootWindowController() { | 174 RootWindowController* WmShell::GetPrimaryRootWindowController() { |
| 188 return GetPrimaryRootWindow()->GetRootWindowController(); | 175 return GetPrimaryRootWindow()->GetRootWindowController(); |
| 189 } | 176 } |
| 190 | 177 |
| 191 bool WmShell::IsForceMaximizeOnFirstRun() { | 178 bool WmShell::IsForceMaximizeOnFirstRun() { |
| 192 return delegate()->IsForceMaximizeOnFirstRun(); | 179 return Shell::Get()->shell_delegate()->IsForceMaximizeOnFirstRun(); |
| 193 } | 180 } |
| 194 | 181 |
| 195 bool WmShell::IsSystemModalWindowOpen() { | 182 bool WmShell::IsSystemModalWindowOpen() { |
| 196 if (simulate_modal_window_open_for_testing_) | 183 if (simulate_modal_window_open_for_testing_) |
| 197 return true; | 184 return true; |
| 198 | 185 |
| 199 // Traverse all system modal containers, and find its direct child window | 186 // Traverse all system modal containers, and find its direct child window |
| 200 // with "SystemModal" setting, and visible. | 187 // with "SystemModal" setting, and visible. |
| 201 for (WmWindow* root : GetAllRootWindows()) { | 188 for (WmWindow* root : GetAllRootWindows()) { |
| 202 WmWindow* system_modal = | 189 WmWindow* system_modal = |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 } | 299 } |
| 313 | 300 |
| 314 void WmShell::SessionStateChanged(session_manager::SessionState state) { | 301 void WmShell::SessionStateChanged(session_manager::SessionState state) { |
| 315 // Create the shelf when a session becomes active. It's safe to do this | 302 // Create the shelf when a session becomes active. It's safe to do this |
| 316 // multiple times (e.g. initial login vs. multiprofile add session). | 303 // multiple times (e.g. initial login vs. multiprofile add session). |
| 317 if (state == session_manager::SessionState::ACTIVE) | 304 if (state == session_manager::SessionState::ACTIVE) |
| 318 CreateShelfView(); | 305 CreateShelfView(); |
| 319 } | 306 } |
| 320 | 307 |
| 321 } // namespace ash | 308 } // namespace ash |
| OLD | NEW |