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

Side by Side Diff: mojo/services/view_manager/connection_manager.h

Issue 774473003: Move view_manager service implementation to //services (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 MOJO_SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_
6 #define MOJO_SERVICES_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 "mojo/public/cpp/bindings/array.h"
15 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
16 #include "mojo/services/public/interfaces/window_manager/window_manager_internal .mojom.h"
17 #include "mojo/services/view_manager/ids.h"
18 #include "mojo/services/view_manager/server_view_delegate.h"
19
20 namespace mojo {
21 namespace service {
22
23 class ClientConnection;
24 class ConnectionManagerDelegate;
25 class DisplayManager;
26 class ServerView;
27 class ViewManagerServiceImpl;
28
29 // ConnectionManager manages the set of connections to the ViewManager (all the
30 // ViewManagerServiceImpls) as well as providing the root of the hierarchy.
31 class ConnectionManager : public ServerViewDelegate,
32 public WindowManagerInternalClient {
33 public:
34 // Create when a ViewManagerServiceImpl is about to make a change. Ensures
35 // clients are notified correctly.
36 class ScopedChange {
37 public:
38 ScopedChange(ViewManagerServiceImpl* connection,
39 ConnectionManager* connection_manager,
40 bool is_delete_view);
41 ~ScopedChange();
42
43 ConnectionSpecificId connection_id() const { return connection_id_; }
44 bool is_delete_view() const { return is_delete_view_; }
45
46 // Marks the connection with the specified id as having seen a message.
47 void MarkConnectionAsMessaged(ConnectionSpecificId connection_id) {
48 message_ids_.insert(connection_id);
49 }
50
51 // Returns true if MarkConnectionAsMessaged(connection_id) was invoked.
52 bool DidMessageConnection(ConnectionSpecificId connection_id) const {
53 return message_ids_.count(connection_id) > 0;
54 }
55
56 private:
57 ConnectionManager* connection_manager_;
58 const ConnectionSpecificId connection_id_;
59 const bool is_delete_view_;
60
61 // See description of MarkConnectionAsMessaged/DidMessageConnection.
62 std::set<ConnectionSpecificId> message_ids_;
63
64 DISALLOW_COPY_AND_ASSIGN(ScopedChange);
65 };
66
67 ConnectionManager(ConnectionManagerDelegate* delegate,
68 scoped_ptr<DisplayManager> display_manager,
69 WindowManagerInternal* wm_internal);
70 ~ConnectionManager() override;
71
72 // Returns the id for the next ViewManagerServiceImpl.
73 ConnectionSpecificId GetAndAdvanceNextConnectionId();
74
75 // Invoked when a ViewManagerServiceImpl's connection encounters an error.
76 void OnConnectionError(ClientConnection* connection);
77
78 // See description of ViewManagerService::Embed() for details. This assumes
79 // |transport_view_id| is valid.
80 void EmbedAtView(ConnectionSpecificId creator_id,
81 const std::string& url,
82 const ViewId& view_id,
83 InterfaceRequest<ServiceProvider> service_provider);
84
85 // Returns the connection by id.
86 ViewManagerServiceImpl* GetConnection(ConnectionSpecificId connection_id);
87
88 // Returns the View identified by |id|.
89 ServerView* GetView(const ViewId& id);
90
91 ServerView* root() { return root_.get(); }
92
93 bool IsProcessingChange() const { return current_change_ != NULL; }
94
95 bool is_processing_delete_view() const {
96 return current_change_ && current_change_->is_delete_view();
97 }
98
99 // Invoked when a connection messages a client about the change. This is used
100 // to avoid sending ServerChangeIdAdvanced() unnecessarily.
101 void OnConnectionMessagedClient(ConnectionSpecificId id);
102
103 // Returns true if OnConnectionMessagedClient() was invoked for id.
104 bool DidConnectionMessageClient(ConnectionSpecificId id) const;
105
106 // Returns the ViewManagerServiceImpl that has |id| as a root.
107 ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) {
108 return const_cast<ViewManagerServiceImpl*>(
109 const_cast<const ConnectionManager*>(this)->GetConnectionWithRoot(id));
110 }
111 const ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) const;
112
113 WindowManagerInternal* wm_internal() { return wm_internal_; }
114
115 void SetWindowManagerClientConnection(
116 scoped_ptr<ClientConnection> connection);
117 bool has_window_manager_client_connection() const {
118 return window_manager_client_connection_ != nullptr;
119 }
120
121 // WindowManagerInternalClient implementation helper; see mojom for details.
122 bool CloneAndAnimate(const ViewId& view_id);
123
124 // These functions trivially delegate to all ViewManagerServiceImpls, which in
125 // term notify their clients.
126 void ProcessViewDestroyed(ServerView* view);
127 void ProcessViewBoundsChanged(const ServerView* view,
128 const gfx::Rect& old_bounds,
129 const gfx::Rect& new_bounds);
130 void ProcessWillChangeViewHierarchy(const ServerView* view,
131 const ServerView* new_parent,
132 const ServerView* old_parent);
133 void ProcessViewHierarchyChanged(const ServerView* view,
134 const ServerView* new_parent,
135 const ServerView* old_parent);
136 void ProcessViewReorder(const ServerView* view,
137 const ServerView* relative_view,
138 const OrderDirection direction);
139 void ProcessViewDeleted(const ViewId& view);
140
141 private:
142 typedef std::map<ConnectionSpecificId, ClientConnection*> ConnectionMap;
143
144 // Invoked when a connection is about to make a change. Subsequently followed
145 // by FinishChange() once the change is done.
146 //
147 // Changes should never nest, meaning each PrepareForChange() must be
148 // balanced with a call to FinishChange() with no PrepareForChange()
149 // in between.
150 void PrepareForChange(ScopedChange* change);
151
152 // Balances a call to PrepareForChange().
153 void FinishChange();
154
155 // Returns true if the specified connection originated the current change.
156 bool IsChangeSource(ConnectionSpecificId connection_id) const {
157 return current_change_ && current_change_->connection_id() == connection_id;
158 }
159
160 // Adds |connection| to internal maps.
161 void AddConnection(ClientConnection* connection);
162
163 // Callback from animation timer.
164 // TODO(sky): make this real (move to a different class).
165 void DoAnimation();
166
167 // Overridden from ServerViewDelegate:
168 void OnWillDestroyView(ServerView* view) override;
169 void OnViewDestroyed(const ServerView* view) override;
170 void OnWillChangeViewHierarchy(ServerView* view,
171 ServerView* new_parent,
172 ServerView* old_parent) override;
173 void OnViewHierarchyChanged(const ServerView* view,
174 const ServerView* new_parent,
175 const ServerView* old_parent) override;
176 void OnViewBoundsChanged(const ServerView* view,
177 const gfx::Rect& old_bounds,
178 const gfx::Rect& new_bounds) override;
179 void OnViewSurfaceIdChanged(const ServerView* view) override;
180 void OnViewReordered(const ServerView* view,
181 const ServerView* relative,
182 OrderDirection direction) override;
183 void OnWillChangeViewVisibility(ServerView* view) override;
184 void OnViewSharedPropertyChanged(
185 const ServerView* view,
186 const std::string& name,
187 const std::vector<uint8_t>* new_data) override;
188 void OnScheduleViewPaint(const ServerView* view) override;
189
190 // WindowManagerInternalClient:
191 void DispatchInputEventToView(Id transport_view_id, EventPtr event) override;
192 void SetViewportSize(SizePtr size) override;
193 void CloneAndAnimate(Id transport_view_id) override;
194
195 ConnectionManagerDelegate* delegate_;
196
197 // The ClientConnection containing the ViewManagerService implementation
198 // provided to the initial connection (the WindowManager).
199 // NOTE: |window_manager_client_connection_| is also in |connection_map_|.
200 ClientConnection* window_manager_client_connection_;
201
202 // ID to use for next ViewManagerServiceImpl.
203 ConnectionSpecificId next_connection_id_;
204
205 // Set of ViewManagerServiceImpls.
206 ConnectionMap connection_map_;
207
208 scoped_ptr<DisplayManager> display_manager_;
209
210 scoped_ptr<ServerView> root_;
211
212 WindowManagerInternal* wm_internal_;
213
214 // If non-null we're processing a change. The ScopedChange is not owned by us
215 // (it's created on the stack by ViewManagerServiceImpl).
216 ScopedChange* current_change_;
217
218 bool in_destructor_;
219
220 // TODO(sky): nuke! Just a proof of concept until get real animation api.
221 base::RepeatingTimer<ConnectionManager> animation_timer_;
222
223 DISALLOW_COPY_AND_ASSIGN(ConnectionManager);
224 };
225
226 } // namespace service
227 } // namespace mojo
228
229 #endif // MOJO_SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698