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

Side by Side Diff: ash/common/wm_shell.cc

Issue 2761373002: Move yet more from WmShell 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/common/wm_shell.h ('k') | ash/metrics/user_metrics_recorder.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 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/session/session_controller.h" 10 #include "ash/common/session/session_controller.h"
11 #include "ash/common/session/session_state_delegate.h" 11 #include "ash/common/session/session_state_delegate.h"
12 #include "ash/common/shelf/app_list_shelf_item_delegate.h" 12 #include "ash/common/shelf/app_list_shelf_item_delegate.h"
13 #include "ash/common/shelf/shelf_controller.h"
14 #include "ash/common/shelf/shelf_delegate.h"
15 #include "ash/common/shelf/shelf_model.h"
16 #include "ash/common/shelf/shelf_window_watcher.h"
17 #include "ash/common/shell_delegate.h" 13 #include "ash/common/shell_delegate.h"
18 #include "ash/common/shutdown_controller.h" 14 #include "ash/common/shutdown_controller.h"
19 #include "ash/common/system/chromeos/network/vpn_list.h" 15 #include "ash/common/system/chromeos/network/vpn_list.h"
20 #include "ash/common/system/tray/system_tray_notifier.h" 16 #include "ash/common/system/tray/system_tray_notifier.h"
21 #include "ash/common/wm/overview/window_selector_controller.h" 17 #include "ash/common/wm/overview/window_selector_controller.h"
22 #include "ash/common/wm/root_window_finder.h" 18 #include "ash/common/wm/root_window_finder.h"
23 #include "ash/common/wm/system_modal_container_layout_manager.h" 19 #include "ash/common/wm/system_modal_container_layout_manager.h"
24 #include "ash/common/wm/window_cycle_controller.h" 20 #include "ash/common/wm/window_cycle_controller.h"
25 #include "ash/common/wm_window.h" 21 #include "ash/common/wm_window.h"
26 #include "ash/public/cpp/shell_window_ids.h" 22 #include "ash/public/cpp/shell_window_ids.h"
27 #include "ash/root_window_controller.h" 23 #include "ash/root_window_controller.h"
28 #include "ash/shell.h" 24 #include "ash/shell.h"
29 #include "base/bind.h" 25 #include "base/bind.h"
30 #include "base/logging.h" 26 #include "base/logging.h"
31 #include "base/memory/ptr_util.h" 27 #include "base/memory/ptr_util.h"
32 #include "ui/display/display.h" 28 #include "ui/display/display.h"
33 29
34 namespace ash { 30 namespace ash {
35 31
36 // static 32 // static
37 WmShell* WmShell::instance_ = nullptr; 33 WmShell* WmShell::instance_ = nullptr;
38 34
39 WmShell::~WmShell() { 35 WmShell::~WmShell() {
40 DCHECK_EQ(this, instance_); 36 DCHECK_EQ(this, instance_);
41 instance_ = nullptr; 37 instance_ = nullptr;
42 session_controller_->RemoveSessionStateObserver(this);
43 } 38 }
44 39
45 // static 40 // static
46 WmShell* WmShell::Get() { 41 WmShell* WmShell::Get() {
47 return instance_; 42 return instance_;
48 } 43 }
49 44
50 void WmShell::Shutdown() { 45 void WmShell::Shutdown() {
51 // ShelfWindowWatcher has window observers and a pointer to the shelf model.
52 shelf_window_watcher_.reset();
53 // ShelfItemDelegate subclasses it owns have complex cleanup to run (e.g. ARC
54 // shelf items in Chrome) so explicitly shutdown early.
55 shelf_model()->DestroyItemDelegates();
56 // Must be destroyed before FocusClient.
57 shelf_delegate_.reset();
58
59 // Removes itself as an observer of |pref_store_|.
60 shelf_controller_.reset();
61 }
62
63 ShelfModel* WmShell::shelf_model() {
64 return shelf_controller_->model();
65 } 46 }
66 47
67 void WmShell::ShowContextMenu(const gfx::Point& location_in_screen, 48 void WmShell::ShowContextMenu(const gfx::Point& location_in_screen,
68 ui::MenuSourceType source_type) { 49 ui::MenuSourceType source_type) {
69 // Bail if there is no active user session or if the screen is locked. 50 // Bail if there is no active user session or if the screen is locked.
70 if (session_controller()->NumberOfLoggedInUsers() < 1 || 51 if (Shell::Get()->session_controller()->NumberOfLoggedInUsers() < 1 ||
71 session_controller()->IsScreenLocked()) { 52 Shell::Get()->session_controller()->IsScreenLocked()) {
72 return; 53 return;
73 } 54 }
74 55
75 WmWindow* root = wm::GetRootWindowAt(location_in_screen); 56 WmWindow* root = wm::GetRootWindowAt(location_in_screen);
76 root->GetRootWindowController()->ShowContextMenu(location_in_screen, 57 root->GetRootWindowController()->ShowContextMenu(location_in_screen,
77 source_type); 58 source_type);
78 } 59 }
79 60
80 void WmShell::CreateShelfView() {
81 // Must occur after SessionController creation and user login.
82 DCHECK(session_controller());
83 DCHECK_GT(session_controller()->NumberOfLoggedInUsers(), 0);
84 CreateShelfDelegate();
85
86 for (WmWindow* root_window : GetAllRootWindows())
87 root_window->GetRootWindowController()->CreateShelfView();
88 }
89
90 void WmShell::CreateShelfDelegate() {
91 // May be called multiple times as shelves are created and destroyed.
92 if (shelf_delegate_)
93 return;
94 // Must occur after SessionController creation and user login because
95 // Chrome's implementation of ShelfDelegate assumes it can get information
96 // about multi-profile login state.
97 DCHECK(session_controller());
98 DCHECK_GT(session_controller()->NumberOfLoggedInUsers(), 0);
99 shelf_delegate_.reset(
100 Shell::Get()->shell_delegate()->CreateShelfDelegate(shelf_model()));
101 shelf_window_watcher_.reset(new ShelfWindowWatcher(shelf_model()));
102 }
103
104 void WmShell::UpdateAfterLoginStatusChange(LoginStatus status) {
105 for (WmWindow* root_window : GetAllRootWindows()) {
106 root_window->GetRootWindowController()->UpdateAfterLoginStatusChange(
107 status);
108 }
109 }
110
111 void WmShell::OnLockStateEvent(LockStateObserver::EventType event) { 61 void WmShell::OnLockStateEvent(LockStateObserver::EventType event) {
112 for (auto& observer : lock_state_observers_) 62 for (auto& observer : lock_state_observers_)
113 observer.OnLockStateEvent(event); 63 observer.OnLockStateEvent(event);
114 } 64 }
115 65
116 void WmShell::AddLockStateObserver(LockStateObserver* observer) { 66 void WmShell::AddLockStateObserver(LockStateObserver* observer) {
117 lock_state_observers_.AddObserver(observer); 67 lock_state_observers_.AddObserver(observer);
118 } 68 }
119 69
120 void WmShell::RemoveLockStateObserver(LockStateObserver* observer) { 70 void WmShell::RemoveLockStateObserver(LockStateObserver* observer) {
121 lock_state_observers_.RemoveObserver(observer); 71 lock_state_observers_.RemoveObserver(observer);
122 } 72 }
123 73
124 void WmShell::SetShelfDelegateForTesting(
125 std::unique_ptr<ShelfDelegate> test_delegate) {
126 shelf_delegate_ = std::move(test_delegate);
127 }
128
129 WmShell::WmShell() 74 WmShell::WmShell()
130 : session_controller_(base::MakeUnique<SessionController>()), 75 : shutdown_controller_(base::MakeUnique<ShutdownController>()),
131 shelf_controller_(base::MakeUnique<ShelfController>()),
132 shutdown_controller_(base::MakeUnique<ShutdownController>()),
133 system_tray_notifier_(base::MakeUnique<SystemTrayNotifier>()), 76 system_tray_notifier_(base::MakeUnique<SystemTrayNotifier>()),
134 vpn_list_(base::MakeUnique<VpnList>()), 77 vpn_list_(base::MakeUnique<VpnList>()),
135 window_cycle_controller_(base::MakeUnique<WindowCycleController>()), 78 window_cycle_controller_(base::MakeUnique<WindowCycleController>()),
136 window_selector_controller_( 79 window_selector_controller_(
137 base::MakeUnique<WindowSelectorController>()) { 80 base::MakeUnique<WindowSelectorController>()) {
138 DCHECK(!instance_); 81 DCHECK(!instance_);
139 instance_ = this; 82 instance_ = this;
140 session_controller_->AddSessionStateObserver(this);
141 } 83 }
142 84
143 RootWindowController* WmShell::GetPrimaryRootWindowController() { 85 RootWindowController* WmShell::GetPrimaryRootWindowController() {
144 return GetPrimaryRootWindow()->GetRootWindowController(); 86 return GetPrimaryRootWindow()->GetRootWindowController();
145 } 87 }
146 88
147 bool WmShell::IsForceMaximizeOnFirstRun() { 89 bool WmShell::IsForceMaximizeOnFirstRun() {
148 return Shell::Get()->shell_delegate()->IsForceMaximizeOnFirstRun(); 90 return Shell::Get()->shell_delegate()->IsForceMaximizeOnFirstRun();
149 } 91 }
150 92
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 135 }
194 136
195 void WmShell::DeleteWindowCycleController() { 137 void WmShell::DeleteWindowCycleController() {
196 window_cycle_controller_.reset(); 138 window_cycle_controller_.reset();
197 } 139 }
198 140
199 void WmShell::DeleteWindowSelectorController() { 141 void WmShell::DeleteWindowSelectorController() {
200 window_selector_controller_.reset(); 142 window_selector_controller_.reset();
201 } 143 }
202 144
203 void WmShell::SessionStateChanged(session_manager::SessionState state) {
204 // Create the shelf when a session becomes active. It's safe to do this
205 // multiple times (e.g. initial login vs. multiprofile add session).
206 if (state == session_manager::SessionState::ACTIVE)
207 CreateShelfView();
208
209 // Only trigger an update in mash because with classic ash chrome calls
210 // UpdateAfterLoginStatusChange() directly.
211 if (IsRunningInMash()) {
212 // TODO(jamescook): Should this call Shell::OnLoginStatusChanged() too?
213 UpdateAfterLoginStatusChange(session_controller_->GetLoginStatus());
214 }
215 }
216
217 } // namespace ash 145 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm_shell.h ('k') | ash/metrics/user_metrics_recorder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698