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

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

Issue 513923004: More viewmanager renaming: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sim30 Created 6 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
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 MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_
6 #define MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ 6 #define MOJO_SERVICES_VIEW_MANAGER_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 "mojo/public/cpp/bindings/array.h" 12 #include "mojo/public/cpp/bindings/array.h"
13 #include "mojo/services/view_manager/display_manager.h" 13 #include "mojo/services/view_manager/display_manager.h"
14 #include "mojo/services/view_manager/ids.h" 14 #include "mojo/services/view_manager/ids.h"
15 #include "mojo/services/view_manager/node.h" 15 #include "mojo/services/view_manager/server_view.h"
16 #include "mojo/services/view_manager/node_delegate.h" 16 #include "mojo/services/view_manager/server_view_delegate.h"
17 #include "mojo/services/view_manager/view_manager_export.h" 17 #include "mojo/services/view_manager/view_manager_export.h"
18 18
19 namespace ui { 19 namespace ui {
20 class Event; 20 class Event;
21 } 21 }
22 22
23 namespace mojo { 23 namespace mojo {
24 24
25 class ApplicationConnection; 25 class ApplicationConnection;
26 26
27 namespace service { 27 namespace service {
28 28
29 class DisplayManagerDelegate; 29 class DisplayManagerDelegate;
30 class ViewManagerServiceImpl; 30 class ViewManagerServiceImpl;
31 31
32 // RootNodeManager is responsible for managing the set of 32 // ConnectionManager manages the set of connections to the ViewManager (all the
33 // ViewManagerServiceImpls as well as providing the root of the node hierarchy. 33 // ViewManagerServiceImpls) as well as providing the root of the hierarchy.
34 class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate { 34 class MOJO_VIEW_MANAGER_EXPORT ConnectionManager : public ServerViewDelegate {
35 public: 35 public:
36 // Create when a ViewManagerServiceImpl is about to make a change. Ensures 36 // Create when a ViewManagerServiceImpl is about to make a change. Ensures
37 // clients are notified of the correct change id. 37 // clients are notified correctly.
38 class ScopedChange { 38 class ScopedChange {
39 public: 39 public:
40 ScopedChange(ViewManagerServiceImpl* connection, 40 ScopedChange(ViewManagerServiceImpl* connection,
41 RootNodeManager* root, 41 ConnectionManager* connection_manager,
42 bool is_delete_node); 42 bool is_delete_view);
43 ~ScopedChange(); 43 ~ScopedChange();
44 44
45 ConnectionSpecificId connection_id() const { return connection_id_; } 45 ConnectionSpecificId connection_id() const { return connection_id_; }
46 bool is_delete_node() const { return is_delete_node_; } 46 bool is_delete_view() const { return is_delete_view_; }
47 47
48 // Marks the connection with the specified id as having seen a message. 48 // Marks the connection with the specified id as having seen a message.
49 void MarkConnectionAsMessaged(ConnectionSpecificId connection_id) { 49 void MarkConnectionAsMessaged(ConnectionSpecificId connection_id) {
50 message_ids_.insert(connection_id); 50 message_ids_.insert(connection_id);
51 } 51 }
52 52
53 // Returns true if MarkConnectionAsMessaged(connection_id) was invoked. 53 // Returns true if MarkConnectionAsMessaged(connection_id) was invoked.
54 bool DidMessageConnection(ConnectionSpecificId connection_id) const { 54 bool DidMessageConnection(ConnectionSpecificId connection_id) const {
55 return message_ids_.count(connection_id) > 0; 55 return message_ids_.count(connection_id) > 0;
56 } 56 }
57 57
58 private: 58 private:
59 RootNodeManager* root_; 59 ConnectionManager* connection_manager_;
60 const ConnectionSpecificId connection_id_; 60 const ConnectionSpecificId connection_id_;
61 const bool is_delete_node_; 61 const bool is_delete_view_;
62 62
63 // See description of MarkConnectionAsMessaged/DidMessageConnection. 63 // See description of MarkConnectionAsMessaged/DidMessageConnection.
64 std::set<ConnectionSpecificId> message_ids_; 64 std::set<ConnectionSpecificId> message_ids_;
65 65
66 DISALLOW_COPY_AND_ASSIGN(ScopedChange); 66 DISALLOW_COPY_AND_ASSIGN(ScopedChange);
67 }; 67 };
68 68
69 RootNodeManager(ApplicationConnection* app_connection, 69 ConnectionManager(ApplicationConnection* app_connection,
70 DisplayManagerDelegate* display_manager_delegate, 70 DisplayManagerDelegate* display_manager_delegate,
71 const Callback<void()>& native_viewport_closed_callback); 71 const Callback<void()>& native_viewport_closed_callback);
72 virtual ~RootNodeManager(); 72 virtual ~ConnectionManager();
73 73
74 // Returns the id for the next ViewManagerServiceImpl. 74 // Returns the id for the next ViewManagerServiceImpl.
75 ConnectionSpecificId GetAndAdvanceNextConnectionId(); 75 ConnectionSpecificId GetAndAdvanceNextConnectionId();
76 76
77 void AddConnection(ViewManagerServiceImpl* connection); 77 void AddConnection(ViewManagerServiceImpl* connection);
78 void RemoveConnection(ViewManagerServiceImpl* connection); 78 void RemoveConnection(ViewManagerServiceImpl* connection);
79 79
80 // Establishes the initial client. Similar to Connect(), but the resulting 80 // Establishes the initial client. Similar to Connect(), but the resulting
81 // client is allowed to do anything. 81 // client is allowed to do anything.
82 void EmbedRoot(const std::string& url, 82 void EmbedRoot(const std::string& url,
83 InterfaceRequest<ServiceProvider> service_provider); 83 InterfaceRequest<ServiceProvider> service_provider);
84 84
85 // See description of ViewManagerService::Embed() for details. This assumes 85 // See description of ViewManagerService::Embed() for details. This assumes
86 // |transport_node_id| is valid. 86 // |transport_view_id| is valid.
87 void Embed(ConnectionSpecificId creator_id, 87 void Embed(ConnectionSpecificId creator_id,
88 const String& url, 88 const String& url,
89 Id transport_node_id, 89 Id transport_view_id,
90 InterfaceRequest<ServiceProvider> service_provider); 90 InterfaceRequest<ServiceProvider> service_provider);
91 91
92 // Returns the connection by id. 92 // Returns the connection by id.
93 ViewManagerServiceImpl* GetConnection(ConnectionSpecificId connection_id); 93 ViewManagerServiceImpl* GetConnection(ConnectionSpecificId connection_id);
94 94
95 // Returns the Node identified by |id|. 95 // Returns the View identified by |id|.
96 Node* GetNode(const NodeId& id); 96 ServerView* GetView(const ViewId& id);
97 97
98 Node* root() { return root_.get(); } 98 ServerView* root() { return root_.get(); }
99 99
100 bool IsProcessingChange() const { return current_change_ != NULL; } 100 bool IsProcessingChange() const { return current_change_ != NULL; }
101 101
102 bool is_processing_delete_node() const { 102 bool is_processing_delete_view() const {
103 return current_change_ && current_change_->is_delete_node(); } 103 return current_change_ && current_change_->is_delete_view();
104 }
104 105
105 // Invoked when a connection messages a client about the change. This is used 106 // Invoked when a connection messages a client about the change. This is used
106 // to avoid sending ServerChangeIdAdvanced() unnecessarily. 107 // to avoid sending ServerChangeIdAdvanced() unnecessarily.
107 void OnConnectionMessagedClient(ConnectionSpecificId id); 108 void OnConnectionMessagedClient(ConnectionSpecificId id);
108 109
109 // Returns true if OnConnectionMessagedClient() was invoked for id. 110 // Returns true if OnConnectionMessagedClient() was invoked for id.
110 bool DidConnectionMessageClient(ConnectionSpecificId id) const; 111 bool DidConnectionMessageClient(ConnectionSpecificId id) const;
111 112
112 ViewManagerServiceImpl* GetConnectionByCreator( 113 ViewManagerServiceImpl* GetConnectionByCreator(
113 ConnectionSpecificId creator_id, 114 ConnectionSpecificId creator_id,
114 const std::string& url) const; 115 const std::string& url) const;
115 116
116 // Returns the ViewManagerServiceImpl that has |id| as a root. 117 // Returns the ViewManagerServiceImpl that has |id| as a root.
117 ViewManagerServiceImpl* GetConnectionWithRoot(const NodeId& id) { 118 ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) {
118 return const_cast<ViewManagerServiceImpl*>( 119 return const_cast<ViewManagerServiceImpl*>(
119 const_cast<const RootNodeManager*>(this)->GetConnectionWithRoot(id)); 120 const_cast<const ConnectionManager*>(this)->GetConnectionWithRoot(id));
120 } 121 }
121 const ViewManagerServiceImpl* GetConnectionWithRoot(const NodeId& id) const; 122 const ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) const;
122 123
123 void DispatchNodeInputEventToWindowManager(EventPtr event); 124 void DispatchViewInputEventToWindowManager(EventPtr event);
124 125
125 // These functions trivially delegate to all ViewManagerServiceImpls, which in 126 // These functions trivially delegate to all ViewManagerServiceImpls, which in
126 // term notify their clients. 127 // term notify their clients.
127 void ProcessNodeDestroyed(Node* node); 128 void ProcessViewDestroyed(ServerView* view);
128 void ProcessNodeBoundsChanged(const Node* node, 129 void ProcessViewBoundsChanged(const ServerView* view,
129 const gfx::Rect& old_bounds, 130 const gfx::Rect& old_bounds,
130 const gfx::Rect& new_bounds); 131 const gfx::Rect& new_bounds);
131 void ProcessNodeHierarchyChanged(const Node* node, 132 void ProcessViewHierarchyChanged(const ServerView* view,
132 const Node* new_parent, 133 const ServerView* new_parent,
133 const Node* old_parent); 134 const ServerView* old_parent);
134 void ProcessNodeReorder(const Node* node, 135 void ProcessViewReorder(const ServerView* view,
135 const Node* relative_node, 136 const ServerView* relative_view,
136 const OrderDirection direction); 137 const OrderDirection direction);
137 void ProcessNodeDeleted(const NodeId& node); 138 void ProcessViewDeleted(const ViewId& view);
138 139
139 private: 140 private:
140 // Used to setup any static state needed by RootNodeManager. 141 // Used to setup any static state needed by ConnectionManager.
141 struct Context { 142 struct Context {
142 Context(); 143 Context();
143 ~Context(); 144 ~Context();
144 }; 145 };
145 146
146 typedef std::map<ConnectionSpecificId, ViewManagerServiceImpl*> ConnectionMap; 147 typedef std::map<ConnectionSpecificId, ViewManagerServiceImpl*> ConnectionMap;
147 148
148 // Invoked when a connection is about to make a change. Subsequently followed 149 // Invoked when a connection is about to make a change. Subsequently followed
149 // by FinishChange() once the change is done. 150 // by FinishChange() once the change is done.
150 // 151 //
151 // Changes should never nest, meaning each PrepareForChange() must be 152 // Changes should never nest, meaning each PrepareForChange() must be
152 // balanced with a call to FinishChange() with no PrepareForChange() 153 // balanced with a call to FinishChange() with no PrepareForChange()
153 // in between. 154 // in between.
154 void PrepareForChange(ScopedChange* change); 155 void PrepareForChange(ScopedChange* change);
155 156
156 // Balances a call to PrepareForChange(). 157 // Balances a call to PrepareForChange().
157 void FinishChange(); 158 void FinishChange();
158 159
159 // Returns true if the specified connection originated the current change. 160 // Returns true if the specified connection originated the current change.
160 bool IsChangeSource(ConnectionSpecificId connection_id) const { 161 bool IsChangeSource(ConnectionSpecificId connection_id) const {
161 return current_change_ && current_change_->connection_id() == connection_id; 162 return current_change_ && current_change_->connection_id() == connection_id;
162 } 163 }
163 164
164 // Implementation of the two embed variants. 165 // Implementation of the two embed variants.
165 ViewManagerServiceImpl* EmbedImpl( 166 ViewManagerServiceImpl* EmbedImpl(
166 ConnectionSpecificId creator_id, 167 ConnectionSpecificId creator_id,
167 const String& url, 168 const String& url,
168 const NodeId& root_id, 169 const ViewId& root_id,
169 InterfaceRequest<ServiceProvider> service_provider); 170 InterfaceRequest<ServiceProvider> service_provider);
170 171
171 // Overridden from NodeDelegate: 172 // Overridden from ServerViewDelegate:
172 virtual void OnNodeDestroyed(const Node* node) OVERRIDE; 173 virtual void OnViewDestroyed(const ServerView* view) OVERRIDE;
173 virtual void OnNodeHierarchyChanged(const Node* node, 174 virtual void OnViewHierarchyChanged(const ServerView* view,
174 const Node* new_parent, 175 const ServerView* new_parent,
175 const Node* old_parent) OVERRIDE; 176 const ServerView* old_parent) OVERRIDE;
176 virtual void OnNodeBoundsChanged(const Node* node, 177 virtual void OnViewBoundsChanged(const ServerView* view,
177 const gfx::Rect& old_bounds, 178 const gfx::Rect& old_bounds,
178 const gfx::Rect& new_bounds) OVERRIDE; 179 const gfx::Rect& new_bounds) OVERRIDE;
179 virtual void OnNodeBitmapChanged(const Node* node) OVERRIDE; 180 virtual void OnViewBitmapChanged(const ServerView* view) OVERRIDE;
180 181
181 Context context_; 182 Context context_;
182 183
183 ApplicationConnection* app_connection_; 184 ApplicationConnection* app_connection_;
184 185
185 // ID to use for next ViewManagerServiceImpl. 186 // ID to use for next ViewManagerServiceImpl.
186 ConnectionSpecificId next_connection_id_; 187 ConnectionSpecificId next_connection_id_;
187 188
188 // Set of ViewManagerServiceImpls. 189 // Set of ViewManagerServiceImpls.
189 ConnectionMap connection_map_; 190 ConnectionMap connection_map_;
190 191
191 DisplayManager display_manager_; 192 DisplayManager display_manager_;
192 193
193 // Root node. 194 scoped_ptr<ServerView> root_;
194 scoped_ptr<Node> root_;
195 195
196 // Set of ViewManagerServiceImpls created by way of Connect(). These have to 196 // Set of ViewManagerServiceImpls created by way of Connect(). These have to
197 // be explicitly destroyed. 197 // be explicitly destroyed.
198 std::set<ViewManagerServiceImpl*> connections_created_by_connect_; 198 std::set<ViewManagerServiceImpl*> connections_created_by_connect_;
199 199
200 // If non-null we're processing a change. The ScopedChange is not owned by us 200 // If non-null we're processing a change. The ScopedChange is not owned by us
201 // (it's created on the stack by ViewManagerServiceImpl). 201 // (it's created on the stack by ViewManagerServiceImpl).
202 ScopedChange* current_change_; 202 ScopedChange* current_change_;
203 203
204 DISALLOW_COPY_AND_ASSIGN(RootNodeManager); 204 DISALLOW_COPY_AND_ASSIGN(ConnectionManager);
205 }; 205 };
206 206
207 } // namespace service 207 } // namespace service
208 } // namespace mojo 208 } // namespace mojo
209 209
210 #endif // MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ 210 #endif // MOJO_SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_
OLDNEW
« no previous file with comments | « mojo/services/view_manager/access_policy_delegate.h ('k') | mojo/services/view_manager/connection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698