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

Side by Side Diff: services/ui/public/cpp/window_tree_client.cc

Issue 2301353003: Changes ownership of WindowTreeClient (Closed)
Patch Set: Created 4 years, 3 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 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 "services/ui/public/cpp/window_tree_client.h" 5 #include "services/ui/public/cpp/window_tree_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 11 matching lines...) Expand all
22 #include "services/ui/public/cpp/window_tracker.h" 22 #include "services/ui/public/cpp/window_tracker.h"
23 #include "services/ui/public/cpp/window_tree_client_delegate.h" 23 #include "services/ui/public/cpp/window_tree_client_delegate.h"
24 #include "services/ui/public/cpp/window_tree_client_observer.h" 24 #include "services/ui/public/cpp/window_tree_client_observer.h"
25 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h" 25 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h"
26 #include "ui/events/event.h" 26 #include "ui/events/event.h"
27 #include "ui/gfx/geometry/insets.h" 27 #include "ui/gfx/geometry/insets.h"
28 #include "ui/gfx/geometry/size.h" 28 #include "ui/gfx/geometry/size.h"
29 29
30 namespace ui { 30 namespace ui {
31 31
32 void DeleteWindowTreeClient(WindowTreeClient* client) { delete client; }
33
34 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { 32 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) {
35 return (client_id << 16) | local_id; 33 return (client_id << 16) | local_id;
36 } 34 }
37 35
38 Id server_id(Window* window) { 36 Id server_id(Window* window) {
39 return WindowPrivate(window).server_id(); 37 return WindowPrivate(window).server_id();
40 } 38 }
41 39
42 // Helper called to construct a local window object from transport data. 40 // Helper called to construct a local window object from transport data.
43 Window* AddWindowToClient(WindowTreeClient* client, 41 Window* AddWindowToClient(WindowTreeClient* client,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 mojo::InterfaceRequest<mojom::WindowTreeClient> request) 88 mojo::InterfaceRequest<mojom::WindowTreeClient> request)
91 : client_id_(0), 89 : client_id_(0),
92 next_window_id_(1), 90 next_window_id_(1),
93 next_change_id_(1), 91 next_change_id_(1),
94 delegate_(delegate), 92 delegate_(delegate),
95 window_manager_delegate_(window_manager_delegate), 93 window_manager_delegate_(window_manager_delegate),
96 capture_window_(nullptr), 94 capture_window_(nullptr),
97 focused_window_(nullptr), 95 focused_window_(nullptr),
98 binding_(this), 96 binding_(this),
99 tree_(nullptr), 97 tree_(nullptr),
100 delete_on_no_roots_(!window_manager_delegate),
101 in_destructor_(false), 98 in_destructor_(false),
102 weak_factory_(this) { 99 weak_factory_(this) {
103 // Allow for a null request in tests. 100 // Allow for a null request in tests.
104 if (request.is_pending()) 101 if (request.is_pending())
105 binding_.Bind(std::move(request)); 102 binding_.Bind(std::move(request));
106 if (window_manager_delegate) 103 if (window_manager_delegate)
107 window_manager_delegate->SetWindowManagerClient(this); 104 window_manager_delegate->SetWindowManagerClient(this);
108 } 105 }
109 106
110 WindowTreeClient::~WindowTreeClient() { 107 WindowTreeClient::~WindowTreeClient() {
(...skipping 16 matching lines...) Expand all
127 124
128 // Delete the non-owned windows last. In the typical case these are roots. The 125 // Delete the non-owned windows last. In the typical case these are roots. The
129 // exception is the window manager and embed roots, which may know about 126 // exception is the window manager and embed roots, which may know about
130 // other random windows that it doesn't own. 127 // other random windows that it doesn't own.
131 // NOTE: we manually delete as we're a friend. 128 // NOTE: we manually delete as we're a friend.
132 while (!tracker.windows().empty()) 129 while (!tracker.windows().empty())
133 delete tracker.windows().front(); 130 delete tracker.windows().front();
134 131
135 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_, 132 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_,
136 OnDidDestroyClient(this)); 133 OnDidDestroyClient(this));
137
138 delegate_->OnDidDestroyClient(this);
139 } 134 }
140 135
141 void WindowTreeClient::ConnectViaWindowTreeFactory( 136 void WindowTreeClient::ConnectViaWindowTreeFactory(
142 shell::Connector* connector) { 137 shell::Connector* connector) {
143 // Clients created with no root shouldn't delete automatically.
144 delete_on_no_roots_ = false;
145
146 // The client id doesn't really matter, we use 101 purely for debugging. 138 // The client id doesn't really matter, we use 101 purely for debugging.
147 client_id_ = 101; 139 client_id_ = 101;
148 140
149 mojom::WindowTreeFactoryPtr factory; 141 mojom::WindowTreeFactoryPtr factory;
150 connector->ConnectToInterface("mojo:ui", &factory); 142 connector->ConnectToInterface("mojo:ui", &factory);
151 mojom::WindowTreePtr window_tree; 143 mojom::WindowTreePtr window_tree;
152 factory->CreateWindowTree(GetProxy(&window_tree), 144 factory->CreateWindowTree(GetProxy(&window_tree),
153 binding_.CreateInterfacePtrAndBind()); 145 binding_.CreateInterfacePtrAndBind());
154 SetWindowTree(std::move(window_tree)); 146 SetWindowTree(std::move(window_tree));
155 } 147 }
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 431
440 // Remove any InFlightChanges associated with the window. 432 // Remove any InFlightChanges associated with the window.
441 std::set<uint32_t> in_flight_change_ids_to_remove; 433 std::set<uint32_t> in_flight_change_ids_to_remove;
442 for (const auto& pair : in_flight_map_) { 434 for (const auto& pair : in_flight_map_) {
443 if (pair.second->window() == window) 435 if (pair.second->window() == window)
444 in_flight_change_ids_to_remove.insert(pair.first); 436 in_flight_change_ids_to_remove.insert(pair.first);
445 } 437 }
446 for (auto change_id : in_flight_change_ids_to_remove) 438 for (auto change_id : in_flight_change_ids_to_remove)
447 in_flight_map_.erase(change_id); 439 in_flight_map_.erase(change_id);
448 440
449 if (roots_.erase(window) > 0 && roots_.empty() && delete_on_no_roots_ && 441 const bool was_root = roots_.erase(window) > 0;
450 !in_destructor_) { 442 if (!in_destructor_ && was_root && roots_.empty() && is_from_embed_)
451 delete this; 443 delegate_->OnEmbedRootDestroyed(window);
452 }
453 } 444 }
454 445
455 Window* WindowTreeClient::GetWindowByServerId(Id id) { 446 Window* WindowTreeClient::GetWindowByServerId(Id id) {
456 IdToWindowMap::const_iterator it = windows_.find(id); 447 IdToWindowMap::const_iterator it = windows_.find(id);
457 return it != windows_.end() ? it->second : NULL; 448 return it != windows_.end() ? it->second : NULL;
458 } 449 }
459 450
460 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching( 451 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching(
461 const InFlightChange& change) { 452 const InFlightChange& change) {
462 for (const auto& pair : in_flight_map_) { 453 for (const auto& pair : in_flight_map_) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 tree_ptr_.set_connection_error_handler(base::Bind( 521 tree_ptr_.set_connection_error_handler(base::Bind(
531 &WindowTreeClient::OnConnectionLost, weak_factory_.GetWeakPtr())); 522 &WindowTreeClient::OnConnectionLost, weak_factory_.GetWeakPtr()));
532 523
533 if (window_manager_delegate_) { 524 if (window_manager_delegate_) {
534 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, 525 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_,
535 tree_ptr_.associated_group())); 526 tree_ptr_.associated_group()));
536 } 527 }
537 } 528 }
538 529
539 void WindowTreeClient::OnConnectionLost() { 530 void WindowTreeClient::OnConnectionLost() {
540 delete this; 531 delegate_->OnLostConnection(this);
541 } 532 }
542 533
543 void WindowTreeClient::OnEmbedImpl(mojom::WindowTree* window_tree, 534 void WindowTreeClient::OnEmbedImpl(mojom::WindowTree* window_tree,
544 ClientSpecificId client_id, 535 ClientSpecificId client_id,
545 mojom::WindowDataPtr root_data, 536 mojom::WindowDataPtr root_data,
546 int64_t display_id, 537 int64_t display_id,
547 Id focused_window_id, 538 Id focused_window_id,
548 bool drawn) { 539 bool drawn) {
549 // WARNING: this is only called if WindowTreeClient was created as the 540 // WARNING: this is only called if WindowTreeClient was created as the
550 // result of an embedding. 541 // result of an embedding.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 585
595 if (change_id == current_wm_move_loop_change_) { 586 if (change_id == current_wm_move_loop_change_) {
596 current_wm_move_loop_change_ = 0; 587 current_wm_move_loop_change_ = 0;
597 current_wm_move_loop_window_id_ = 0; 588 current_wm_move_loop_window_id_ = 0;
598 } 589 }
599 } 590 }
600 591
601 //////////////////////////////////////////////////////////////////////////////// 592 ////////////////////////////////////////////////////////////////////////////////
602 // WindowTreeClient, WindowTreeClient implementation: 593 // WindowTreeClient, WindowTreeClient implementation:
603 594
604 void WindowTreeClient::SetDeleteOnNoRoots(bool value) {
605 delete_on_no_roots_ = value;
606 }
607
608 const std::set<Window*>& WindowTreeClient::GetRoots() { 595 const std::set<Window*>& WindowTreeClient::GetRoots() {
609 return roots_; 596 return roots_;
610 } 597 }
611 598
612 Window* WindowTreeClient::GetFocusedWindow() { 599 Window* WindowTreeClient::GetFocusedWindow() {
613 return focused_window_; 600 return focused_window_;
614 } 601 }
615 602
616 void WindowTreeClient::ClearFocus() { 603 void WindowTreeClient::ClearFocus() {
617 if (!focused_window_) 604 if (!focused_window_)
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 observers_.RemoveObserver(observer); 698 observers_.RemoveObserver(observer);
712 } 699 }
713 700
714 void WindowTreeClient::SetCanAcceptEvents(Id window_id, 701 void WindowTreeClient::SetCanAcceptEvents(Id window_id,
715 bool can_accept_events) { 702 bool can_accept_events) {
716 DCHECK(tree_); 703 DCHECK(tree_);
717 tree_->SetCanAcceptEvents(window_id, can_accept_events); 704 tree_->SetCanAcceptEvents(window_id, can_accept_events);
718 } 705 }
719 706
720 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, 707 void WindowTreeClient::OnEmbed(ClientSpecificId client_id,
721 mojom::WindowDataPtr root_data, 708 mojom::WindowDataPtr root_data,
722 mojom::WindowTreePtr tree, 709 mojom::WindowTreePtr tree,
723 int64_t display_id, 710 int64_t display_id,
724 Id focused_window_id, 711 Id focused_window_id,
725 bool drawn) { 712 bool drawn) {
726 DCHECK(!tree_ptr_); 713 DCHECK(!tree_ptr_);
727 tree_ptr_ = std::move(tree); 714 tree_ptr_ = std::move(tree);
728 tree_ptr_.set_connection_error_handler( 715
729 base::Bind(&DeleteWindowTreeClient, this)); 716 is_from_embed_ = true;
730 717
731 if (window_manager_delegate_) { 718 if (window_manager_delegate_) {
732 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, 719 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_,
733 tree_ptr_.associated_group())); 720 tree_ptr_.associated_group()));
734 } 721 }
735 722
736 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, 723 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id,
737 focused_window_id, drawn); 724 focused_window_id, drawn);
738 } 725 }
739 726
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 Window* window, 1253 Window* window,
1267 const gfx::Vector2d& offset, 1254 const gfx::Vector2d& offset,
1268 const gfx::Insets& hit_area) { 1255 const gfx::Insets& hit_area) {
1269 if (window_manager_internal_client_) { 1256 if (window_manager_internal_client_) {
1270 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1257 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1271 server_id(window), offset.x(), offset.y(), hit_area); 1258 server_id(window), offset.x(), offset.y(), hit_area);
1272 } 1259 }
1273 } 1260 }
1274 1261
1275 } // namespace ui 1262 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698