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

Side by Side Diff: ash/mus/window_manager_application.cc

Issue 2072343002: Changes how window manager obtains WindowTree from mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include Created 4 years, 6 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/mus/window_manager_application.h ('k') | components/mus/demo/manifest.json » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/mus/window_manager_application.h" 5 #include "ash/mus/window_manager_application.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "ash/mus/accelerator_registrar_impl.h" 9 #include "ash/mus/accelerator_registrar_impl.h"
10 #include "ash/mus/bridge/wm_lookup_mus.h"
11 #include "ash/mus/bridge/wm_shell_mus.h"
12 #include "ash/mus/root_window_controller.h" 10 #include "ash/mus/root_window_controller.h"
13 #include "ash/mus/root_windows_observer.h" 11 #include "ash/mus/root_windows_observer.h"
14 #include "ash/mus/shelf_layout_impl.h" 12 #include "ash/mus/shelf_layout_impl.h"
15 #include "ash/mus/user_window_controller_impl.h" 13 #include "ash/mus/user_window_controller_impl.h"
14 #include "ash/mus/window_manager.h"
16 #include "base/bind.h" 15 #include "base/bind.h"
17 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
18 #include "components/mus/common/event_matcher_util.h" 17 #include "components/mus/common/event_matcher_util.h"
19 #include "components/mus/public/cpp/window.h" 18 #include "components/mus/public/cpp/window.h"
20 #include "components/mus/public/interfaces/window_manager_factory.mojom.h" 19 #include "components/mus/public/cpp/window_tree_client.h"
21 #include "services/shell/public/cpp/connection.h" 20 #include "services/shell/public/cpp/connection.h"
22 #include "services/shell/public/cpp/connector.h" 21 #include "services/shell/public/cpp/connector.h"
23 #include "services/tracing/public/cpp/tracing_impl.h" 22 #include "services/tracing/public/cpp/tracing_impl.h"
24 #include "ui/events/event.h" 23 #include "ui/events/event.h"
25 #include "ui/views/mus/aura_init.h" 24 #include "ui/views/mus/aura_init.h"
26 #include "ui/views/mus/screen_mus.h"
27 25
28 namespace ash { 26 namespace ash {
29 namespace mus { 27 namespace mus {
30 28
31 WindowManagerApplication::WindowManagerApplication() 29 WindowManagerApplication::WindowManagerApplication()
32 : connector_(nullptr), window_manager_factory_binding_(this) {} 30 : connector_(nullptr), screenlock_state_listener_binding_(this) {}
33 31
34 WindowManagerApplication::~WindowManagerApplication() { 32 WindowManagerApplication::~WindowManagerApplication() {
35 // AcceleratorRegistrarImpl removes an observer in its destructor. Destroy 33 // AcceleratorRegistrarImpl removes an observer in its destructor. Destroy
36 // it early on. 34 // it early on.
37 std::set<AcceleratorRegistrarImpl*> accelerator_registrars( 35 std::set<AcceleratorRegistrarImpl*> accelerator_registrars(
38 accelerator_registrars_); 36 accelerator_registrars_);
39 for (AcceleratorRegistrarImpl* registrar : accelerator_registrars) 37 for (AcceleratorRegistrarImpl* registrar : accelerator_registrars)
40 registrar->Destroy(); 38 registrar->Destroy();
41 39
42 std::set<RootWindowController*> controllers(root_controllers_); 40 // Destroy the WindowManager while still valid. This way we ensure
43 for (RootWindowController* controller : controllers) 41 // OnWillDestroyRootWindowController() is called (if it hasn't been already).
44 controller->Destroy(); 42 window_manager_.reset();
45 }
46
47 std::set<RootWindowController*> WindowManagerApplication::GetRootControllers() {
48 std::set<RootWindowController*> root_controllers;
49 for (RootWindowController* controller : root_controllers_) {
50 if (controller->root())
51 root_controllers.insert(controller);
52 }
53 return root_controllers;
54 }
55
56 void WindowManagerApplication::OnRootWindowControllerGotRoot(
57 RootWindowController* root_controller) {
58 if (shell_)
59 return; // |root_controller| is the > 1 root, nothing to do.
60
61 if (connector_)
62 aura_init_.reset(new views::AuraInit(connector_, "ash_mus_resources.pak"));
63
64 shell_.reset(new WmShellMus(root_controller->root()->window_tree()));
65 lookup_.reset(new WmLookupMus);
66 }
67
68 void WindowManagerApplication::OnRootWindowControllerDoneInit(
69 RootWindowController* root_controller) {
70 if (!screen_) {
71 std::unique_ptr<views::ScreenMus> screen(new views::ScreenMus(nullptr));
72 screen->Init(connector_);
73 screen_ = std::move(screen);
74 }
75
76 // TODO(msw): figure out if this should be per display, or global.
77 user_window_controller_->Initialize(root_controller);
78 for (auto& request : user_window_controller_requests_)
79 user_window_controller_bindings_.AddBinding(user_window_controller_.get(),
80 std::move(*request));
81 user_window_controller_requests_.clear();
82
83 // TODO(msw): figure out if this should be per display, or global.
84 shelf_layout_->Initialize(root_controller);
85 for (auto& request : shelf_layout_requests_)
86 shelf_layout_bindings_.AddBinding(shelf_layout_.get(), std::move(*request));
87 shelf_layout_requests_.clear();
88
89 FOR_EACH_OBSERVER(RootWindowsObserver, root_windows_observers_,
90 OnRootWindowControllerAdded(root_controller));
91 }
92
93 void WindowManagerApplication::OnRootWindowDestroyed(
94 RootWindowController* root_controller) {
95 root_controllers_.erase(root_controller);
96 user_window_controller_.reset(nullptr);
97 } 43 }
98 44
99 void WindowManagerApplication::OnAccelerator(uint32_t id, 45 void WindowManagerApplication::OnAccelerator(uint32_t id,
100 const ui::Event& event) { 46 const ui::Event& event) {
101 for (auto* registrar : accelerator_registrars_) { 47 for (auto* registrar : accelerator_registrars_) {
102 if (registrar->OwnsAccelerator(id)) { 48 if (registrar->OwnsAccelerator(id)) {
103 registrar->ProcessAccelerator(id, event); 49 registrar->ProcessAccelerator(id, event);
104 break; 50 break;
105 } 51 }
106 } 52 }
107 } 53 }
108 54
109 void WindowManagerApplication::AddRootWindowsObserver(
110 RootWindowsObserver* observer) {
111 root_windows_observers_.AddObserver(observer);
112 }
113
114 void WindowManagerApplication::RemoveRootWindowsObserver(
115 RootWindowsObserver* observer) {
116 root_windows_observers_.RemoveObserver(observer);
117 }
118
119 void WindowManagerApplication::OnAcceleratorRegistrarDestroyed( 55 void WindowManagerApplication::OnAcceleratorRegistrarDestroyed(
120 AcceleratorRegistrarImpl* registrar) { 56 AcceleratorRegistrarImpl* registrar) {
121 accelerator_registrars_.erase(registrar); 57 accelerator_registrars_.erase(registrar);
122 } 58 }
123 59
124 void WindowManagerApplication::AddRootWindowController( 60 void WindowManagerApplication::InitWindowManager(
125 RootWindowController* root_window_controller) { 61 ::mus::WindowTreeClient* window_tree_client) {
126 root_controllers_.insert(root_window_controller); 62 window_manager_->Init(window_tree_client);
63 window_manager_->AddRootWindowsObserver(this);
127 } 64 }
128 65
129 void WindowManagerApplication::Initialize(shell::Connector* connector, 66 void WindowManagerApplication::Initialize(shell::Connector* connector,
130 const shell::Identity& identity, 67 const shell::Identity& identity,
131 uint32_t id) { 68 uint32_t id) {
132 connector_ = connector; 69 connector_ = connector;
133 if (connector) { 70 window_manager_.reset(new WindowManager(this, connector_));
134 tracing_.Initialize(connector, identity.name());
135 71
136 ::mus::mojom::WindowManagerFactoryServicePtr wm_factory_service; 72 aura_init_.reset(new views::AuraInit(connector_, "ash_mus_resources.pak"));
137 connector_->ConnectToInterface("mojo:mus", &wm_factory_service);
138 wm_factory_service->SetWindowManagerFactory(
139 window_manager_factory_binding_.CreateInterfacePtrAndBind());
140 }
141 73
142 shelf_layout_.reset(new ShelfLayoutImpl); 74 tracing_.Initialize(connector, identity.name());
143 user_window_controller_.reset(new UserWindowControllerImpl()); 75
76 ::mus::WindowTreeClient* window_tree_client = new ::mus::WindowTreeClient(
77 window_manager_.get(), window_manager_.get(), nullptr);
78 window_tree_client->ConnectAsWindowManager(connector);
79
80 InitWindowManager(window_tree_client);
144 } 81 }
145 82
146 bool WindowManagerApplication::AcceptConnection(shell::Connection* connection) { 83 bool WindowManagerApplication::AcceptConnection(shell::Connection* connection) {
147 connection->AddInterface<mojom::ShelfLayout>(this); 84 connection->AddInterface<mojom::ShelfLayout>(this);
148 connection->AddInterface<mojom::UserWindowController>(this); 85 connection->AddInterface<mojom::UserWindowController>(this);
149 connection->AddInterface<::mus::mojom::AcceleratorRegistrar>(this); 86 connection->AddInterface<::mus::mojom::AcceleratorRegistrar>(this);
150 if (connection->GetRemoteIdentity().name() == "mojo:mash_session") 87 if (connection->GetRemoteIdentity().name() == "mojo:mash_session") {
151 connection->GetInterface(&session_); 88 connection->GetInterface(&session_);
89 session_->AddScreenlockStateListener(
90 screenlock_state_listener_binding_.CreateInterfacePtrAndBind());
91 }
152 return true; 92 return true;
153 } 93 }
154 94
155 void WindowManagerApplication::Create( 95 void WindowManagerApplication::Create(
156 shell::Connection* connection, 96 shell::Connection* connection,
157 mojo::InterfaceRequest<mojom::ShelfLayout> request) { 97 mojo::InterfaceRequest<mojom::ShelfLayout> request) {
158 // TODO(msw): Handle multiple shelves (one per display). 98 // TODO(msw): Handle multiple shelves (one per display).
159 if (!root_controllers_.empty() && (*root_controllers_.begin())->root()) { 99 if (!window_manager_->GetRootWindowControllers().empty()) {
160 shelf_layout_bindings_.AddBinding(shelf_layout_.get(), std::move(request)); 100 shelf_layout_bindings_.AddBinding(shelf_layout_.get(), std::move(request));
161 } else { 101 } else {
162 shelf_layout_requests_.push_back(base::WrapUnique( 102 shelf_layout_requests_.push_back(base::WrapUnique(
163 new mojo::InterfaceRequest<mojom::ShelfLayout>(std::move(request)))); 103 new mojo::InterfaceRequest<mojom::ShelfLayout>(std::move(request))));
164 } 104 }
165 } 105 }
166 106
167 void WindowManagerApplication::Create( 107 void WindowManagerApplication::Create(
168 shell::Connection* connection, 108 shell::Connection* connection,
169 mojo::InterfaceRequest<mojom::UserWindowController> request) { 109 mojo::InterfaceRequest<mojom::UserWindowController> request) {
170 if (!root_controllers_.empty() && (*root_controllers_.begin())->root()) { 110 if (!window_manager_->GetRootWindowControllers().empty()) {
171 user_window_controller_bindings_.AddBinding(user_window_controller_.get(), 111 user_window_controller_bindings_.AddBinding(user_window_controller_.get(),
172 std::move(request)); 112 std::move(request));
173 } else { 113 } else {
174 user_window_controller_requests_.push_back(base::WrapUnique( 114 user_window_controller_requests_.push_back(base::WrapUnique(
175 new mojo::InterfaceRequest<mojom::UserWindowController>( 115 new mojo::InterfaceRequest<mojom::UserWindowController>(
176 std::move(request)))); 116 std::move(request))));
177 } 117 }
178 } 118 }
179 119
180 void WindowManagerApplication::Create( 120 void WindowManagerApplication::Create(
181 shell::Connection* connection, 121 shell::Connection* connection,
182 mojo::InterfaceRequest<::mus::mojom::AcceleratorRegistrar> request) { 122 mojo::InterfaceRequest<::mus::mojom::AcceleratorRegistrar> request) {
183 static int accelerator_registrar_count = 0; 123 static int accelerator_registrar_count = 0;
184 if (accelerator_registrar_count == std::numeric_limits<int>::max()) { 124 if (accelerator_registrar_count == std::numeric_limits<int>::max()) {
185 // Restart from zero if we have reached the limit. It is technically 125 // Restart from zero if we have reached the limit. It is technically
186 // possible to end up with multiple active registrars with the same 126 // possible to end up with multiple active registrars with the same
187 // namespace, but it is highly unlikely. In the event that multiple 127 // namespace, but it is highly unlikely. In the event that multiple
188 // registrars have the same namespace, this new registrar will be unable to 128 // registrars have the same namespace, this new registrar will be unable to
189 // install accelerators. 129 // install accelerators.
190 accelerator_registrar_count = 0; 130 accelerator_registrar_count = 0;
191 } 131 }
192 accelerator_registrars_.insert(new AcceleratorRegistrarImpl( 132 accelerator_registrars_.insert(new AcceleratorRegistrarImpl(
193 this, ++accelerator_registrar_count, std::move(request), 133 window_manager_.get(), ++accelerator_registrar_count, std::move(request),
194 base::Bind(&WindowManagerApplication::OnAcceleratorRegistrarDestroyed, 134 base::Bind(&WindowManagerApplication::OnAcceleratorRegistrarDestroyed,
195 base::Unretained(this)))); 135 base::Unretained(this))));
196 } 136 }
197 137
198 void WindowManagerApplication::CreateWindowManager( 138 void WindowManagerApplication::ScreenlockStateChanged(bool locked) {
199 ::mus::mojom::DisplayPtr display, 139 window_manager_->SetScreenLocked(locked);
200 mojo::InterfaceRequest<::mus::mojom::WindowTreeClient> client_request) { 140 }
201 AddRootWindowController(RootWindowController::CreateFromDisplay( 141
202 this, std::move(display), std::move(client_request))); 142 void WindowManagerApplication::OnRootWindowControllerAdded(
143 RootWindowController* controller) {
144 if (user_window_controller_)
145 return;
146
147 // TODO(sky): |shelf_layout_| and |user_window_controller_| should really
148 // be owned by WindowManager and/or RootWindowController. But this code is
149 // temporary while migrating away from sysui.
150
151 shelf_layout_.reset(new ShelfLayoutImpl);
152 user_window_controller_.reset(new UserWindowControllerImpl());
153
154 // TODO(msw): figure out if this should be per display, or global.
155 user_window_controller_->Initialize(controller);
156 for (auto& request : user_window_controller_requests_)
157 user_window_controller_bindings_.AddBinding(user_window_controller_.get(),
158 std::move(*request));
159 user_window_controller_requests_.clear();
160
161 // TODO(msw): figure out if this should be per display, or global.
162 shelf_layout_->Initialize(controller);
163 for (auto& request : shelf_layout_requests_)
164 shelf_layout_bindings_.AddBinding(shelf_layout_.get(), std::move(*request));
165 shelf_layout_requests_.clear();
166 }
167
168 void WindowManagerApplication::OnWillDestroyRootWindowController(
169 RootWindowController* controller) {
170 // TODO(msw): this isn't right, ownership should belong in WindowManager
171 // and/or RootWindowController. But this is temporary until we get rid of
172 // sysui.
173 shelf_layout_.reset();
174 user_window_controller_.reset();
203 } 175 }
204 176
205 } // namespace mus 177 } // namespace mus
206 } // namespace ash 178 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/window_manager_application.h ('k') | components/mus/demo/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698