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

Side by Side Diff: components/mus/ws/connection_manager.cc

Issue 1750143002: Changes ownership of WindowTreeHostConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 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 | « components/mus/ws/connection_manager.h ('k') | components/mus/ws/window_tree_host_connection.h » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/mus/ws/connection_manager.h" 5 #include "components/mus/ws/connection_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "components/mus/ws/client_connection.h" 9 #include "components/mus/ws/client_connection.h"
10 #include "components/mus/ws/connection_manager_delegate.h" 10 #include "components/mus/ws/connection_manager_delegate.h"
(...skipping 20 matching lines...) Expand all
31 next_connection_id_(1), 31 next_connection_id_(1),
32 next_host_id_(0), 32 next_host_id_(0),
33 current_operation_(nullptr), 33 current_operation_(nullptr),
34 in_destructor_(false), 34 in_destructor_(false),
35 next_wm_change_id_(0), 35 next_wm_change_id_(0),
36 got_valid_frame_decorations_(false) {} 36 got_valid_frame_decorations_(false) {}
37 37
38 ConnectionManager::~ConnectionManager() { 38 ConnectionManager::~ConnectionManager() {
39 in_destructor_ = true; 39 in_destructor_ = true;
40 40
41 // Copy the HostConnectionMap because it will be mutated as the connections 41 // DestroyHost() removes from |hosts_| and deletes the WindowTreeHostImpl.
42 // are closed. 42 while (!hosts_.empty())
43 HostConnectionMap host_connection_map(host_connection_map_); 43 DestroyHost(*hosts_.begin());
44 for (auto& pair : host_connection_map) 44 DCHECK(hosts_.empty());
45 pair.second->CloseConnection();
46 45
47 STLDeleteValues(&connection_map_); 46 STLDeleteValues(&connection_map_);
48 // All the connections should have been destroyed. 47 // All the connections should have been destroyed.
49 DCHECK(host_connection_map_.empty());
50 DCHECK(connection_map_.empty()); 48 DCHECK(connection_map_.empty());
51 } 49 }
52 50
53 void ConnectionManager::AddHost(WindowTreeHostConnection* host_connection) { 51 void ConnectionManager::AddHost(WindowTreeHostImpl* host) {
54 DCHECK_EQ(0u, 52 DCHECK_EQ(0u, pending_hosts_.count(host));
55 host_connection_map_.count(host_connection->window_tree_host())); 53 pending_hosts_.insert(host);
56 const bool is_first_connection = host_connection_map_.empty(); 54 }
57 host_connection_map_[host_connection->window_tree_host()] = host_connection; 55
58 if (is_first_connection) 56 void ConnectionManager::DestroyHost(WindowTreeHostImpl* host) {
59 delegate_->OnFirstRootConnectionCreated(); 57 DCHECK(hosts_.count(host));
58 hosts_.erase(host);
59 delete host;
60 } 60 }
61 61
62 ServerWindow* ConnectionManager::CreateServerWindow( 62 ServerWindow* ConnectionManager::CreateServerWindow(
63 const WindowId& id, 63 const WindowId& id,
64 const std::map<std::string, std::vector<uint8_t>>& properties) { 64 const std::map<std::string, std::vector<uint8_t>>& properties) {
65 ServerWindow* window = new ServerWindow(this, id, properties); 65 ServerWindow* window = new ServerWindow(this, id, properties);
66 window->AddObserver(this); 66 window->AddObserver(this);
67 return window; 67 return window;
68 } 68 }
69 69
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 for (uint32_t id : to_remove) 115 for (uint32_t id : to_remove)
116 in_flight_wm_change_map_.erase(id); 116 in_flight_wm_change_map_.erase(id);
117 } 117 }
118 118
119 ClientConnection* ConnectionManager::GetClientConnection( 119 ClientConnection* ConnectionManager::GetClientConnection(
120 WindowTreeImpl* window_tree) { 120 WindowTreeImpl* window_tree) {
121 return connection_map_[window_tree->id()]; 121 return connection_map_[window_tree->id()];
122 } 122 }
123 123
124 void ConnectionManager::OnHostConnectionClosed( 124 void ConnectionManager::OnHostConnectionClosed(WindowTreeHostImpl* host) {
125 WindowTreeHostConnection* connection) { 125 if (pending_hosts_.count(host)) {
126 auto it = host_connection_map_.find(connection->window_tree_host()); 126 pending_hosts_.erase(host);
127 DCHECK(it != host_connection_map_.end()); 127 delete host;
128 return;
129 }
130 auto it = hosts_.find(host);
131 DCHECK(it != hosts_.end());
128 132
129 // Get the ClientConnection by WindowTreeImpl ID. 133 // Get the ClientConnection by WindowTreeImpl ID.
130 ConnectionMap::iterator service_connection_it = 134 ConnectionMap::iterator service_connection_it =
131 connection_map_.find(it->first->GetWindowTree()->id()); 135 connection_map_.find(host->GetWindowTree()->id());
132 DCHECK(service_connection_it != connection_map_.end()); 136 DCHECK(service_connection_it != connection_map_.end());
133 137
138 scoped_ptr<WindowTreeHostImpl> host_owner(*it);
139 hosts_.erase(it);
140
134 // Tear down the associated WindowTree connection. 141 // Tear down the associated WindowTree connection.
135 // TODO(fsamuel): I don't think this is quite right, we should tear down all 142 // TODO(fsamuel): I don't think this is quite right, we should tear down all
136 // connections within the root's viewport. We should probably employ an 143 // connections within the root's viewport. We should probably employ an
137 // observer pattern to do this. Each WindowTreeImpl should track its 144 // observer pattern to do this. Each WindowTreeImpl should track its
138 // parent's lifetime. 145 // parent's lifetime.
139 host_connection_map_.erase(it);
140 OnConnectionError(service_connection_it->second); 146 OnConnectionError(service_connection_it->second);
141 147
142 for (auto& pair : connection_map_) { 148 for (auto& pair : connection_map_)
143 pair.second->service()->OnWillDestroyWindowTreeHost( 149 pair.second->service()->OnWillDestroyWindowTreeHost(host);
144 connection->window_tree_host());
145 }
146 150
147 // If we have no more roots left, let the app know so it can terminate. 151 // If we have no more roots left, let the app know so it can terminate.
148 if (!host_connection_map_.size()) 152 if (!hosts_.size() && !pending_hosts_.size())
149 delegate_->OnNoMoreRootConnections(); 153 delegate_->OnNoMoreRootConnections();
150 } 154 }
151 155
152 WindowTreeImpl* ConnectionManager::EmbedAtWindow( 156 WindowTreeImpl* ConnectionManager::EmbedAtWindow(
153 ServerWindow* root, 157 ServerWindow* root,
154 uint32_t policy_bitmask, 158 uint32_t policy_bitmask,
155 mojom::WindowTreeClientPtr client) { 159 mojom::WindowTreeClientPtr client) {
156 mojom::WindowTreePtr tree_ptr; 160 mojom::WindowTreePtr tree_ptr;
157 ClientConnection* client_connection = 161 ClientConnection* client_connection =
158 delegate_->CreateClientConnectionForEmbedAtWindow( 162 delegate_->CreateClientConnectionForEmbedAtWindow(
(...skipping 12 matching lines...) Expand all
171 connection->service()->Init(connection->client(), std::move(tree_ptr)); 175 connection->service()->Init(connection->client(), std::move(tree_ptr));
172 } 176 }
173 177
174 WindowTreeImpl* ConnectionManager::GetConnection( 178 WindowTreeImpl* ConnectionManager::GetConnection(
175 ConnectionSpecificId connection_id) { 179 ConnectionSpecificId connection_id) {
176 ConnectionMap::iterator i = connection_map_.find(connection_id); 180 ConnectionMap::iterator i = connection_map_.find(connection_id);
177 return i == connection_map_.end() ? nullptr : i->second->service(); 181 return i == connection_map_.end() ? nullptr : i->second->service();
178 } 182 }
179 183
180 ServerWindow* ConnectionManager::GetWindow(const WindowId& id) { 184 ServerWindow* ConnectionManager::GetWindow(const WindowId& id) {
181 for (auto& pair : host_connection_map_) { 185 for (WindowTreeHostImpl* host : hosts_) {
182 if (pair.first->root_window()->id() == id) 186 if (host->root_window()->id() == id)
183 return pair.first->root_window(); 187 return host->root_window();
184 } 188 }
185 WindowTreeImpl* service = GetConnection(id.connection_id); 189 WindowTreeImpl* service = GetConnection(id.connection_id);
186 return service ? service->GetWindow(id) : nullptr; 190 return service ? service->GetWindow(id) : nullptr;
187 } 191 }
188 192
189 bool ConnectionManager::IsWindowAttachedToRoot( 193 bool ConnectionManager::IsWindowAttachedToRoot(
190 const ServerWindow* window) const { 194 const ServerWindow* window) const {
191 for (auto& pair : host_connection_map_) { 195 for (WindowTreeHostImpl* host : hosts_) {
192 if (pair.first->IsWindowAttachedToRoot(window)) 196 if (host->IsWindowAttachedToRoot(window))
193 return true; 197 return true;
194 } 198 }
195 return false; 199 return false;
196 } 200 }
197 201
198 void ConnectionManager::SchedulePaint(const ServerWindow* window, 202 void ConnectionManager::SchedulePaint(const ServerWindow* window,
199 const gfx::Rect& bounds) { 203 const gfx::Rect& bounds) {
200 for (auto& pair : host_connection_map_) { 204 for (WindowTreeHostImpl* host : hosts_) {
201 if (pair.first->SchedulePaintIfInViewport(window, bounds)) 205 if (host->SchedulePaintIfInViewport(window, bounds))
202 return; 206 return;
203 } 207 }
204 } 208 }
205 209
210 void ConnectionManager::OnWindowTreeHostDisplayAvailable(
211 WindowTreeHostImpl* host) {
212 DCHECK_NE(0u, pending_hosts_.count(host));
213 DCHECK_EQ(0u, hosts_.count(host));
214 const bool is_first_connection = hosts_.empty();
215 hosts_.insert(host);
216 pending_hosts_.erase(host);
217 if (is_first_connection)
218 delegate_->OnFirstRootConnectionCreated();
219 }
220
206 void ConnectionManager::OnConnectionMessagedClient(ConnectionSpecificId id) { 221 void ConnectionManager::OnConnectionMessagedClient(ConnectionSpecificId id) {
207 if (current_operation_) 222 if (current_operation_)
208 current_operation_->MarkConnectionAsMessaged(id); 223 current_operation_->MarkConnectionAsMessaged(id);
209 } 224 }
210 225
211 bool ConnectionManager::DidConnectionMessageClient( 226 bool ConnectionManager::DidConnectionMessageClient(
212 ConnectionSpecificId id) const { 227 ConnectionSpecificId id) const {
213 return current_operation_ && current_operation_->DidMessageConnection(id); 228 return current_operation_ && current_operation_->DidMessageConnection(id);
214 } 229 }
215 230
216 mojom::ViewportMetricsPtr ConnectionManager::GetViewportMetricsForWindow( 231 mojom::ViewportMetricsPtr ConnectionManager::GetViewportMetricsForWindow(
217 const ServerWindow* window) { 232 const ServerWindow* window) {
218 WindowTreeHostImpl* host = GetWindowTreeHostByWindow(window); 233 WindowTreeHostImpl* host = GetWindowTreeHostByWindow(window);
219 if (host) 234 if (host)
220 return host->GetViewportMetrics().Clone(); 235 return host->GetViewportMetrics().Clone();
221 236
222 if (!host_connection_map_.empty()) 237 if (!hosts_.empty())
223 return host_connection_map_.begin()->first->GetViewportMetrics().Clone(); 238 return (*hosts_.begin())->GetViewportMetrics().Clone();
224 239
225 mojom::ViewportMetricsPtr metrics = mojom::ViewportMetrics::New(); 240 mojom::ViewportMetricsPtr metrics = mojom::ViewportMetrics::New();
226 metrics->size_in_pixels = mojo::Size::New(); 241 metrics->size_in_pixels = mojo::Size::New();
227 return metrics; 242 return metrics;
228 } 243 }
229 244
230 const WindowTreeImpl* ConnectionManager::GetConnectionWithRoot( 245 const WindowTreeImpl* ConnectionManager::GetConnectionWithRoot(
231 const ServerWindow* window) const { 246 const ServerWindow* window) const {
232 if (!window) 247 if (!window)
233 return nullptr; 248 return nullptr;
234 for (auto& pair : connection_map_) { 249 for (auto& pair : connection_map_) {
235 if (pair.second->service()->HasRoot(window)) 250 if (pair.second->service()->HasRoot(window))
236 return pair.second->service(); 251 return pair.second->service();
237 } 252 }
238 return nullptr; 253 return nullptr;
239 } 254 }
240 255
241 WindowTreeHostImpl* ConnectionManager::GetWindowTreeHostByWindow( 256 WindowTreeHostImpl* ConnectionManager::GetWindowTreeHostByWindow(
242 const ServerWindow* window) { 257 const ServerWindow* window) {
243 return const_cast<WindowTreeHostImpl*>( 258 return const_cast<WindowTreeHostImpl*>(
244 static_cast<const ConnectionManager*>(this) 259 static_cast<const ConnectionManager*>(this)
245 ->GetWindowTreeHostByWindow(window)); 260 ->GetWindowTreeHostByWindow(window));
246 } 261 }
247 262
248 const WindowTreeHostImpl* ConnectionManager::GetWindowTreeHostByWindow( 263 const WindowTreeHostImpl* ConnectionManager::GetWindowTreeHostByWindow(
249 const ServerWindow* window) const { 264 const ServerWindow* window) const {
250 while (window && window->parent()) 265 while (window && window->parent())
251 window = window->parent(); 266 window = window->parent();
252 for (auto& pair : host_connection_map_) { 267 for (WindowTreeHostImpl* host : hosts_) {
253 if (window == pair.first->root_window()) 268 if (window == host->root_window())
254 return pair.first; 269 return host;
255 } 270 }
256 return nullptr; 271 return nullptr;
257 } 272 }
258 273
259 WindowTreeHostImpl* ConnectionManager::GetActiveWindowTreeHost() { 274 WindowTreeHostImpl* ConnectionManager::GetActiveWindowTreeHost() {
260 return host_connection_map_.begin()->first; 275 // TODO(sky): this isn't active, but first. Make it active.
276 return hosts_.size() ? *hosts_.begin() : nullptr;
261 } 277 }
262 278
263 void ConnectionManager::AddDisplayManagerBinding( 279 void ConnectionManager::AddDisplayManagerBinding(
264 mojo::InterfaceRequest<mojom::DisplayManager> request) { 280 mojo::InterfaceRequest<mojom::DisplayManager> request) {
265 display_manager_bindings_.AddBinding(this, std::move(request)); 281 display_manager_bindings_.AddBinding(this, std::move(request));
266 } 282 }
267 283
268 void ConnectionManager::CreateWindowManagerFactoryService( 284 void ConnectionManager::CreateWindowManagerFactoryService(
269 mojo::InterfaceRequest<mojom::WindowManagerFactoryService> request) { 285 mojo::InterfaceRequest<mojom::WindowManagerFactoryService> request) {
270 if (window_manager_factory_service_) 286 if (window_manager_factory_service_)
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 481
466 void ConnectionManager::MaybeUpdateNativeCursor(ServerWindow* window) { 482 void ConnectionManager::MaybeUpdateNativeCursor(ServerWindow* window) {
467 // This can be null in unit tests. 483 // This can be null in unit tests.
468 WindowTreeHostImpl* impl = GetWindowTreeHostByWindow(window); 484 WindowTreeHostImpl* impl = GetWindowTreeHostByWindow(window);
469 if (impl) 485 if (impl)
470 impl->MaybeChangeCursorOnWindowTreeChange(); 486 impl->MaybeChangeCursorOnWindowTreeChange();
471 } 487 }
472 488
473 void ConnectionManager::CallOnDisplays( 489 void ConnectionManager::CallOnDisplays(
474 mojom::DisplayManagerObserver* observer) { 490 mojom::DisplayManagerObserver* observer) {
475 mojo::Array<mojom::DisplayPtr> displays(host_connection_map_.size()); 491 mojo::Array<mojom::DisplayPtr> displays(hosts_.size());
476 { 492 {
477 size_t i = 0; 493 size_t i = 0;
478 for (auto& pair : host_connection_map_) { 494 // TODO(sky): need ordering!
479 displays[i] = DisplayForHost(pair.first); 495 for (WindowTreeHostImpl* host : hosts_) {
496 displays[i] = DisplayForHost(host);
480 ++i; 497 ++i;
481 } 498 }
482 } 499 }
483 observer->OnDisplays(std::move(displays)); 500 observer->OnDisplays(std::move(displays));
484 } 501 }
485 502
486 void ConnectionManager::CallOnDisplayChanged( 503 void ConnectionManager::CallOnDisplayChanged(
487 mojom::DisplayManagerObserver* observer, 504 mojom::DisplayManagerObserver* observer,
488 WindowTreeHostImpl* host) { 505 WindowTreeHostImpl* host) {
489 mojo::Array<mojom::DisplayPtr> displays(1); 506 mojo::Array<mojom::DisplayPtr> displays(1);
490 displays[0] = DisplayForHost(host); 507 displays[0] = DisplayForHost(host);
491 display_manager_observers_.ForAllPtrs( 508 display_manager_observers_.ForAllPtrs(
492 [&displays](mojom::DisplayManagerObserver* observer) { 509 [&displays](mojom::DisplayManagerObserver* observer) {
493 observer->OnDisplaysChanged(displays.Clone()); 510 observer->OnDisplaysChanged(displays.Clone());
494 }); 511 });
495 } 512 }
496 513
497 mojom::DisplayPtr ConnectionManager::DisplayForHost(WindowTreeHostImpl* host) { 514 mojom::DisplayPtr ConnectionManager::DisplayForHost(WindowTreeHostImpl* host) {
498 size_t i = 0; 515 size_t i = 0;
499 int next_x = 0; 516 int next_x = 0;
500 for (auto& pair : host_connection_map_) { 517 for (WindowTreeHostImpl* host2 : hosts_) {
501 const ServerWindow* root = host->root_window(); 518 const ServerWindow* root = host->root_window();
502 if (pair.first == host) { 519 if (host == host2) {
503 mojom::DisplayPtr display = mojom::Display::New(); 520 mojom::DisplayPtr display = mojom::Display::New();
504 display = mojom::Display::New(); 521 display = mojom::Display::New();
505 display->id = host->id(); 522 display->id = host->id();
506 display->bounds = mojo::Rect::New(); 523 display->bounds = mojo::Rect::New();
507 display->bounds->x = next_x; 524 display->bounds->x = next_x;
508 display->bounds->y = 0; 525 display->bounds->y = 0;
509 display->bounds->width = root->bounds().size().width(); 526 display->bounds->width = root->bounds().size().width();
510 display->bounds->height = root->bounds().size().height(); 527 display->bounds->height = root->bounds().size().height();
511 // TODO(sky): window manager needs an API to set the work area. 528 // TODO(sky): window manager needs an API to set the work area.
512 display->work_area = display->bounds.Clone(); 529 display->work_area = display->bounds.Clone();
(...skipping 24 matching lines...) Expand all
537 SchedulePaint(window, gfx::Rect(window->bounds().size())); 554 SchedulePaint(window, gfx::Rect(window->bounds().size()));
538 } 555 }
539 556
540 const ServerWindow* ConnectionManager::GetRootWindow( 557 const ServerWindow* ConnectionManager::GetRootWindow(
541 const ServerWindow* window) const { 558 const ServerWindow* window) const {
542 const WindowTreeHostImpl* host = GetWindowTreeHostByWindow(window); 559 const WindowTreeHostImpl* host = GetWindowTreeHostByWindow(window);
543 return host ? host->root_window() : nullptr; 560 return host ? host->root_window() : nullptr;
544 } 561 }
545 562
546 void ConnectionManager::ScheduleSurfaceDestruction(ServerWindow* window) { 563 void ConnectionManager::ScheduleSurfaceDestruction(ServerWindow* window) {
547 for (auto& pair : host_connection_map_) { 564 for (WindowTreeHostImpl* host : hosts_) {
548 if (pair.first->root_window()->Contains(window)) { 565 if (host->root_window()->Contains(window)) {
549 pair.first->ScheduleSurfaceDestruction(window); 566 host->ScheduleSurfaceDestruction(window);
550 break; 567 break;
551 } 568 }
552 } 569 }
553 } 570 }
554 571
555 ServerWindow* ConnectionManager::FindWindowForSurface( 572 ServerWindow* ConnectionManager::FindWindowForSurface(
556 const ServerWindow* ancestor, 573 const ServerWindow* ancestor,
557 mojom::SurfaceType surface_type, 574 mojom::SurfaceType surface_type,
558 const ClientWindowId& client_window_id) { 575 const ClientWindowId& client_window_id) {
559 WindowTreeImpl* window_tree; 576 WindowTreeImpl* window_tree;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 if (!got_valid_frame_decorations_) { 727 if (!got_valid_frame_decorations_) {
711 display_manager_observers_.AddInterfacePtr(std::move(observer)); 728 display_manager_observers_.AddInterfacePtr(std::move(observer));
712 return; 729 return;
713 } 730 }
714 CallOnDisplays(observer.get()); 731 CallOnDisplays(observer.get());
715 display_manager_observers_.AddInterfacePtr(std::move(observer)); 732 display_manager_observers_.AddInterfacePtr(std::move(observer));
716 } 733 }
717 734
718 } // namespace ws 735 } // namespace ws
719 } // namespace mus 736 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/connection_manager.h ('k') | components/mus/ws/window_tree_host_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698