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_VIEW_MANAGER_CONNECTION_H_ | 5 #ifndef MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ |
6 #define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ | 6 #define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 TransportConnectionId id() const { return id_; } | 44 TransportConnectionId id() const { return id_; } |
45 | 45 |
46 // Returns the Node with the specified id. | 46 // Returns the Node with the specified id. |
47 Node* GetNode(const NodeId& id) { | 47 Node* GetNode(const NodeId& id) { |
48 return const_cast<Node*>( | 48 return const_cast<Node*>( |
49 const_cast<const ViewManagerConnection*>(this)->GetNode(id)); | 49 const_cast<const ViewManagerConnection*>(this)->GetNode(id)); |
50 } | 50 } |
51 const Node* GetNode(const NodeId& id) const; | 51 const Node* GetNode(const NodeId& id) const; |
52 | 52 |
53 // Returns the View with the specified id. | 53 // Returns the View with the specified id. |
54 View* GetView(const ViewId& id); | 54 View* GetView(const ViewId& id) { |
| 55 return const_cast<View*>( |
| 56 const_cast<const ViewManagerConnection*>(this)->GetView(id)); |
| 57 } |
| 58 const View* GetView(const ViewId& id) const; |
55 | 59 |
56 // The following methods are invoked after the corresponding change has been | 60 // The following methods are invoked after the corresponding change has been |
57 // processed. They do the appropriate bookkeeping and update the client as | 61 // processed. They do the appropriate bookkeeping and update the client as |
58 // necessary. | 62 // necessary. |
59 void ProcessNodeHierarchyChanged(const Node* node, | 63 void ProcessNodeHierarchyChanged(const Node* node, |
60 const Node* new_parent, | 64 const Node* new_parent, |
61 const Node* old_parent, | 65 const Node* old_parent, |
62 TransportChangeId server_change_id, | 66 TransportChangeId server_change_id, |
63 bool originated_change); | 67 bool originated_change); |
64 void ProcessNodeViewReplaced(const Node* node, | 68 void ProcessNodeViewReplaced(const Node* node, |
65 const View* new_view, | 69 const View* new_view, |
66 const View* old_view, | 70 const View* old_view, |
67 bool originated_change); | 71 bool originated_change); |
68 void ProcessNodeDeleted(const NodeId& node, | 72 void ProcessNodeDeleted(const NodeId& node, |
69 TransportChangeId server_change_id, | 73 TransportChangeId server_change_id, |
70 bool originated_change); | 74 bool originated_change); |
71 void ProcessViewDeleted(const ViewId& view, bool originated_change); | 75 void ProcessViewDeleted(const ViewId& view, bool originated_change); |
72 | 76 |
73 private: | 77 private: |
74 typedef std::map<TransportConnectionSpecificNodeId, Node*> NodeMap; | 78 typedef std::map<TransportConnectionSpecificNodeId, Node*> NodeMap; |
75 typedef std::map<TransportConnectionSpecificViewId, View*> ViewMap; | 79 typedef std::map<TransportConnectionSpecificViewId, View*> ViewMap; |
76 typedef base::hash_set<TransportNodeId> NodeIdSet; | 80 typedef base::hash_set<TransportNodeId> NodeIdSet; |
77 | 81 |
78 // Returns true if this connection is allowed to delete the specified node. | 82 // These functions return true if the corresponding mojom function is allowed |
| 83 // for this connection. |
| 84 bool CanRemoveNodeFromParent(const Node* node) const; |
| 85 bool CanAddNode(const Node* parent, const Node* child) const; |
79 bool CanDeleteNode(const NodeId& node_id) const; | 86 bool CanDeleteNode(const NodeId& node_id) const; |
80 | |
81 // Returns true if this connection is allowed to delete the specified view. | |
82 bool CanDeleteView(const ViewId& view_id) const; | 87 bool CanDeleteView(const ViewId& view_id) const; |
| 88 bool CanSetView(const Node* node, const ViewId& view_id) const; |
| 89 bool CanGetNodeTree(const Node* node) const; |
83 | 90 |
84 // Deletes a node owned by this connection. Returns true on success. |source| | 91 // Deletes a node owned by this connection. Returns true on success. |source| |
85 // is the connection that originated the change. | 92 // is the connection that originated the change. |
86 bool DeleteNodeImpl(ViewManagerConnection* source, const NodeId& node_id); | 93 bool DeleteNodeImpl(ViewManagerConnection* source, const NodeId& node_id); |
87 | 94 |
88 // Deletes a view owned by this connection. Returns true on success. |source| | 95 // Deletes a view owned by this connection. Returns true on success. |source| |
89 // is the connection that originated the change. | 96 // is the connection that originated the change. |
90 bool DeleteViewImpl(ViewManagerConnection* source, const ViewId& view_id); | 97 bool DeleteViewImpl(ViewManagerConnection* source, const ViewId& view_id); |
91 | 98 |
92 // Sets the view associated with a node. | 99 // Sets the view associated with a node. |
93 bool SetViewImpl(const NodeId& node_id, const ViewId& view_id); | 100 bool SetViewImpl(Node* node, const ViewId& view_id); |
94 | 101 |
95 // If |node| is known (in |known_nodes_|) does nothing. Otherwise adds |node| | 102 // If |node| is known (in |known_nodes_|) does nothing. Otherwise adds |node| |
96 // to |nodes|, marks |node| as known and recurses. | 103 // to |nodes|, marks |node| as known and recurses. |
97 void GetUnknownNodesFrom(const Node* node, std::vector<const Node*>* nodes); | 104 void GetUnknownNodesFrom(const Node* node, std::vector<const Node*>* nodes); |
98 | 105 |
99 // Removes |node| and all its descendants from |known_nodes_|. This does not | 106 // Removes |node| and all its descendants from |known_nodes_|. This does not |
100 // recurse through nodes that were created by this connection. | 107 // recurse through nodes that were created by this connection. |
101 void RemoveFromKnown(const Node* node); | 108 void RemoveFromKnown(const Node* node); |
102 | 109 |
103 // Returns true if |node| is a non-null and a descendant of |roots_| (or | 110 // Returns true if |node| is a non-null and a descendant of |roots_| (or |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // OnConnectionEstablished(). | 172 // OnConnectionEstablished(). |
166 TransportConnectionId id_; | 173 TransportConnectionId id_; |
167 | 174 |
168 NodeMap node_map_; | 175 NodeMap node_map_; |
169 | 176 |
170 ViewMap view_map_; | 177 ViewMap view_map_; |
171 | 178 |
172 // The set of nodes that has been communicated to the client. | 179 // The set of nodes that has been communicated to the client. |
173 NodeIdSet known_nodes_; | 180 NodeIdSet known_nodes_; |
174 | 181 |
175 // This is the set of nodes the client can see. The client can not delete or | 182 // This is the set of nodes the connection can parent nodes to (in addition to |
176 // move these. | 183 // any nodes created by this connection). If empty the connection can |
| 184 // manipulate any nodes (except for deleting other connections nodes/views). |
| 185 // The connection can not delete or move these. If this is set to a non-empty |
| 186 // value and all the nodes are deleted (by another connection), then an |
| 187 // invalid node is added here to ensure this connection is still constrained. |
177 NodeIdSet roots_; | 188 NodeIdSet roots_; |
178 | 189 |
179 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnection); | 190 DISALLOW_COPY_AND_ASSIGN(ViewManagerConnection); |
180 }; | 191 }; |
181 | 192 |
182 #if defined(OS_WIN) | 193 #if defined(OS_WIN) |
183 #pragma warning(pop) | 194 #pragma warning(pop) |
184 #endif | 195 #endif |
185 | 196 |
186 } // namespace service | 197 } // namespace service |
187 } // namespace view_manager | 198 } // namespace view_manager |
188 } // namespace mojo | 199 } // namespace mojo |
189 | 200 |
190 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ | 201 #endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_CONNECTION_H_ |
OLD | NEW |