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 MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ | 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ |
6 #define MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ | 6 #define MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // Create when a ViewManagerConnection is about to make a change. Ensures | 45 // Create when a ViewManagerConnection is about to make a change. Ensures |
46 // clients are notified of the correct change id. | 46 // clients are notified of the correct change id. |
47 class ScopedChange { | 47 class ScopedChange { |
48 public: | 48 public: |
49 ScopedChange(ViewManagerConnection* connection, | 49 ScopedChange(ViewManagerConnection* connection, |
50 RootNodeManager* root, | 50 RootNodeManager* root, |
51 RootNodeManager::ChangeType change_type, | 51 RootNodeManager::ChangeType change_type, |
52 bool is_delete_node); | 52 bool is_delete_node); |
53 ~ScopedChange(); | 53 ~ScopedChange(); |
54 | 54 |
55 TransportConnectionId connection_id() const { return connection_id_; } | 55 ConnectionSpecificId connection_id() const { return connection_id_; } |
56 ChangeType change_type() const { return change_type_; } | 56 ChangeType change_type() const { return change_type_; } |
57 bool is_delete_node() const { return is_delete_node_; } | 57 bool is_delete_node() const { return is_delete_node_; } |
58 | 58 |
59 // Marks the connection with the specified id as having seen a message. | 59 // Marks the connection with the specified id as having seen a message. |
60 void MarkConnectionAsMessaged(TransportConnectionId connection_id) { | 60 void MarkConnectionAsMessaged(ConnectionSpecificId connection_id) { |
61 message_ids_.insert(connection_id); | 61 message_ids_.insert(connection_id); |
62 } | 62 } |
63 | 63 |
64 // Returns true if MarkConnectionAsMessaged(connection_id) was invoked. | 64 // Returns true if MarkConnectionAsMessaged(connection_id) was invoked. |
65 bool DidMessageConnection(TransportConnectionId connection_id) const { | 65 bool DidMessageConnection(ConnectionSpecificId connection_id) const { |
66 return message_ids_.count(connection_id) > 0; | 66 return message_ids_.count(connection_id) > 0; |
67 } | 67 } |
68 | 68 |
69 private: | 69 private: |
70 RootNodeManager* root_; | 70 RootNodeManager* root_; |
71 const TransportConnectionId connection_id_; | 71 const ConnectionSpecificId connection_id_; |
72 const ChangeType change_type_; | 72 const ChangeType change_type_; |
73 const bool is_delete_node_; | 73 const bool is_delete_node_; |
74 | 74 |
75 // See description of MarkConnectionAsMessaged/DidMessageConnection. | 75 // See description of MarkConnectionAsMessaged/DidMessageConnection. |
76 std::set<TransportConnectionId> message_ids_; | 76 std::set<ConnectionSpecificId> message_ids_; |
77 | 77 |
78 DISALLOW_COPY_AND_ASSIGN(ScopedChange); | 78 DISALLOW_COPY_AND_ASSIGN(ScopedChange); |
79 }; | 79 }; |
80 | 80 |
81 RootNodeManager(ServiceProvider* service_provider, | 81 RootNodeManager(ServiceProvider* service_provider, |
82 RootViewManagerDelegate* view_manager_delegate); | 82 RootViewManagerDelegate* view_manager_delegate); |
83 virtual ~RootNodeManager(); | 83 virtual ~RootNodeManager(); |
84 | 84 |
85 // Returns the id for the next ViewManagerConnection. | 85 // Returns the id for the next ViewManagerConnection. |
86 TransportConnectionId GetAndAdvanceNextConnectionId(); | 86 ConnectionSpecificId GetAndAdvanceNextConnectionId(); |
87 | 87 |
88 TransportChangeId next_server_change_id() const { | 88 Id next_server_change_id() const { |
89 return next_server_change_id_; | 89 return next_server_change_id_; |
90 } | 90 } |
91 | 91 |
92 void AddConnection(ViewManagerConnection* connection); | 92 void AddConnection(ViewManagerConnection* connection); |
93 void RemoveConnection(ViewManagerConnection* connection); | 93 void RemoveConnection(ViewManagerConnection* connection); |
94 | 94 |
95 // Establishes the initial client. Similar to Connect(), but the resulting | 95 // Establishes the initial client. Similar to Connect(), but the resulting |
96 // client is allowed to do anything. | 96 // client is allowed to do anything. |
97 void InitialConnect(const std::string& url); | 97 void InitialConnect(const std::string& url); |
98 | 98 |
99 // See description of IViewManager::Connect() for details. This assumes | 99 // See description of IViewManager::Connect() for details. This assumes |
100 // |node_ids| has been validated. | 100 // |node_ids| has been validated. |
101 void Connect(TransportConnectionId creator_id, | 101 void Connect(ConnectionSpecificId creator_id, |
102 const String& url, | 102 const String& url, |
103 const Array<TransportNodeId>& node_ids); | 103 const Array<Id>& node_ids); |
104 | 104 |
105 // Returns the connection by id. | 105 // Returns the connection by id. |
106 ViewManagerConnection* GetConnection(TransportConnectionId connection_id); | 106 ViewManagerConnection* GetConnection(ConnectionSpecificId connection_id); |
107 | 107 |
108 // Returns the Node identified by |id|. | 108 // Returns the Node identified by |id|. |
109 Node* GetNode(const NodeId& id); | 109 Node* GetNode(const NodeId& id); |
110 | 110 |
111 // Returns the View identified by |id|. | 111 // Returns the View identified by |id|. |
112 View* GetView(const ViewId& id); | 112 View* GetView(const ViewId& id); |
113 | 113 |
114 Node* root() { return &root_; } | 114 Node* root() { return &root_; } |
115 | 115 |
116 bool IsProcessingChange() const { return current_change_ != NULL; } | 116 bool IsProcessingChange() const { return current_change_ != NULL; } |
117 | 117 |
118 bool is_processing_delete_node() const { | 118 bool is_processing_delete_node() const { |
119 return current_change_ && current_change_->is_delete_node(); } | 119 return current_change_ && current_change_->is_delete_node(); } |
120 | 120 |
121 // Invoked when a connection messages a client about the change. This is used | 121 // Invoked when a connection messages a client about the change. This is used |
122 // to avoid sending ServerChangeIdAdvanced() unnecessarily. | 122 // to avoid sending ServerChangeIdAdvanced() unnecessarily. |
123 void OnConnectionMessagedClient(TransportConnectionId id); | 123 void OnConnectionMessagedClient(ConnectionSpecificId id); |
124 | 124 |
125 // Returns true if OnConnectionMessagedClient() was invoked for id. | 125 // Returns true if OnConnectionMessagedClient() was invoked for id. |
126 bool DidConnectionMessageClient(TransportConnectionId id) const; | 126 bool DidConnectionMessageClient(ConnectionSpecificId id) const; |
127 | 127 |
128 ViewManagerConnection* GetConnectionByCreator( | 128 ViewManagerConnection* GetConnectionByCreator( |
129 TransportConnectionId creator_id, | 129 ConnectionSpecificId creator_id, |
130 const std::string& url) const; | 130 const std::string& url) const; |
131 | 131 |
132 // These functions trivially delegate to all ViewManagerConnections, which in | 132 // These functions trivially delegate to all ViewManagerConnections, which in |
133 // term notify their clients. | 133 // term notify their clients. |
134 void ProcessNodeBoundsChanged(const Node* node, | 134 void ProcessNodeBoundsChanged(const Node* node, |
135 const gfx::Rect& old_bounds, | 135 const gfx::Rect& old_bounds, |
136 const gfx::Rect& new_bounds); | 136 const gfx::Rect& new_bounds); |
137 void ProcessNodeHierarchyChanged(const Node* node, | 137 void ProcessNodeHierarchyChanged(const Node* node, |
138 const Node* new_parent, | 138 const Node* new_parent, |
139 const Node* old_parent); | 139 const Node* old_parent); |
140 void ProcessNodeViewReplaced(const Node* node, | 140 void ProcessNodeViewReplaced(const Node* node, |
141 const View* new_view_id, | 141 const View* new_view_id, |
142 const View* old_view_id); | 142 const View* old_view_id); |
143 void ProcessNodeDeleted(const NodeId& node); | 143 void ProcessNodeDeleted(const NodeId& node); |
144 void ProcessViewDeleted(const ViewId& view); | 144 void ProcessViewDeleted(const ViewId& view); |
145 | 145 |
146 private: | 146 private: |
147 // Used to setup any static state needed by RootNodeManager. | 147 // Used to setup any static state needed by RootNodeManager. |
148 struct Context { | 148 struct Context { |
149 Context(); | 149 Context(); |
150 ~Context(); | 150 ~Context(); |
151 }; | 151 }; |
152 | 152 |
153 typedef std::map<TransportConnectionId, ViewManagerConnection*> ConnectionMap; | 153 typedef std::map<ConnectionSpecificId, ViewManagerConnection*> ConnectionMap; |
154 | 154 |
155 // Invoked when a connection is about to make a change. Subsequently followed | 155 // Invoked when a connection is about to make a change. Subsequently followed |
156 // by FinishChange() once the change is done. | 156 // by FinishChange() once the change is done. |
157 // | 157 // |
158 // Changes should never nest, meaning each PrepareForChange() must be | 158 // Changes should never nest, meaning each PrepareForChange() must be |
159 // balanced with a call to FinishChange() with no PrepareForChange() | 159 // balanced with a call to FinishChange() with no PrepareForChange() |
160 // in between. | 160 // in between. |
161 void PrepareForChange(ScopedChange* change); | 161 void PrepareForChange(ScopedChange* change); |
162 | 162 |
163 // Balances a call to PrepareForChange(). | 163 // Balances a call to PrepareForChange(). |
164 void FinishChange(); | 164 void FinishChange(); |
165 | 165 |
166 // Returns true if the specified connection originated the current change. | 166 // Returns true if the specified connection originated the current change. |
167 bool IsChangeSource(TransportConnectionId connection_id) const { | 167 bool IsChangeSource(ConnectionSpecificId connection_id) const { |
168 return current_change_ && current_change_->connection_id() == connection_id; | 168 return current_change_ && current_change_->connection_id() == connection_id; |
169 } | 169 } |
170 | 170 |
171 // Implementation of the two connect variants. | 171 // Implementation of the two connect variants. |
172 ViewManagerConnection* ConnectImpl(TransportConnectionId creator_id, | 172 ViewManagerConnection* ConnectImpl(ConnectionSpecificId creator_id, |
173 const String& url, | 173 const String& url, |
174 const Array<TransportNodeId>& node_ids); | 174 const Array<Id>& node_ids); |
175 | 175 |
176 // Overridden from NodeDelegate: | 176 // Overridden from NodeDelegate: |
177 virtual void OnNodeHierarchyChanged(const Node* node, | 177 virtual void OnNodeHierarchyChanged(const Node* node, |
178 const Node* new_parent, | 178 const Node* new_parent, |
179 const Node* old_parent) OVERRIDE; | 179 const Node* old_parent) OVERRIDE; |
180 virtual void OnNodeViewReplaced(const Node* node, | 180 virtual void OnNodeViewReplaced(const Node* node, |
181 const View* new_view, | 181 const View* new_view, |
182 const View* old_view) OVERRIDE; | 182 const View* old_view) OVERRIDE; |
183 virtual void OnViewInputEvent(const View* view, | 183 virtual void OnViewInputEvent(const View* view, |
184 const ui::Event* event) OVERRIDE; | 184 const ui::Event* event) OVERRIDE; |
185 | 185 |
186 Context context_; | 186 Context context_; |
187 | 187 |
188 ServiceProvider* service_provider_; | 188 ServiceProvider* service_provider_; |
189 | 189 |
190 // ID to use for next ViewManagerConnection. | 190 // ID to use for next ViewManagerConnection. |
191 TransportConnectionId next_connection_id_; | 191 ConnectionSpecificId next_connection_id_; |
192 | 192 |
193 TransportChangeId next_server_change_id_; | 193 Id next_server_change_id_; |
194 | 194 |
195 // Set of ViewManagerConnections. | 195 // Set of ViewManagerConnections. |
196 ConnectionMap connection_map_; | 196 ConnectionMap connection_map_; |
197 | 197 |
198 RootViewManager root_view_manager_; | 198 RootViewManager root_view_manager_; |
199 | 199 |
200 // Root node. | 200 // Root node. |
201 Node root_; | 201 Node root_; |
202 | 202 |
203 // Set of ViewManagerConnections created by way of Connect(). These have to be | 203 // Set of ViewManagerConnections created by way of Connect(). These have to be |
204 // explicitly destroyed. | 204 // explicitly destroyed. |
205 std::set<ViewManagerConnection*> connections_created_by_connect_; | 205 std::set<ViewManagerConnection*> connections_created_by_connect_; |
206 | 206 |
207 // If non-null we're processing a change. The ScopedChange is not owned by us | 207 // If non-null we're processing a change. The ScopedChange is not owned by us |
208 // (it's created on the stack by ViewManagerConnection). | 208 // (it's created on the stack by ViewManagerConnection). |
209 ScopedChange* current_change_; | 209 ScopedChange* current_change_; |
210 | 210 |
211 DISALLOW_COPY_AND_ASSIGN(RootNodeManager); | 211 DISALLOW_COPY_AND_ASSIGN(RootNodeManager); |
212 }; | 212 }; |
213 | 213 |
214 } // namespace service | 214 } // namespace service |
215 } // namespace view_manager | 215 } // namespace view_manager |
216 } // namespace mojo | 216 } // namespace mojo |
217 | 217 |
218 #endif // MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ | 218 #endif // MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ |
OLD | NEW |