OLD | NEW |
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 #ifndef COMPONENTS_MUS_CONNECTION_MANAGER_H_ | 5 #ifndef COMPONENTS_MUS_CONNECTION_MANAGER_H_ |
6 #define COMPONENTS_MUS_CONNECTION_MANAGER_H_ | 6 #define COMPONENTS_MUS_CONNECTION_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/timer/timer.h" | 13 #include "base/timer/timer.h" |
14 #include "components/mus/focus_controller_delegate.h" | 14 #include "components/mus/focus_controller_delegate.h" |
15 #include "components/mus/ids.h" | 15 #include "components/mus/ids.h" |
16 #include "components/mus/public/interfaces/view_tree.mojom.h" | 16 #include "components/mus/public/interfaces/view_tree.mojom.h" |
17 #include "components/mus/public/interfaces/view_tree_host.mojom.h" | 17 #include "components/mus/public/interfaces/view_tree_host.mojom.h" |
18 #include "components/mus/server_view_delegate.h" | 18 #include "components/mus/server_view_delegate.h" |
19 #include "components/mus/server_view_observer.h" | 19 #include "components/mus/server_view_observer.h" |
20 #include "components/mus/surfaces/surfaces_state.h" | 20 #include "components/mus/surfaces/surfaces_state.h" |
21 #include "components/mus/view_tree_host_impl.h" | 21 #include "components/mus/view_tree_host_impl.h" |
22 #include "mojo/converters/surfaces/custom_surface_converter.h" | 22 #include "mojo/converters/surfaces/custom_surface_converter.h" |
23 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h" | 23 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h" |
24 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" | 24 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
25 | 25 |
26 namespace view_manager { | 26 namespace mus { |
27 | 27 |
28 class ClientConnection; | 28 class ClientConnection; |
29 class ConnectionManagerDelegate; | 29 class ConnectionManagerDelegate; |
30 class ServerView; | 30 class ServerView; |
31 class ViewTreeHostConnection; | 31 class ViewTreeHostConnection; |
32 class ViewTreeImpl; | 32 class ViewTreeImpl; |
33 | 33 |
34 // ConnectionManager manages the set of connections to the ViewManager (all the | 34 // ConnectionManager manages the set of connections to the ViewManager (all the |
35 // ViewTreeImpl) as well as providing the root of the hierarchy. | 35 // ViewTreeImpl) as well as providing the root of the hierarchy. |
36 class ConnectionManager : public ServerViewDelegate, | 36 class ConnectionManager : public ServerViewDelegate, |
37 public ServerViewObserver, | 37 public ServerViewObserver, |
38 public mojo::CustomSurfaceConverter { | 38 public mojo::CustomSurfaceConverter { |
39 public: | 39 public: |
40 // Create when a ViewTreeImpl is about to make a change. Ensures clients are | 40 // Create when a ViewTreeImpl is about to make a change. Ensures clients are |
41 // notified correctly. | 41 // notified correctly. |
42 class ScopedChange { | 42 class ScopedChange { |
43 public: | 43 public: |
44 ScopedChange(ViewTreeImpl* connection, | 44 ScopedChange(ViewTreeImpl* connection, |
45 ConnectionManager* connection_manager, | 45 ConnectionManager* connection_manager, |
46 bool is_delete_view); | 46 bool is_delete_view); |
47 ~ScopedChange(); | 47 ~ScopedChange(); |
48 | 48 |
49 mojo::ConnectionSpecificId connection_id() const { return connection_id_; } | 49 ConnectionSpecificId connection_id() const { return connection_id_; } |
50 bool is_delete_view() const { return is_delete_view_; } | 50 bool is_delete_view() const { return is_delete_view_; } |
51 | 51 |
52 // Marks the connection with the specified id as having seen a message. | 52 // Marks the connection with the specified id as having seen a message. |
53 void MarkConnectionAsMessaged(mojo::ConnectionSpecificId connection_id) { | 53 void MarkConnectionAsMessaged(ConnectionSpecificId connection_id) { |
54 message_ids_.insert(connection_id); | 54 message_ids_.insert(connection_id); |
55 } | 55 } |
56 | 56 |
57 // Returns true if MarkConnectionAsMessaged(connection_id) was invoked. | 57 // Returns true if MarkConnectionAsMessaged(connection_id) was invoked. |
58 bool DidMessageConnection(mojo::ConnectionSpecificId connection_id) const { | 58 bool DidMessageConnection(ConnectionSpecificId connection_id) const { |
59 return message_ids_.count(connection_id) > 0; | 59 return message_ids_.count(connection_id) > 0; |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 ConnectionManager* connection_manager_; | 63 ConnectionManager* connection_manager_; |
64 const mojo::ConnectionSpecificId connection_id_; | 64 const ConnectionSpecificId connection_id_; |
65 const bool is_delete_view_; | 65 const bool is_delete_view_; |
66 | 66 |
67 // See description of MarkConnectionAsMessaged/DidMessageConnection. | 67 // See description of MarkConnectionAsMessaged/DidMessageConnection. |
68 std::set<mojo::ConnectionSpecificId> message_ids_; | 68 std::set<ConnectionSpecificId> message_ids_; |
69 | 69 |
70 DISALLOW_COPY_AND_ASSIGN(ScopedChange); | 70 DISALLOW_COPY_AND_ASSIGN(ScopedChange); |
71 }; | 71 }; |
72 | 72 |
73 ConnectionManager( | 73 ConnectionManager(ConnectionManagerDelegate* delegate, |
74 ConnectionManagerDelegate* delegate, | 74 const scoped_refptr<SurfacesState>& surfaces_state); |
75 const scoped_refptr<surfaces::SurfacesState>& surfaces_state); | |
76 ~ConnectionManager() override; | 75 ~ConnectionManager() override; |
77 | 76 |
78 // Adds a ViewTreeHost. | 77 // Adds a ViewTreeHost. |
79 void AddHost(ViewTreeHostConnection* connection); | 78 void AddHost(ViewTreeHostConnection* connection); |
80 | 79 |
81 // Creates a new ServerView. The return value is owned by the caller, but must | 80 // Creates a new ServerView. The return value is owned by the caller, but must |
82 // be destroyed before ConnectionManager. | 81 // be destroyed before ConnectionManager. |
83 ServerView* CreateServerView(const ViewId& id); | 82 ServerView* CreateServerView(const ViewId& id); |
84 | 83 |
85 // Returns the id for the next ViewTreeImpl. | 84 // Returns the id for the next ViewTreeImpl. |
86 mojo::ConnectionSpecificId GetAndAdvanceNextConnectionId(); | 85 ConnectionSpecificId GetAndAdvanceNextConnectionId(); |
87 | 86 |
88 // Returns the id for the next ViewTreeHostImpl. | 87 // Returns the id for the next ViewTreeHostImpl. |
89 uint16_t GetAndAdvanceNextHostId(); | 88 uint16_t GetAndAdvanceNextHostId(); |
90 | 89 |
91 // Invoked when a ViewTreeImpl's connection encounters an error. | 90 // Invoked when a ViewTreeImpl's connection encounters an error. |
92 void OnConnectionError(ClientConnection* connection); | 91 void OnConnectionError(ClientConnection* connection); |
93 | 92 |
94 // Invoked when a ViewTreeHostBindingOwnerBase's connection encounters an | 93 // Invoked when a ViewTreeHostBindingOwnerBase's connection encounters an |
95 // error or the associated Display window is closed. | 94 // error or the associated Display window is closed. |
96 void OnHostConnectionClosed(ViewTreeHostConnection* connection); | 95 void OnHostConnectionClosed(ViewTreeHostConnection* connection); |
97 | 96 |
98 // See description of ViewTree::Embed() for details. This assumes | 97 // See description of ViewTree::Embed() for details. This assumes |
99 // |transport_view_id| is valid. | 98 // |transport_view_id| is valid. |
100 void EmbedAtView(mojo::ConnectionSpecificId creator_id, | 99 void EmbedAtView(ConnectionSpecificId creator_id, |
101 const ViewId& view_id, | 100 const ViewId& view_id, |
102 mojo::URLRequestPtr request); | 101 mojo::URLRequestPtr request); |
103 ViewTreeImpl* EmbedAtView(mojo::ConnectionSpecificId creator_id, | 102 ViewTreeImpl* EmbedAtView(ConnectionSpecificId creator_id, |
104 const ViewId& view_id, | 103 const ViewId& view_id, |
105 mojo::ViewTreeClientPtr client); | 104 mojo::ViewTreeClientPtr client); |
106 | 105 |
107 // Returns the connection by id. | 106 // Returns the connection by id. |
108 ViewTreeImpl* GetConnection(mojo::ConnectionSpecificId connection_id); | 107 ViewTreeImpl* GetConnection(ConnectionSpecificId connection_id); |
109 | 108 |
110 // Returns the View identified by |id|. | 109 // Returns the View identified by |id|. |
111 ServerView* GetView(const ViewId& id); | 110 ServerView* GetView(const ViewId& id); |
112 | 111 |
113 // Returns whether |view| is a descendant of some root view but not itself a | 112 // Returns whether |view| is a descendant of some root view but not itself a |
114 // root view. | 113 // root view. |
115 bool IsViewAttachedToRoot(const ServerView* view) const; | 114 bool IsViewAttachedToRoot(const ServerView* view) const; |
116 | 115 |
117 // Schedules a paint for the specified region in the coordinates of |view|. | 116 // Schedules a paint for the specified region in the coordinates of |view|. |
118 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds); | 117 void SchedulePaint(const ServerView* view, const gfx::Rect& bounds); |
119 | 118 |
120 bool IsProcessingChange() const { return current_change_ != NULL; } | 119 bool IsProcessingChange() const { return current_change_ != NULL; } |
121 | 120 |
122 bool is_processing_delete_view() const { | 121 bool is_processing_delete_view() const { |
123 return current_change_ && current_change_->is_delete_view(); | 122 return current_change_ && current_change_->is_delete_view(); |
124 } | 123 } |
125 | 124 |
126 // Invoked when the ViewTreeHostImpl's display is closed. | 125 // Invoked when the ViewTreeHostImpl's display is closed. |
127 void OnDisplayClosed(); | 126 void OnDisplayClosed(); |
128 | 127 |
129 // Invoked when a connection messages a client about the change. This is used | 128 // Invoked when a connection messages a client about the change. This is used |
130 // to avoid sending ServerChangeIdAdvanced() unnecessarily. | 129 // to avoid sending ServerChangeIdAdvanced() unnecessarily. |
131 void OnConnectionMessagedClient(mojo::ConnectionSpecificId id); | 130 void OnConnectionMessagedClient(ConnectionSpecificId id); |
132 | 131 |
133 // Returns true if OnConnectionMessagedClient() was invoked for id. | 132 // Returns true if OnConnectionMessagedClient() was invoked for id. |
134 bool DidConnectionMessageClient(mojo::ConnectionSpecificId id) const; | 133 bool DidConnectionMessageClient(ConnectionSpecificId id) const; |
135 | 134 |
136 // Returns the metrics of the viewport where the provided |view| is displayed. | 135 // Returns the metrics of the viewport where the provided |view| is displayed. |
137 mojo::ViewportMetricsPtr GetViewportMetricsForView(const ServerView* view); | 136 mojo::ViewportMetricsPtr GetViewportMetricsForView(const ServerView* view); |
138 | 137 |
139 // Returns the ViewTreeImpl that has |id| as a root. | 138 // Returns the ViewTreeImpl that has |id| as a root. |
140 ViewTreeImpl* GetConnectionWithRoot(const ViewId& id) { | 139 ViewTreeImpl* GetConnectionWithRoot(const ViewId& id) { |
141 return const_cast<ViewTreeImpl*>( | 140 return const_cast<ViewTreeImpl*>( |
142 const_cast<const ConnectionManager*>(this)->GetConnectionWithRoot(id)); | 141 const_cast<const ConnectionManager*>(this)->GetConnectionWithRoot(id)); |
143 } | 142 } |
144 const ViewTreeImpl* GetConnectionWithRoot(const ViewId& id) const; | 143 const ViewTreeImpl* GetConnectionWithRoot(const ViewId& id) const; |
(...skipping 23 matching lines...) Expand all Loading... |
168 const ServerView* old_parent); | 167 const ServerView* old_parent); |
169 void ProcessViewHierarchyChanged(const ServerView* view, | 168 void ProcessViewHierarchyChanged(const ServerView* view, |
170 const ServerView* new_parent, | 169 const ServerView* new_parent, |
171 const ServerView* old_parent); | 170 const ServerView* old_parent); |
172 void ProcessViewReorder(const ServerView* view, | 171 void ProcessViewReorder(const ServerView* view, |
173 const ServerView* relative_view, | 172 const ServerView* relative_view, |
174 const mojo::OrderDirection direction); | 173 const mojo::OrderDirection direction); |
175 void ProcessViewDeleted(const ViewId& view); | 174 void ProcessViewDeleted(const ViewId& view); |
176 | 175 |
177 private: | 176 private: |
178 using ConnectionMap = std::map<mojo::ConnectionSpecificId, ClientConnection*>; | 177 using ConnectionMap = std::map<ConnectionSpecificId, ClientConnection*>; |
179 using HostConnectionMap = | 178 using HostConnectionMap = |
180 std::map<ViewTreeHostImpl*, ViewTreeHostConnection*>; | 179 std::map<ViewTreeHostImpl*, ViewTreeHostConnection*>; |
181 | 180 |
182 // Invoked when a connection is about to make a change. Subsequently followed | 181 // Invoked when a connection is about to make a change. Subsequently followed |
183 // by FinishChange() once the change is done. | 182 // by FinishChange() once the change is done. |
184 // | 183 // |
185 // Changes should never nest, meaning each PrepareForChange() must be | 184 // Changes should never nest, meaning each PrepareForChange() must be |
186 // balanced with a call to FinishChange() with no PrepareForChange() | 185 // balanced with a call to FinishChange() with no PrepareForChange() |
187 // in between. | 186 // in between. |
188 void PrepareForChange(ScopedChange* change); | 187 void PrepareForChange(ScopedChange* change); |
189 | 188 |
190 // Balances a call to PrepareForChange(). | 189 // Balances a call to PrepareForChange(). |
191 void FinishChange(); | 190 void FinishChange(); |
192 | 191 |
193 // Returns true if the specified connection originated the current change. | 192 // Returns true if the specified connection originated the current change. |
194 bool IsChangeSource(mojo::ConnectionSpecificId connection_id) const { | 193 bool IsChangeSource(ConnectionSpecificId connection_id) const { |
195 return current_change_ && current_change_->connection_id() == connection_id; | 194 return current_change_ && current_change_->connection_id() == connection_id; |
196 } | 195 } |
197 | 196 |
198 // Adds |connection| to internal maps. | 197 // Adds |connection| to internal maps. |
199 void AddConnection(ClientConnection* connection); | 198 void AddConnection(ClientConnection* connection); |
200 | 199 |
201 // Overridden from ServerViewDelegate: | 200 // Overridden from ServerViewDelegate: |
202 scoped_ptr<cc::CompositorFrame> UpdateViewTreeFromCompositorFrame( | 201 scoped_ptr<cc::CompositorFrame> UpdateViewTreeFromCompositorFrame( |
203 const mojo::CompositorFramePtr& input) override; | 202 const mojo::CompositorFramePtr& input) override; |
204 surfaces::SurfacesState* GetSurfacesState() override; | 203 SurfacesState* GetSurfacesState() override; |
205 void OnScheduleViewPaint(const ServerView* view) override; | 204 void OnScheduleViewPaint(const ServerView* view) override; |
206 const ServerView* GetRootView(const ServerView* view) const override; | 205 const ServerView* GetRootView(const ServerView* view) const override; |
207 | 206 |
208 // Overridden from ServerViewObserver: | 207 // Overridden from ServerViewObserver: |
209 void OnViewDestroyed(ServerView* view) override; | 208 void OnViewDestroyed(ServerView* view) override; |
210 void OnWillChangeViewHierarchy(ServerView* view, | 209 void OnWillChangeViewHierarchy(ServerView* view, |
211 ServerView* new_parent, | 210 ServerView* new_parent, |
212 ServerView* old_parent) override; | 211 ServerView* old_parent) override; |
213 void OnViewHierarchyChanged(ServerView* view, | 212 void OnViewHierarchyChanged(ServerView* view, |
214 ServerView* new_parent, | 213 ServerView* new_parent, |
(...skipping 14 matching lines...) Expand all Loading... |
229 | 228 |
230 // Overriden from CustomSurfaceConverter: | 229 // Overriden from CustomSurfaceConverter: |
231 bool ConvertSurfaceDrawQuad(const mojo::QuadPtr& input, | 230 bool ConvertSurfaceDrawQuad(const mojo::QuadPtr& input, |
232 const mojo::CompositorFrameMetadataPtr& metadata, | 231 const mojo::CompositorFrameMetadataPtr& metadata, |
233 cc::SharedQuadState* sqs, | 232 cc::SharedQuadState* sqs, |
234 cc::RenderPass* render_pass) override; | 233 cc::RenderPass* render_pass) override; |
235 | 234 |
236 ConnectionManagerDelegate* delegate_; | 235 ConnectionManagerDelegate* delegate_; |
237 | 236 |
238 // State for rendering into a Surface. | 237 // State for rendering into a Surface. |
239 scoped_refptr<surfaces::SurfacesState> surfaces_state_; | 238 scoped_refptr<SurfacesState> surfaces_state_; |
240 | 239 |
241 // ID to use for next ViewTreeImpl. | 240 // ID to use for next ViewTreeImpl. |
242 mojo::ConnectionSpecificId next_connection_id_; | 241 ConnectionSpecificId next_connection_id_; |
243 | 242 |
244 // ID to use for next ViewTreeHostImpl. | 243 // ID to use for next ViewTreeHostImpl. |
245 uint16_t next_host_id_; | 244 uint16_t next_host_id_; |
246 | 245 |
247 // Set of ViewTreeImpls. | 246 // Set of ViewTreeImpls. |
248 ConnectionMap connection_map_; | 247 ConnectionMap connection_map_; |
249 | 248 |
250 // Set of ViewTreeHostImpls. | 249 // Set of ViewTreeHostImpls. |
251 HostConnectionMap host_connection_map_; | 250 HostConnectionMap host_connection_map_; |
252 | 251 |
253 // If non-null we're processing a change. The ScopedChange is not owned by us | 252 // If non-null we're processing a change. The ScopedChange is not owned by us |
254 // (it's created on the stack by ViewTreeImpl). | 253 // (it's created on the stack by ViewTreeImpl). |
255 ScopedChange* current_change_; | 254 ScopedChange* current_change_; |
256 | 255 |
257 bool in_destructor_; | 256 bool in_destructor_; |
258 | 257 |
259 DISALLOW_COPY_AND_ASSIGN(ConnectionManager); | 258 DISALLOW_COPY_AND_ASSIGN(ConnectionManager); |
260 }; | 259 }; |
261 | 260 |
262 } // namespace view_manager | 261 } // namespace mus |
263 | 262 |
264 #endif // COMPONENTS_MUS_CONNECTION_MANAGER_H_ | 263 #endif // COMPONENTS_MUS_CONNECTION_MANAGER_H_ |
OLD | NEW |