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