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

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

Issue 1049993002: Get mojo_shell building inside chromium checkout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix presubmit Created 5 years, 8 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 SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_
6 #define 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/view_manager/animation_runner.h"
16 #include "mojo/services/view_manager/ids.h"
17 #include "mojo/services/view_manager/server_view_delegate.h"
18 #include "third_party/mojo_services/src/view_manager/public/interfaces/view_mana ger.mojom.h"
19 #include "third_party/mojo_services/src/window_manager/public/interfaces/window_ manager_internal.mojom.h"
20
21 namespace view_manager {
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 mojo::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 mojo::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(mojo::ConnectionSpecificId connection_id) {
48 message_ids_.insert(connection_id);
49 }
50
51 // Returns true if MarkConnectionAsMessaged(connection_id) was invoked.
52 bool DidMessageConnection(mojo::ConnectionSpecificId connection_id) const {
53 return message_ids_.count(connection_id) > 0;
54 }
55
56 private:
57 ConnectionManager* connection_manager_;
58 const mojo::ConnectionSpecificId connection_id_;
59 const bool is_delete_view_;
60
61 // See description of MarkConnectionAsMessaged/DidMessageConnection.
62 std::set<mojo::ConnectionSpecificId> message_ids_;
63
64 DISALLOW_COPY_AND_ASSIGN(ScopedChange);
65 };
66
67 ConnectionManager(ConnectionManagerDelegate* delegate,
68 scoped_ptr<DisplayManager> display_manager,
69 mojo::WindowManagerInternal* wm_internal);
70 ~ConnectionManager() override;
71
72 // Returns the id for the next ViewManagerServiceImpl.
73 mojo::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(mojo::ConnectionSpecificId creator_id,
81 const std::string& url,
82 const ViewId& view_id,
83 mojo::InterfaceRequest<mojo::ServiceProvider> services,
84 mojo::ServiceProviderPtr exposed_services);
85 void EmbedAtView(mojo::ConnectionSpecificId creator_id,
86 const ViewId& view_id,
87 mojo::ViewManagerClientPtr client);
88
89 // Returns the connection by id.
90 ViewManagerServiceImpl* GetConnection(
91 mojo::ConnectionSpecificId connection_id);
92
93 // Returns the View identified by |id|.
94 ServerView* GetView(const ViewId& id);
95
96 ServerView* root() { return root_.get(); }
97 DisplayManager* display_manager() { return display_manager_.get(); }
98
99 bool IsProcessingChange() const { return current_change_ != NULL; }
100
101 bool is_processing_delete_view() const {
102 return current_change_ && current_change_->is_delete_view();
103 }
104
105 // Invoked when a connection messages a client about the change. This is used
106 // to avoid sending ServerChangeIdAdvanced() unnecessarily.
107 void OnConnectionMessagedClient(mojo::ConnectionSpecificId id);
108
109 // Returns true if OnConnectionMessagedClient() was invoked for id.
110 bool DidConnectionMessageClient(mojo::ConnectionSpecificId id) const;
111
112 // Returns the ViewManagerServiceImpl that has |id| as a root.
113 ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) {
114 return const_cast<ViewManagerServiceImpl*>(
115 const_cast<const ConnectionManager*>(this)->GetConnectionWithRoot(id));
116 }
117 const ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) const;
118
119 mojo::WindowManagerInternal* wm_internal() { return wm_internal_; }
120
121 void SetWindowManagerClientConnection(
122 scoped_ptr<ClientConnection> connection);
123 bool has_window_manager_client_connection() const {
124 return window_manager_client_connection_ != nullptr;
125 }
126
127 mojo::ViewManagerClient* GetWindowManagerViewManagerClient();
128
129 // WindowManagerInternalClient implementation helper; see mojom for details.
130 bool CloneAndAnimate(const ViewId& view_id);
131
132 // These functions trivially delegate to all ViewManagerServiceImpls, which in
133 // term notify their clients.
134 void ProcessViewDestroyed(ServerView* view);
135 void ProcessViewBoundsChanged(const ServerView* view,
136 const gfx::Rect& old_bounds,
137 const gfx::Rect& new_bounds);
138 void ProcessViewportMetricsChanged(const mojo::ViewportMetrics& old_metrics,
139 const mojo::ViewportMetrics& new_metrics);
140 void ProcessWillChangeViewHierarchy(const ServerView* view,
141 const ServerView* new_parent,
142 const ServerView* old_parent);
143 void ProcessViewHierarchyChanged(const ServerView* view,
144 const ServerView* new_parent,
145 const ServerView* old_parent);
146 void ProcessViewReorder(const ServerView* view,
147 const ServerView* relative_view,
148 const mojo::OrderDirection direction);
149 void ProcessViewDeleted(const ViewId& view);
150
151 private:
152 typedef std::map<mojo::ConnectionSpecificId, ClientConnection*> ConnectionMap;
153
154 // Invoked when a connection is about to make a change. Subsequently followed
155 // by FinishChange() once the change is done.
156 //
157 // Changes should never nest, meaning each PrepareForChange() must be
158 // balanced with a call to FinishChange() with no PrepareForChange()
159 // in between.
160 void PrepareForChange(ScopedChange* change);
161
162 // Balances a call to PrepareForChange().
163 void FinishChange();
164
165 // Returns true if the specified connection originated the current change.
166 bool IsChangeSource(mojo::ConnectionSpecificId connection_id) const {
167 return current_change_ && current_change_->connection_id() == connection_id;
168 }
169
170 // Adds |connection| to internal maps.
171 void AddConnection(ClientConnection* connection);
172
173 // Callback from animation timer.
174 // TODO(sky): make this real (move to a different class).
175 void DoAnimation();
176
177 // Overridden from ServerViewDelegate:
178 void OnWillDestroyView(ServerView* view) override;
179 void OnViewDestroyed(const ServerView* view) override;
180 void OnWillChangeViewHierarchy(ServerView* view,
181 ServerView* new_parent,
182 ServerView* old_parent) override;
183 void OnViewHierarchyChanged(const ServerView* view,
184 const ServerView* new_parent,
185 const ServerView* old_parent) override;
186 void OnViewBoundsChanged(const ServerView* view,
187 const gfx::Rect& old_bounds,
188 const gfx::Rect& new_bounds) override;
189 void OnViewSurfaceIdChanged(const ServerView* view) override;
190 void OnViewReordered(const ServerView* view,
191 const ServerView* relative,
192 mojo::OrderDirection direction) override;
193 void OnWillChangeViewVisibility(ServerView* view) override;
194 void OnViewSharedPropertyChanged(
195 const ServerView* view,
196 const std::string& name,
197 const std::vector<uint8_t>* new_data) override;
198 void OnScheduleViewPaint(const ServerView* view) override;
199
200 // WindowManagerInternalClient:
201 void DispatchInputEventToView(mojo::Id transport_view_id,
202 mojo::EventPtr event) override;
203 void SetViewportSize(mojo::SizePtr size) override;
204 void CloneAndAnimate(mojo::Id transport_view_id) override;
205
206 ConnectionManagerDelegate* delegate_;
207
208 // The ClientConnection containing the ViewManagerService implementation
209 // provided to the initial connection (the WindowManager).
210 // NOTE: |window_manager_client_connection_| is also in |connection_map_|.
211 ClientConnection* window_manager_client_connection_;
212
213 // ID to use for next ViewManagerServiceImpl.
214 mojo::ConnectionSpecificId next_connection_id_;
215
216 // Set of ViewManagerServiceImpls.
217 ConnectionMap connection_map_;
218
219 scoped_ptr<DisplayManager> display_manager_;
220
221 scoped_ptr<ServerView> root_;
222
223 mojo::WindowManagerInternal* wm_internal_;
224
225 // If non-null we're processing a change. The ScopedChange is not owned by us
226 // (it's created on the stack by ViewManagerServiceImpl).
227 ScopedChange* current_change_;
228
229 bool in_destructor_;
230
231 // TODO(sky): nuke! Just a proof of concept until get real animation api.
232 base::RepeatingTimer<ConnectionManager> animation_timer_;
233
234 AnimationRunner animation_runner_;
235
236 DISALLOW_COPY_AND_ASSIGN(ConnectionManager);
237 };
238
239 } // namespace view_manager
240
241 #endif // SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_
OLDNEW
« no previous file with comments | « mojo/services/view_manager/client_connection.cc ('k') | mojo/services/view_manager/connection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698