Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: ash/shell.cc

Issue 2739763003: Moves maintaining ShellObservers back to Shell (Closed)
Patch Set: merge Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/shell.h ('k') | ash/system/chromeos/power/tablet_power_button_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ash/shell.h" 5 #include "ash/shell.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 10 matching lines...) Expand all
21 #include "ash/common/gpu_support.h" 21 #include "ash/common/gpu_support.h"
22 #include "ash/common/keyboard/keyboard_ui.h" 22 #include "ash/common/keyboard/keyboard_ui.h"
23 #include "ash/common/login_status.h" 23 #include "ash/common/login_status.h"
24 #include "ash/common/session/session_state_delegate.h" 24 #include "ash/common/session/session_state_delegate.h"
25 #include "ash/common/shelf/app_list_shelf_item_delegate.h" 25 #include "ash/common/shelf/app_list_shelf_item_delegate.h"
26 #include "ash/common/shelf/shelf_delegate.h" 26 #include "ash/common/shelf/shelf_delegate.h"
27 #include "ash/common/shelf/shelf_item_delegate.h" 27 #include "ash/common/shelf/shelf_item_delegate.h"
28 #include "ash/common/shelf/shelf_model.h" 28 #include "ash/common/shelf/shelf_model.h"
29 #include "ash/common/shelf/wm_shelf.h" 29 #include "ash/common/shelf/wm_shelf.h"
30 #include "ash/common/shell_delegate.h" 30 #include "ash/common/shell_delegate.h"
31 #include "ash/common/shell_observer.h"
31 #include "ash/common/system/chromeos/bluetooth/bluetooth_notification_controller .h" 32 #include "ash/common/system/chromeos/bluetooth/bluetooth_notification_controller .h"
32 #include "ash/common/system/chromeos/network/sms_observer.h" 33 #include "ash/common/system/chromeos/network/sms_observer.h"
33 #include "ash/common/system/chromeos/power/power_status.h" 34 #include "ash/common/system/chromeos/power/power_status.h"
34 #include "ash/common/system/status_area_widget.h" 35 #include "ash/common/system/status_area_widget.h"
35 #include "ash/common/system/tray/system_tray_delegate.h" 36 #include "ash/common/system/tray/system_tray_delegate.h"
36 #include "ash/common/wallpaper/wallpaper_delegate.h" 37 #include "ash/common/wallpaper/wallpaper_delegate.h"
37 #include "ash/common/wm/container_finder.h" 38 #include "ash/common/wm/container_finder.h"
38 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 39 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
39 #include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h" 40 #include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h"
40 #include "ash/common/wm/mru_window_tracker.h" 41 #include "ash/common/wm/mru_window_tracker.h"
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // Use translucent-style window frames for dialogs. 284 // Use translucent-style window frames for dialogs.
284 return new CustomFrameViewAsh(widget); 285 return new CustomFrameViewAsh(widget);
285 } 286 }
286 287
287 void Shell::SetDisplayWorkAreaInsets(Window* contains, 288 void Shell::SetDisplayWorkAreaInsets(Window* contains,
288 const gfx::Insets& insets) { 289 const gfx::Insets& insets) {
289 wm_shell_->SetDisplayWorkAreaInsets(WmWindow::Get(contains), insets); 290 wm_shell_->SetDisplayWorkAreaInsets(WmWindow::Get(contains), insets);
290 } 291 }
291 292
292 void Shell::OnLoginStateChanged(LoginStatus status) { 293 void Shell::OnLoginStateChanged(LoginStatus status) {
293 for (auto& observer : *wm_shell_->shell_observers()) 294 for (auto& observer : shell_observers_)
294 observer.OnLoginStateChanged(status); 295 observer.OnLoginStateChanged(status);
295 } 296 }
296 297
297 void Shell::OnAppTerminating() { 298 void Shell::OnAppTerminating() {
298 for (auto& observer : *wm_shell_->shell_observers()) 299 for (auto& observer : shell_observers_)
299 observer.OnAppTerminating(); 300 observer.OnAppTerminating();
300 } 301 }
301 302
302 void Shell::OnLockStateChanged(bool locked) { 303 void Shell::OnLockStateChanged(bool locked) {
303 for (auto& observer : *wm_shell_->shell_observers()) 304 for (auto& observer : shell_observers_)
304 observer.OnLockStateChanged(locked); 305 observer.OnLockStateChanged(locked);
305 #ifndef NDEBUG 306 #ifndef NDEBUG
306 // Make sure that there is no system modal in Lock layer when unlocked. 307 // Make sure that there is no system modal in Lock layer when unlocked.
307 if (!locked) { 308 if (!locked) {
308 std::vector<WmWindow*> containers = wm::GetContainersFromAllRootWindows( 309 std::vector<WmWindow*> containers = wm::GetContainersFromAllRootWindows(
309 kShellWindowId_LockSystemModalContainer, 310 kShellWindowId_LockSystemModalContainer,
310 WmWindow::Get(GetPrimaryRootWindow())); 311 WmWindow::Get(GetPrimaryRootWindow()));
311 for (WmWindow* container : containers) 312 for (WmWindow* container : containers)
312 DCHECK(container->GetChildren().empty()); 313 DCHECK(container->GetChildren().empty());
313 } 314 }
314 #endif 315 #endif
315 } 316 }
316 317
317 void Shell::OnCastingSessionStartedOrStopped(bool started) { 318 void Shell::OnCastingSessionStartedOrStopped(bool started) {
318 for (auto& observer : *wm_shell_->shell_observers()) 319 for (auto& observer : shell_observers_)
319 observer.OnCastingSessionStartedOrStopped(started); 320 observer.OnCastingSessionStartedOrStopped(started);
320 } 321 }
321 322
322 void Shell::OnRootWindowAdded(WmWindow* root_window) { 323 void Shell::OnRootWindowAdded(WmWindow* root_window) {
323 for (auto& observer : *wm_shell_->shell_observers()) 324 for (auto& observer : shell_observers_)
324 observer.OnRootWindowAdded(root_window); 325 observer.OnRootWindowAdded(root_window);
325 } 326 }
326 327
327 void Shell::CreateKeyboard() { 328 void Shell::CreateKeyboard() {
328 InitKeyboard(); 329 InitKeyboard();
329 GetPrimaryRootWindowController()->ActivateKeyboard( 330 GetPrimaryRootWindowController()->ActivateKeyboard(
330 keyboard::KeyboardController::GetInstance()); 331 keyboard::KeyboardController::GetInstance());
331 } 332 }
332 333
333 void Shell::DeactivateKeyboard() { 334 void Shell::DeactivateKeyboard() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 372
372 SystemTray* Shell::GetPrimarySystemTray() { 373 SystemTray* Shell::GetPrimarySystemTray() {
373 return GetPrimaryRootWindowController()->GetSystemTray(); 374 return GetPrimaryRootWindowController()->GetSystemTray();
374 } 375 }
375 376
376 void Shell::SetTouchHudProjectionEnabled(bool enabled) { 377 void Shell::SetTouchHudProjectionEnabled(bool enabled) {
377 if (is_touch_hud_projection_enabled_ == enabled) 378 if (is_touch_hud_projection_enabled_ == enabled)
378 return; 379 return;
379 380
380 is_touch_hud_projection_enabled_ = enabled; 381 is_touch_hud_projection_enabled_ = enabled;
381 for (auto& observer : *wm_shell_->shell_observers()) 382 for (auto& observer : shell_observers_)
382 observer.OnTouchHudProjectionToggled(enabled); 383 observer.OnTouchHudProjectionToggled(enabled);
383 } 384 }
384 385
385 FirstRunHelper* Shell::CreateFirstRunHelper() { 386 FirstRunHelper* Shell::CreateFirstRunHelper() {
386 return new FirstRunHelperImpl; 387 return new FirstRunHelperImpl;
387 } 388 }
388 389
389 void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) { 390 void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) {
390 window_tree_host_manager_->cursor_window_controller() 391 window_tree_host_manager_->cursor_window_controller()
391 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip); 392 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip);
392 } 393 }
393 394
394 void Shell::SetCursorCompositingEnabled(bool enabled) { 395 void Shell::SetCursorCompositingEnabled(bool enabled) {
395 window_tree_host_manager_->cursor_window_controller() 396 window_tree_host_manager_->cursor_window_controller()
396 ->SetCursorCompositingEnabled(enabled); 397 ->SetCursorCompositingEnabled(enabled);
397 native_cursor_manager_->SetNativeCursorEnabled(!enabled); 398 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
398 } 399 }
399 400
400 void Shell::DoInitialWorkspaceAnimation() { 401 void Shell::DoInitialWorkspaceAnimation() {
401 return GetPrimaryRootWindowController() 402 return GetPrimaryRootWindowController()
402 ->workspace_controller() 403 ->workspace_controller()
403 ->DoInitialAnimation(); 404 ->DoInitialAnimation();
404 } 405 }
405 406
407 void Shell::AddShellObserver(ShellObserver* observer) {
408 shell_observers_.AddObserver(observer);
409 }
410
411 void Shell::RemoveShellObserver(ShellObserver* observer) {
412 shell_observers_.RemoveObserver(observer);
413 }
414
415 void Shell::NotifyMaximizeModeStarted() {
416 for (auto& observer : shell_observers_)
417 observer.OnMaximizeModeStarted();
418 }
419
420 void Shell::NotifyMaximizeModeEnding() {
421 for (auto& observer : shell_observers_)
422 observer.OnMaximizeModeEnding();
423 }
424
425 void Shell::NotifyMaximizeModeEnded() {
426 for (auto& observer : shell_observers_)
427 observer.OnMaximizeModeEnded();
428 }
429
430 void Shell::NotifyOverviewModeStarting() {
431 for (auto& observer : shell_observers_)
432 observer.OnOverviewModeStarting();
433 }
434
435 void Shell::NotifyOverviewModeEnded() {
436 for (auto& observer : shell_observers_)
437 observer.OnOverviewModeEnded();
438 }
439
440 void Shell::NotifyFullscreenStateChanged(bool is_fullscreen,
441 WmWindow* root_window) {
442 for (auto& observer : shell_observers_)
443 observer.OnFullscreenStateChanged(is_fullscreen, root_window);
444 }
445
446 void Shell::NotifyPinnedStateChanged(WmWindow* pinned_window) {
447 for (auto& observer : shell_observers_)
448 observer.OnPinnedStateChanged(pinned_window);
449 }
450
451 void Shell::NotifyVirtualKeyboardActivated(bool activated) {
452 for (auto& observer : shell_observers_)
453 observer.OnVirtualKeyboardStateChanged(activated);
454 }
455
456 void Shell::NotifyShelfCreatedForRootWindow(WmWindow* root_window) {
457 for (auto& observer : shell_observers_)
458 observer.OnShelfCreatedForRootWindow(root_window);
459 }
460
461 void Shell::NotifyShelfAlignmentChanged(WmWindow* root_window) {
462 for (auto& observer : shell_observers_)
463 observer.OnShelfAlignmentChanged(root_window);
464 }
465
466 void Shell::NotifyShelfAutoHideBehaviorChanged(WmWindow* root_window) {
467 for (auto& observer : shell_observers_)
468 observer.OnShelfAutoHideBehaviorChanged(root_window);
469 }
470
406 //////////////////////////////////////////////////////////////////////////////// 471 ////////////////////////////////////////////////////////////////////////////////
407 // Shell, private: 472 // Shell, private:
408 473
409 Shell::Shell(std::unique_ptr<WmShell> wm_shell) 474 Shell::Shell(std::unique_ptr<WmShell> wm_shell)
410 : wm_shell_(std::move(wm_shell)), 475 : wm_shell_(std::move(wm_shell)),
411 link_handler_model_factory_(nullptr), 476 link_handler_model_factory_(nullptr),
412 display_configurator_(new display::DisplayConfigurator()), 477 display_configurator_(new display::DisplayConfigurator()),
413 native_cursor_manager_(nullptr), 478 native_cursor_manager_(nullptr),
414 simulate_modal_window_open_for_testing_(false), 479 simulate_modal_window_open_for_testing_(false),
415 is_touch_hud_projection_enabled_(false) { 480 is_touch_hud_projection_enabled_(false) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 629
565 keyboard::KeyboardController::ResetInstance(nullptr); 630 keyboard::KeyboardController::ResetInstance(nullptr);
566 631
567 display_color_manager_.reset(); 632 display_color_manager_.reset();
568 if (display_change_observer_) 633 if (display_change_observer_)
569 display_configurator_->RemoveObserver(display_change_observer_.get()); 634 display_configurator_->RemoveObserver(display_change_observer_.get());
570 if (display_error_observer_) 635 if (display_error_observer_)
571 display_configurator_->RemoveObserver(display_error_observer_.get()); 636 display_configurator_->RemoveObserver(display_error_observer_.get());
572 if (projecting_observer_) { 637 if (projecting_observer_) {
573 display_configurator_->RemoveObserver(projecting_observer_.get()); 638 display_configurator_->RemoveObserver(projecting_observer_.get());
574 wm_shell_->RemoveShellObserver(projecting_observer_.get()); 639 RemoveShellObserver(projecting_observer_.get());
575 } 640 }
576 display_change_observer_.reset(); 641 display_change_observer_.reset();
577 shutdown_observer_.reset(); 642 shutdown_observer_.reset();
578 643
579 PowerStatus::Shutdown(); 644 PowerStatus::Shutdown();
580 645
581 // Ensure that DBusThreadManager outlives this Shell. 646 // Ensure that DBusThreadManager outlives this Shell.
582 DCHECK(chromeos::DBusThreadManager::IsInitialized()); 647 DCHECK(chromeos::DBusThreadManager::IsInitialized());
583 648
584 // Needs to happen right before |instance_| is reset. 649 // Needs to happen right before |instance_| is reset.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 !gpu_support_->IsPanelFittingDisabled()); 693 !gpu_support_->IsPanelFittingDisabled());
629 #endif 694 #endif
630 } 695 }
631 696
632 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell. 697 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell.
633 chromeos::DBusThreadManager* dbus_thread_manager = 698 chromeos::DBusThreadManager* dbus_thread_manager =
634 chromeos::DBusThreadManager::Get(); 699 chromeos::DBusThreadManager::Get();
635 projecting_observer_.reset( 700 projecting_observer_.reset(
636 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient())); 701 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient()));
637 display_configurator_->AddObserver(projecting_observer_.get()); 702 display_configurator_->AddObserver(projecting_observer_.get());
638 wm_shell_->AddShellObserver(projecting_observer_.get()); 703 AddShellObserver(projecting_observer_.get());
639 704
640 if (!display_initialized && chromeos::IsRunningAsSystemCompositor()) { 705 if (!display_initialized && chromeos::IsRunningAsSystemCompositor()) {
641 display_change_observer_ = base::MakeUnique<display::DisplayChangeObserver>( 706 display_change_observer_ = base::MakeUnique<display::DisplayChangeObserver>(
642 display_configurator_.get(), display_manager_.get()); 707 display_configurator_.get(), display_manager_.get());
643 708
644 shutdown_observer_ = 709 shutdown_observer_ =
645 base::MakeUnique<ShutdownObserver>(display_configurator_.get()); 710 base::MakeUnique<ShutdownObserver>(display_configurator_.get());
646 711
647 // Register |display_change_observer_| first so that the rest of 712 // Register |display_change_observer_| first so that the rest of
648 // observer gets invoked after the root windows are configured. 713 // observer gets invoked after the root windows are configured.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 AddPreTargetHandler(speech_feedback_handler_.get()); 785 AddPreTargetHandler(speech_feedback_handler_.get());
721 786
722 // The order in which event filters are added is significant. 787 // The order in which event filters are added is significant.
723 788
724 // ui::UserActivityDetector passes events to observers, so let them get 789 // ui::UserActivityDetector passes events to observers, so let them get
725 // rewritten first. 790 // rewritten first.
726 user_activity_detector_.reset(new ui::UserActivityDetector); 791 user_activity_detector_.reset(new ui::UserActivityDetector);
727 792
728 overlay_filter_.reset(new OverlayEventFilter); 793 overlay_filter_.reset(new OverlayEventFilter);
729 AddPreTargetHandler(overlay_filter_.get()); 794 AddPreTargetHandler(overlay_filter_.get());
730 wm_shell_->AddShellObserver(overlay_filter_.get()); 795 AddShellObserver(overlay_filter_.get());
731 796
732 accelerator_filter_.reset(new ::wm::AcceleratorFilter( 797 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
733 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate), 798 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate),
734 wm_shell_->accelerator_controller()->accelerator_history())); 799 wm_shell_->accelerator_controller()->accelerator_history()));
735 AddPreTargetHandler(accelerator_filter_.get()); 800 AddPreTargetHandler(accelerator_filter_.get());
736 801
737 event_transformation_handler_.reset(new EventTransformationHandler); 802 event_transformation_handler_.reset(new EventTransformationHandler);
738 AddPreTargetHandler(event_transformation_handler_.get()); 803 AddPreTargetHandler(event_transformation_handler_.get());
739 804
740 toplevel_window_event_handler_.reset( 805 toplevel_window_event_handler_.reset(
(...skipping 11 matching lines...) Expand all
752 } 817 }
753 818
754 lock_state_controller_ = 819 lock_state_controller_ =
755 base::MakeUnique<LockStateController>(wm_shell_->shutdown_controller()); 820 base::MakeUnique<LockStateController>(wm_shell_->shutdown_controller());
756 power_button_controller_.reset( 821 power_button_controller_.reset(
757 new PowerButtonController(lock_state_controller_.get())); 822 new PowerButtonController(lock_state_controller_.get()));
758 // Pass the initial display state to PowerButtonController. 823 // Pass the initial display state to PowerButtonController.
759 power_button_controller_->OnDisplayModeChanged( 824 power_button_controller_->OnDisplayModeChanged(
760 display_configurator_->cached_displays()); 825 display_configurator_->cached_displays());
761 826
762 wm_shell_->AddShellObserver(lock_state_controller_.get()); 827 AddShellObserver(lock_state_controller_.get());
763 828
764 // The connector is unavailable in some tests. 829 // The connector is unavailable in some tests.
765 if (is_mash && wm_shell_->delegate()->GetShellConnector()) { 830 if (is_mash && wm_shell_->delegate()->GetShellConnector()) {
766 ui::mojom::UserActivityMonitorPtr user_activity_monitor; 831 ui::mojom::UserActivityMonitorPtr user_activity_monitor;
767 wm_shell_->delegate()->GetShellConnector()->BindInterface( 832 wm_shell_->delegate()->GetShellConnector()->BindInterface(
768 ui::mojom::kServiceName, &user_activity_monitor); 833 ui::mojom::kServiceName, &user_activity_monitor);
769 user_activity_forwarder_ = base::MakeUnique<aura::UserActivityForwarder>( 834 user_activity_forwarder_ = base::MakeUnique<aura::UserActivityForwarder>(
770 std::move(user_activity_monitor), user_activity_detector_.get()); 835 std::move(user_activity_monitor), user_activity_detector_.get());
771 } 836 }
772 837
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 screen_layout_observer_.reset(new ScreenLayoutObserver()); 926 screen_layout_observer_.reset(new ScreenLayoutObserver());
862 } 927 }
863 sms_observer_.reset(new SmsObserver()); 928 sms_observer_.reset(new SmsObserver());
864 929
865 // The compositor thread and main message loop have to be running in 930 // The compositor thread and main message loop have to be running in
866 // order to create mirror window. Run it after the main message loop 931 // order to create mirror window. Run it after the main message loop
867 // is started. 932 // is started.
868 if (!is_mash) 933 if (!is_mash)
869 display_manager_->CreateMirrorWindowAsyncIfAny(); 934 display_manager_->CreateMirrorWindowAsyncIfAny();
870 935
871 for (auto& observer : *wm_shell_->shell_observers()) 936 for (auto& observer : shell_observers_)
872 observer.OnShellInitialized(); 937 observer.OnShellInitialized();
873 938
874 if (!is_mash) 939 if (!is_mash)
875 user_metrics_recorder_->OnShellInitialized(); 940 user_metrics_recorder_->OnShellInitialized();
876 } 941 }
877 942
878 void Shell::InitKeyboard() { 943 void Shell::InitKeyboard() {
879 if (keyboard::IsKeyboardEnabled()) { 944 if (keyboard::IsKeyboardEnabled()) {
880 if (keyboard::KeyboardController::GetInstance()) { 945 if (keyboard::KeyboardController::GetInstance()) {
881 RootWindowControllerList controllers = GetAllRootWindowControllers(); 946 RootWindowControllerList controllers = GetAllRootWindowControllers();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 void Shell::OnWindowActivated( 1026 void Shell::OnWindowActivated(
962 aura::client::ActivationChangeObserver::ActivationReason reason, 1027 aura::client::ActivationChangeObserver::ActivationReason reason,
963 aura::Window* gained_active, 1028 aura::Window* gained_active,
964 aura::Window* lost_active) { 1029 aura::Window* lost_active) {
965 WmWindow* gained_active_wm = WmWindow::Get(gained_active); 1030 WmWindow* gained_active_wm = WmWindow::Get(gained_active);
966 if (gained_active_wm) 1031 if (gained_active_wm)
967 root_window_for_new_windows_ = gained_active_wm->GetRootWindow(); 1032 root_window_for_new_windows_ = gained_active_wm->GetRootWindow();
968 } 1033 }
969 1034
970 } // namespace ash 1035 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shell.h ('k') | ash/system/chromeos/power/tablet_power_button_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698