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

Side by Side Diff: components/view_manager/connection_manager.h

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

Powered by Google App Engine
This is Rietveld 408576698