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

Side by Side Diff: components/mus/ws/window_server.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 | « components/mus/ws/window_server.h ('k') | components/mus/ws/window_tree.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/window_server.h" 5 #include "components/mus/ws/window_server.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" 13 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h"
14 #include "components/mus/ws/display.h" 14 #include "components/mus/ws/display.h"
15 #include "components/mus/ws/display_binding.h" 15 #include "components/mus/ws/display_binding.h"
16 #include "components/mus/ws/display_manager.h" 16 #include "components/mus/ws/display_manager.h"
17 #include "components/mus/ws/operation.h" 17 #include "components/mus/ws/operation.h"
18 #include "components/mus/ws/server_window.h" 18 #include "components/mus/ws/server_window.h"
19 #include "components/mus/ws/window_coordinate_conversions.h" 19 #include "components/mus/ws/window_coordinate_conversions.h"
20 #include "components/mus/ws/window_manager_access_policy.h" 20 #include "components/mus/ws/window_manager_access_policy.h"
21 #include "components/mus/ws/window_manager_factory_service.h"
22 #include "components/mus/ws/window_manager_state.h" 21 #include "components/mus/ws/window_manager_state.h"
22 #include "components/mus/ws/window_manager_window_tree_factory.h"
23 #include "components/mus/ws/window_server_delegate.h" 23 #include "components/mus/ws/window_server_delegate.h"
24 #include "components/mus/ws/window_tree.h" 24 #include "components/mus/ws/window_tree.h"
25 #include "components/mus/ws/window_tree_binding.h" 25 #include "components/mus/ws/window_tree_binding.h"
26 #include "services/shell/public/cpp/connection.h" 26 #include "services/shell/public/cpp/connection.h"
27 #include "ui/gfx/geometry/size_conversions.h" 27 #include "ui/gfx/geometry/size_conversions.h"
28 28
29 namespace mus { 29 namespace mus {
30 namespace ws { 30 namespace ws {
31 31
32 WindowServer::WindowServer( 32 WindowServer::WindowServer(
33 WindowServerDelegate* delegate, 33 WindowServerDelegate* delegate,
34 const scoped_refptr<mus::SurfacesState>& surfaces_state) 34 const scoped_refptr<mus::SurfacesState>& surfaces_state)
35 : delegate_(delegate), 35 : delegate_(delegate),
36 surfaces_state_(surfaces_state), 36 surfaces_state_(surfaces_state),
37 next_client_id_(1), 37 next_client_id_(1),
38 display_manager_(new DisplayManager(this)), 38 display_manager_(new DisplayManager(this)),
39 current_operation_(nullptr), 39 current_operation_(nullptr),
40 in_destructor_(false), 40 in_destructor_(false),
41 next_wm_change_id_(0), 41 next_wm_change_id_(0),
42 window_manager_factory_registry_(this, &user_id_tracker_) {} 42 window_manager_window_tree_factory_set_(this, &user_id_tracker_) {}
43 43
44 WindowServer::~WindowServer() { 44 WindowServer::~WindowServer() {
45 in_destructor_ = true; 45 in_destructor_ = true;
46 46
47 // Destroys the window trees results in querying for the display. Tear down 47 // Destroys the window trees results in querying for the display. Tear down
48 // the displays first so that the trees are notified of the display going 48 // the displays first so that the trees are notified of the display going
49 // away while the display is still valid. 49 // away while the display is still valid.
50 display_manager_->DestroyAllDisplays(); 50 display_manager_->DestroyAllDisplays();
51 51
52 while (!tree_map_.empty()) 52 while (!tree_map_.empty())
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 if (!binding) { 87 if (!binding) {
88 binding.reset(new ws::DefaultWindowTreeBinding( 88 binding.reset(new ws::DefaultWindowTreeBinding(
89 tree, this, std::move(window_tree_request), std::move(client))); 89 tree, this, std::move(window_tree_request), std::move(client)));
90 } 90 }
91 91
92 AddTree(std::move(tree_ptr), std::move(binding), std::move(window_tree_ptr)); 92 AddTree(std::move(tree_ptr), std::move(binding), std::move(window_tree_ptr));
93 OnTreeMessagedClient(tree->id()); 93 OnTreeMessagedClient(tree->id());
94 return tree; 94 return tree;
95 } 95 }
96 96
97 WindowTree* WindowServer::AddTree(std::unique_ptr<WindowTree> tree_impl_ptr, 97 void WindowServer::AddTree(std::unique_ptr<WindowTree> tree_impl_ptr,
98 std::unique_ptr<WindowTreeBinding> binding, 98 std::unique_ptr<WindowTreeBinding> binding,
99 mojom::WindowTreePtr tree_ptr) { 99 mojom::WindowTreePtr tree_ptr) {
100 CHECK_EQ(0u, tree_map_.count(tree_impl_ptr->id())); 100 CHECK_EQ(0u, tree_map_.count(tree_impl_ptr->id()));
101 WindowTree* tree = tree_impl_ptr.get(); 101 WindowTree* tree = tree_impl_ptr.get();
102 tree_map_[tree->id()] = std::move(tree_impl_ptr); 102 tree_map_[tree->id()] = std::move(tree_impl_ptr);
103 tree->Init(std::move(binding), std::move(tree_ptr)); 103 tree->Init(std::move(binding), std::move(tree_ptr));
104 return tree;
105 } 104 }
106 105
107 WindowTree* WindowServer::CreateTreeForWindowManager( 106 WindowTree* WindowServer::CreateTreeForWindowManager(
108 Display* display, 107 const UserId& user_id,
109 mojom::WindowManagerFactory* factory, 108 mojom::WindowTreeRequest window_tree_request,
110 ServerWindow* root, 109 mojom::WindowTreeClientPtr window_tree_client) {
111 const UserId& user_id) { 110 std::unique_ptr<WindowTree> window_tree(new WindowTree(
112 mojom::DisplayPtr display_ptr = display->ToMojomDisplay(); 111 this, user_id, nullptr, base::WrapUnique(new WindowManagerAccessPolicy)));
113 mojom::WindowTreeClientPtr tree_client; 112 std::unique_ptr<WindowTreeBinding> window_tree_binding =
114 factory->CreateWindowManager(std::move(display_ptr), GetProxy(&tree_client));
115 std::unique_ptr<WindowTree> tree_ptr(new WindowTree(
116 this, user_id, root, base::WrapUnique(new WindowManagerAccessPolicy)));
117 WindowTree* tree = tree_ptr.get();
118 mojom::WindowTreePtr window_tree_ptr;
119 mojom::WindowTreeRequest tree_request;
120 std::unique_ptr<WindowTreeBinding> binding =
121 delegate_->CreateWindowTreeBinding( 113 delegate_->CreateWindowTreeBinding(
122 WindowServerDelegate::BindingType::WINDOW_MANAGER, this, tree, 114 WindowServerDelegate::BindingType::WINDOW_MANAGER, this,
123 &tree_request, &tree_client); 115 window_tree.get(), &window_tree_request, &window_tree_client);
124 if (!binding) { 116 if (!window_tree_binding) {
125 DefaultWindowTreeBinding* default_binding = 117 window_tree_binding.reset(new DefaultWindowTreeBinding(
126 new DefaultWindowTreeBinding(tree_ptr.get(), std::move(tree_client)); 118 window_tree.get(), this, std::move(window_tree_request),
127 binding.reset(default_binding); 119 std::move(window_tree_client)));
128 window_tree_ptr = default_binding->CreateInterfacePtrAndBind();
129 } 120 }
130 AddTree(std::move(tree_ptr), std::move(binding), std::move(window_tree_ptr)); 121 WindowTree* window_tree_ptr = window_tree.get();
131 tree->ConfigureWindowManager(); 122 AddTree(std::move(window_tree), std::move(window_tree_binding), nullptr);
132 return tree; 123 window_tree_ptr->ConfigureWindowManager();
124 return window_tree_ptr;
133 } 125 }
134 126
135 void WindowServer::DestroyTree(WindowTree* tree) { 127 void WindowServer::DestroyTree(WindowTree* tree) {
136 std::unique_ptr<WindowTree> tree_ptr; 128 std::unique_ptr<WindowTree> tree_ptr;
137 { 129 {
138 auto iter = tree_map_.find(tree->id()); 130 auto iter = tree_map_.find(tree->id());
139 DCHECK(iter != tree_map_.end()); 131 DCHECK(iter != tree_map_.end());
140 tree_ptr = std::move(iter->second); 132 tree_ptr = std::move(iter->second);
141 tree_map_.erase(iter); 133 tree_map_.erase(iter);
142 } 134 }
143 135
144 // Notify remaining connections so that they can cleanup. 136 // Notify remaining connections so that they can cleanup.
145 for (auto& pair : tree_map_) 137 for (auto& pair : tree_map_)
146 pair.second->OnWindowDestroyingTreeImpl(tree); 138 pair.second->OnWindowDestroyingTreeImpl(tree);
147 139
148 // Notify the hosts, taking care to only notify each host once. 140 // Notify the hosts, taking care to only notify each host once.
149 std::set<Display*> displays_notified; 141 std::set<Display*> displays_notified;
150 for (auto* root : tree->roots()) { 142 for (auto* root : tree->roots()) {
151 // WindowTree holds its roots as a const, which is right as WindowTree 143 // WindowTree holds its roots as a const, which is right as WindowTree
152 // doesn't need to modify the window. OTOH we do. We could look up the 144 // doesn't need to modify the window. OTOH we do. We could look up the
153 // window using the id to get non-const version, but instead we cast. 145 // window using the id to get non-const version, but instead we cast.
154 Display* display = 146 Display* display =
155 display_manager_->GetDisplayContaining(const_cast<ServerWindow*>(root)); 147 display_manager_->GetDisplayContaining(const_cast<ServerWindow*>(root));
156 if (display && displays_notified.count(display) == 0) { 148 if (display && displays_notified.count(display) == 0) {
157 display->OnWillDestroyTree(tree); 149 display->OnWillDestroyTree(tree);
158 displays_notified.insert(display); 150 displays_notified.insert(display);
159 } 151 }
160 } 152 }
161 153
154 window_manager_window_tree_factory_set_.DeleteFactoryAssociatedWithTree(tree);
155
162 // Remove any requests from the client that resulted in a call to the window 156 // Remove any requests from the client that resulted in a call to the window
163 // manager and we haven't gotten a response back yet. 157 // manager and we haven't gotten a response back yet.
164 std::set<uint32_t> to_remove; 158 std::set<uint32_t> to_remove;
165 for (auto& pair : in_flight_wm_change_map_) { 159 for (auto& pair : in_flight_wm_change_map_) {
166 if (pair.second.client_id == tree->id()) 160 if (pair.second.client_id == tree->id())
167 to_remove.insert(pair.first); 161 to_remove.insert(pair.first);
168 } 162 }
169 for (uint32_t id : to_remove) 163 for (uint32_t id : to_remove)
170 in_flight_wm_change_map_.erase(id); 164 in_flight_wm_change_map_.erase(id);
171 } 165 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 const ServerWindow* window) const { 211 const ServerWindow* window) const {
218 if (!window) 212 if (!window)
219 return nullptr; 213 return nullptr;
220 for (auto& pair : tree_map_) { 214 for (auto& pair : tree_map_) {
221 if (pair.second->HasRoot(window)) 215 if (pair.second->HasRoot(window))
222 return pair.second.get(); 216 return pair.second.get();
223 } 217 }
224 return nullptr; 218 return nullptr;
225 } 219 }
226 220
227 void WindowServer::OnFirstWindowManagerFactorySet() { 221 void WindowServer::OnFirstWindowManagerWindowTreeFactoryReady() {
228 if (display_manager_->has_active_or_pending_displays()) 222 if (display_manager_->has_active_or_pending_displays())
229 return; 223 return;
230 224
231 // We've been supplied a WindowManagerFactory and no displays have been 225 // We've been supplied a WindowManagerFactory and no displays have been
232 // created yet. Treat this as a signal to create a Display. 226 // created yet. Treat this as a signal to create a Display.
233 // TODO(sky): we need a better way to determine this, most likely a switch. 227 // TODO(sky): we need a better way to determine this, most likely a switch.
234 delegate_->CreateDefaultDisplays(); 228 delegate_->CreateDefaultDisplays();
235 } 229 }
236 230
237 bool WindowServer::SetFocusedWindow(ServerWindow* window) { 231 bool WindowServer::SetFocusedWindow(ServerWindow* window) {
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 // If we're deleting a window, then this is a superfluous message. 640 // If we're deleting a window, then this is a superfluous message.
647 if (current_operation_type() == OperationType::DELETE_WINDOW) 641 if (current_operation_type() == OperationType::DELETE_WINDOW)
648 return; 642 return;
649 for (auto& pair : tree_map_) { 643 for (auto& pair : tree_map_) {
650 pair.second->ProcessTransientWindowRemoved(window, transient_child, 644 pair.second->ProcessTransientWindowRemoved(window, transient_child,
651 IsOperationSource(pair.first)); 645 IsOperationSource(pair.first));
652 } 646 }
653 } 647 }
654 648
655 void WindowServer::OnFirstDisplayReady() { 649 void WindowServer::OnFirstDisplayReady() {
650 // TODO(sky): remove this, temporary until window manager state made
651 // global.
652 if (!created_one_display_) {
653 created_one_display_ = true;
654 std::vector<WindowManagerWindowTreeFactory*> factories =
655 window_manager_window_tree_factory_set_.GetFactories();
656 for (WindowManagerWindowTreeFactory* factory : factories)
657 factory->BindPendingRequest();
658 }
656 delegate_->OnFirstDisplayReady(); 659 delegate_->OnFirstDisplayReady();
657 } 660 }
658 661
659 void WindowServer::OnNoMoreDisplays() { 662 void WindowServer::OnNoMoreDisplays() {
660 delegate_->OnNoMoreDisplays(); 663 delegate_->OnNoMoreDisplays();
661 } 664 }
662 665
663 } // namespace ws 666 } // namespace ws
664 } // namespace mus 667 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/window_server.h ('k') | components/mus/ws/window_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698