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

Side by Side Diff: ash/shell.cc

Issue 2739763003: Moves maintaining ShellObservers back to Shell (Closed)
Patch Set: 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
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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // Use translucent-style window frames for dialogs. 282 // Use translucent-style window frames for dialogs.
282 return new CustomFrameViewAsh(widget); 283 return new CustomFrameViewAsh(widget);
283 } 284 }
284 285
285 void Shell::SetDisplayWorkAreaInsets(Window* contains, 286 void Shell::SetDisplayWorkAreaInsets(Window* contains,
286 const gfx::Insets& insets) { 287 const gfx::Insets& insets) {
287 wm_shell_->SetDisplayWorkAreaInsets(WmWindow::Get(contains), insets); 288 wm_shell_->SetDisplayWorkAreaInsets(WmWindow::Get(contains), insets);
288 } 289 }
289 290
290 void Shell::OnLoginStateChanged(LoginStatus status) { 291 void Shell::OnLoginStateChanged(LoginStatus status) {
291 for (auto& observer : *wm_shell_->shell_observers()) 292 for (auto& observer : shell_observers_)
292 observer.OnLoginStateChanged(status); 293 observer.OnLoginStateChanged(status);
293 } 294 }
294 295
295 void Shell::OnAppTerminating() { 296 void Shell::OnAppTerminating() {
296 for (auto& observer : *wm_shell_->shell_observers()) 297 for (auto& observer : shell_observers_)
297 observer.OnAppTerminating(); 298 observer.OnAppTerminating();
298 } 299 }
299 300
300 void Shell::OnLockStateChanged(bool locked) { 301 void Shell::OnLockStateChanged(bool locked) {
301 for (auto& observer : *wm_shell_->shell_observers()) 302 for (auto& observer : shell_observers_)
302 observer.OnLockStateChanged(locked); 303 observer.OnLockStateChanged(locked);
303 #ifndef NDEBUG 304 #ifndef NDEBUG
304 // Make sure that there is no system modal in Lock layer when unlocked. 305 // Make sure that there is no system modal in Lock layer when unlocked.
305 if (!locked) { 306 if (!locked) {
306 std::vector<WmWindow*> containers = wm::GetContainersFromAllRootWindows( 307 std::vector<WmWindow*> containers = wm::GetContainersFromAllRootWindows(
307 kShellWindowId_LockSystemModalContainer, 308 kShellWindowId_LockSystemModalContainer,
308 WmWindow::Get(GetPrimaryRootWindow())); 309 WmWindow::Get(GetPrimaryRootWindow()));
309 for (WmWindow* container : containers) 310 for (WmWindow* container : containers)
310 DCHECK(container->GetChildren().empty()); 311 DCHECK(container->GetChildren().empty());
311 } 312 }
312 #endif 313 #endif
313 } 314 }
314 315
315 void Shell::OnCastingSessionStartedOrStopped(bool started) { 316 void Shell::OnCastingSessionStartedOrStopped(bool started) {
316 for (auto& observer : *wm_shell_->shell_observers()) 317 for (auto& observer : shell_observers_)
317 observer.OnCastingSessionStartedOrStopped(started); 318 observer.OnCastingSessionStartedOrStopped(started);
318 } 319 }
319 320
320 void Shell::OnRootWindowAdded(WmWindow* root_window) { 321 void Shell::OnRootWindowAdded(WmWindow* root_window) {
321 for (auto& observer : *wm_shell_->shell_observers()) 322 for (auto& observer : shell_observers_)
322 observer.OnRootWindowAdded(root_window); 323 observer.OnRootWindowAdded(root_window);
323 } 324 }
324 325
325 void Shell::CreateKeyboard() { 326 void Shell::CreateKeyboard() {
326 InitKeyboard(); 327 InitKeyboard();
327 GetPrimaryRootWindowController()->ActivateKeyboard( 328 GetPrimaryRootWindowController()->ActivateKeyboard(
328 keyboard::KeyboardController::GetInstance()); 329 keyboard::KeyboardController::GetInstance());
329 } 330 }
330 331
331 void Shell::DeactivateKeyboard() { 332 void Shell::DeactivateKeyboard() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 366
366 SystemTray* Shell::GetPrimarySystemTray() { 367 SystemTray* Shell::GetPrimarySystemTray() {
367 return GetPrimaryRootWindowController()->GetSystemTray(); 368 return GetPrimaryRootWindowController()->GetSystemTray();
368 } 369 }
369 370
370 void Shell::SetTouchHudProjectionEnabled(bool enabled) { 371 void Shell::SetTouchHudProjectionEnabled(bool enabled) {
371 if (is_touch_hud_projection_enabled_ == enabled) 372 if (is_touch_hud_projection_enabled_ == enabled)
372 return; 373 return;
373 374
374 is_touch_hud_projection_enabled_ = enabled; 375 is_touch_hud_projection_enabled_ = enabled;
375 for (auto& observer : *wm_shell_->shell_observers()) 376 for (auto& observer : shell_observers_)
376 observer.OnTouchHudProjectionToggled(enabled); 377 observer.OnTouchHudProjectionToggled(enabled);
377 } 378 }
378 379
379 FirstRunHelper* Shell::CreateFirstRunHelper() { 380 FirstRunHelper* Shell::CreateFirstRunHelper() {
380 return new FirstRunHelperImpl; 381 return new FirstRunHelperImpl;
381 } 382 }
382 383
383 void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) { 384 void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) {
384 window_tree_host_manager_->cursor_window_controller() 385 window_tree_host_manager_->cursor_window_controller()
385 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip); 386 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip);
386 } 387 }
387 388
388 void Shell::SetCursorCompositingEnabled(bool enabled) { 389 void Shell::SetCursorCompositingEnabled(bool enabled) {
389 window_tree_host_manager_->cursor_window_controller() 390 window_tree_host_manager_->cursor_window_controller()
390 ->SetCursorCompositingEnabled(enabled); 391 ->SetCursorCompositingEnabled(enabled);
391 native_cursor_manager_->SetNativeCursorEnabled(!enabled); 392 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
392 } 393 }
393 394
394 void Shell::DoInitialWorkspaceAnimation() { 395 void Shell::DoInitialWorkspaceAnimation() {
395 return GetPrimaryRootWindowController() 396 return GetPrimaryRootWindowController()
396 ->workspace_controller() 397 ->workspace_controller()
397 ->DoInitialAnimation(); 398 ->DoInitialAnimation();
398 } 399 }
399 400
401 void Shell::AddShellObserver(ShellObserver* observer) {
402 shell_observers_.AddObserver(observer);
403 }
404
405 void Shell::RemoveShellObserver(ShellObserver* observer) {
406 shell_observers_.RemoveObserver(observer);
407 }
408
409 void Shell::OnMaximizeModeStarted() {
410 for (auto& observer : shell_observers_)
411 observer.OnMaximizeModeStarted();
412 }
413
414 void Shell::OnMaximizeModeEnding() {
415 for (auto& observer : shell_observers_)
416 observer.OnMaximizeModeEnding();
417 }
418
419 void Shell::OnMaximizeModeEnded() {
420 for (auto& observer : shell_observers_)
421 observer.OnMaximizeModeEnded();
422 }
423
424 void Shell::OnOverviewModeStarting() {
425 for (auto& observer : shell_observers_)
426 observer.OnOverviewModeStarting();
427 }
428
429 void Shell::OnOverviewModeEnded() {
430 for (auto& observer : shell_observers_)
431 observer.OnOverviewModeEnded();
432 }
433
434 void Shell::NotifyFullscreenStateChanged(bool is_fullscreen,
435 WmWindow* root_window) {
436 for (auto& observer : shell_observers_)
437 observer.OnFullscreenStateChanged(is_fullscreen, root_window);
438 }
439
440 void Shell::NotifyPinnedStateChanged(WmWindow* pinned_window) {
441 for (auto& observer : shell_observers_)
442 observer.OnPinnedStateChanged(pinned_window);
443 }
444
445 void Shell::NotifyVirtualKeyboardActivated(bool activated) {
446 for (auto& observer : shell_observers_)
447 observer.OnVirtualKeyboardStateChanged(activated);
448 }
449
450 void Shell::NotifyShelfCreatedForRootWindow(WmWindow* root_window) {
451 for (auto& observer : shell_observers_)
452 observer.OnShelfCreatedForRootWindow(root_window);
453 }
454
455 void Shell::NotifyShelfAlignmentChanged(WmWindow* root_window) {
456 for (auto& observer : shell_observers_)
457 observer.OnShelfAlignmentChanged(root_window);
458 }
459
460 void Shell::NotifyShelfAutoHideBehaviorChanged(WmWindow* root_window) {
461 for (auto& observer : shell_observers_)
462 observer.OnShelfAutoHideBehaviorChanged(root_window);
463 }
464
400 //////////////////////////////////////////////////////////////////////////////// 465 ////////////////////////////////////////////////////////////////////////////////
401 // Shell, private: 466 // Shell, private:
402 467
403 Shell::Shell(std::unique_ptr<WmShell> wm_shell) 468 Shell::Shell(std::unique_ptr<WmShell> wm_shell)
404 : wm_shell_(std::move(wm_shell)), 469 : wm_shell_(std::move(wm_shell)),
405 link_handler_model_factory_(nullptr), 470 link_handler_model_factory_(nullptr),
406 activation_client_(nullptr), 471 activation_client_(nullptr),
407 display_configurator_(new display::DisplayConfigurator()), 472 display_configurator_(new display::DisplayConfigurator()),
408 native_cursor_manager_(nullptr), 473 native_cursor_manager_(nullptr),
409 simulate_modal_window_open_for_testing_(false), 474 simulate_modal_window_open_for_testing_(false),
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 623
559 keyboard::KeyboardController::ResetInstance(nullptr); 624 keyboard::KeyboardController::ResetInstance(nullptr);
560 625
561 display_color_manager_.reset(); 626 display_color_manager_.reset();
562 if (display_change_observer_) 627 if (display_change_observer_)
563 display_configurator_->RemoveObserver(display_change_observer_.get()); 628 display_configurator_->RemoveObserver(display_change_observer_.get());
564 if (display_error_observer_) 629 if (display_error_observer_)
565 display_configurator_->RemoveObserver(display_error_observer_.get()); 630 display_configurator_->RemoveObserver(display_error_observer_.get());
566 if (projecting_observer_) { 631 if (projecting_observer_) {
567 display_configurator_->RemoveObserver(projecting_observer_.get()); 632 display_configurator_->RemoveObserver(projecting_observer_.get());
568 wm_shell_->RemoveShellObserver(projecting_observer_.get()); 633 RemoveShellObserver(projecting_observer_.get());
569 } 634 }
570 display_change_observer_.reset(); 635 display_change_observer_.reset();
571 shutdown_observer_.reset(); 636 shutdown_observer_.reset();
572 637
573 PowerStatus::Shutdown(); 638 PowerStatus::Shutdown();
574 639
575 // Ensure that DBusThreadManager outlives this Shell. 640 // Ensure that DBusThreadManager outlives this Shell.
576 DCHECK(chromeos::DBusThreadManager::IsInitialized()); 641 DCHECK(chromeos::DBusThreadManager::IsInitialized());
577 642
578 // Needs to happen right before |instance_| is reset. 643 // Needs to happen right before |instance_| is reset.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 !gpu_support_->IsPanelFittingDisabled()); 687 !gpu_support_->IsPanelFittingDisabled());
623 #endif 688 #endif
624 } 689 }
625 690
626 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell. 691 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell.
627 chromeos::DBusThreadManager* dbus_thread_manager = 692 chromeos::DBusThreadManager* dbus_thread_manager =
628 chromeos::DBusThreadManager::Get(); 693 chromeos::DBusThreadManager::Get();
629 projecting_observer_.reset( 694 projecting_observer_.reset(
630 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient())); 695 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient()));
631 display_configurator_->AddObserver(projecting_observer_.get()); 696 display_configurator_->AddObserver(projecting_observer_.get());
632 wm_shell_->AddShellObserver(projecting_observer_.get()); 697 AddShellObserver(projecting_observer_.get());
633 698
634 if (!display_initialized && chromeos::IsRunningAsSystemCompositor()) { 699 if (!display_initialized && chromeos::IsRunningAsSystemCompositor()) {
635 display_change_observer_ = base::MakeUnique<display::DisplayChangeObserver>( 700 display_change_observer_ = base::MakeUnique<display::DisplayChangeObserver>(
636 display_configurator_.get(), display_manager_.get()); 701 display_configurator_.get(), display_manager_.get());
637 702
638 shutdown_observer_ = 703 shutdown_observer_ =
639 base::MakeUnique<ShutdownObserver>(display_configurator_.get()); 704 base::MakeUnique<ShutdownObserver>(display_configurator_.get());
640 705
641 // Register |display_change_observer_| first so that the rest of 706 // Register |display_change_observer_| first so that the rest of
642 // observer gets invoked after the root windows are configured. 707 // observer gets invoked after the root windows are configured.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 AddPreTargetHandler(speech_feedback_handler_.get()); 784 AddPreTargetHandler(speech_feedback_handler_.get());
720 785
721 // The order in which event filters are added is significant. 786 // The order in which event filters are added is significant.
722 787
723 // ui::UserActivityDetector passes events to observers, so let them get 788 // ui::UserActivityDetector passes events to observers, so let them get
724 // rewritten first. 789 // rewritten first.
725 user_activity_detector_.reset(new ui::UserActivityDetector); 790 user_activity_detector_.reset(new ui::UserActivityDetector);
726 791
727 overlay_filter_.reset(new OverlayEventFilter); 792 overlay_filter_.reset(new OverlayEventFilter);
728 AddPreTargetHandler(overlay_filter_.get()); 793 AddPreTargetHandler(overlay_filter_.get());
729 wm_shell_->AddShellObserver(overlay_filter_.get()); 794 AddShellObserver(overlay_filter_.get());
730 795
731 accelerator_filter_.reset(new ::wm::AcceleratorFilter( 796 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
732 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate), 797 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate),
733 wm_shell_->accelerator_controller()->accelerator_history())); 798 wm_shell_->accelerator_controller()->accelerator_history()));
734 AddPreTargetHandler(accelerator_filter_.get()); 799 AddPreTargetHandler(accelerator_filter_.get());
735 800
736 event_transformation_handler_.reset(new EventTransformationHandler); 801 event_transformation_handler_.reset(new EventTransformationHandler);
737 AddPreTargetHandler(event_transformation_handler_.get()); 802 AddPreTargetHandler(event_transformation_handler_.get());
738 803
739 toplevel_window_event_handler_.reset( 804 toplevel_window_event_handler_.reset(
(...skipping 11 matching lines...) Expand all
751 } 816 }
752 817
753 lock_state_controller_ = 818 lock_state_controller_ =
754 base::MakeUnique<LockStateController>(wm_shell_->shutdown_controller()); 819 base::MakeUnique<LockStateController>(wm_shell_->shutdown_controller());
755 power_button_controller_.reset( 820 power_button_controller_.reset(
756 new PowerButtonController(lock_state_controller_.get())); 821 new PowerButtonController(lock_state_controller_.get()));
757 // Pass the initial display state to PowerButtonController. 822 // Pass the initial display state to PowerButtonController.
758 power_button_controller_->OnDisplayModeChanged( 823 power_button_controller_->OnDisplayModeChanged(
759 display_configurator_->cached_displays()); 824 display_configurator_->cached_displays());
760 825
761 wm_shell_->AddShellObserver(lock_state_controller_.get()); 826 AddShellObserver(lock_state_controller_.get());
762 827
763 // The connector is unavailable in some tests. 828 // The connector is unavailable in some tests.
764 if (is_mash && wm_shell_->delegate()->GetShellConnector()) { 829 if (is_mash && wm_shell_->delegate()->GetShellConnector()) {
765 ui::mojom::UserActivityMonitorPtr user_activity_monitor; 830 ui::mojom::UserActivityMonitorPtr user_activity_monitor;
766 wm_shell_->delegate()->GetShellConnector()->BindInterface( 831 wm_shell_->delegate()->GetShellConnector()->BindInterface(
767 ui::mojom::kServiceName, &user_activity_monitor); 832 ui::mojom::kServiceName, &user_activity_monitor);
768 user_activity_forwarder_ = base::MakeUnique<aura::UserActivityForwarder>( 833 user_activity_forwarder_ = base::MakeUnique<aura::UserActivityForwarder>(
769 std::move(user_activity_monitor), user_activity_detector_.get()); 834 std::move(user_activity_monitor), user_activity_detector_.get());
770 } 835 }
771 836
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 screen_layout_observer_.reset(new ScreenLayoutObserver()); 925 screen_layout_observer_.reset(new ScreenLayoutObserver());
861 } 926 }
862 sms_observer_.reset(new SmsObserver()); 927 sms_observer_.reset(new SmsObserver());
863 928
864 // The compositor thread and main message loop have to be running in 929 // The compositor thread and main message loop have to be running in
865 // order to create mirror window. Run it after the main message loop 930 // order to create mirror window. Run it after the main message loop
866 // is started. 931 // is started.
867 if (!is_mash) 932 if (!is_mash)
868 display_manager_->CreateMirrorWindowAsyncIfAny(); 933 display_manager_->CreateMirrorWindowAsyncIfAny();
869 934
870 for (auto& observer : *wm_shell_->shell_observers()) 935 for (auto& observer : shell_observers_)
871 observer.OnShellInitialized(); 936 observer.OnShellInitialized();
872 937
873 if (!is_mash) 938 if (!is_mash)
874 user_metrics_recorder_->OnShellInitialized(); 939 user_metrics_recorder_->OnShellInitialized();
875 } 940 }
876 941
877 void Shell::InitKeyboard() { 942 void Shell::InitKeyboard() {
878 if (keyboard::IsKeyboardEnabled()) { 943 if (keyboard::IsKeyboardEnabled()) {
879 if (keyboard::KeyboardController::GetInstance()) { 944 if (keyboard::KeyboardController::GetInstance()) {
880 RootWindowControllerList controllers = GetAllRootWindowControllers(); 945 RootWindowControllerList controllers = GetAllRootWindowControllers();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const { 1018 std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
954 return std::unique_ptr<ui::EventTargetIterator>(); 1019 return std::unique_ptr<ui::EventTargetIterator>();
955 } 1020 }
956 1021
957 ui::EventTargeter* Shell::GetEventTargeter() { 1022 ui::EventTargeter* Shell::GetEventTargeter() {
958 NOTREACHED(); 1023 NOTREACHED();
959 return nullptr; 1024 return nullptr;
960 } 1025 }
961 1026
962 } // namespace ash 1027 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698