| 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 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID, | 34 CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID, |
| 35 CHANGE_TYPE_DONT_ADVANCE_SERVER_CHANGE_ID, | 35 CHANGE_TYPE_DONT_ADVANCE_SERVER_CHANGE_ID, |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 // Create when a ViewManagerConnection is about to make a change. Ensures | 38 // Create when a ViewManagerConnection is about to make a change. Ensures |
| 39 // clients are notified of the correct change id. | 39 // clients are notified of the correct change id. |
| 40 class ScopedChange { | 40 class ScopedChange { |
| 41 public: | 41 public: |
| 42 ScopedChange(ViewManagerConnection* connection, | 42 ScopedChange(ViewManagerConnection* connection, |
| 43 RootNodeManager* root, | 43 RootNodeManager* root, |
| 44 RootNodeManager::ChangeType change_type); | 44 RootNodeManager::ChangeType change_type, |
| 45 bool is_delete_node); |
| 45 ~ScopedChange(); | 46 ~ScopedChange(); |
| 46 | 47 |
| 47 private: | 48 private: |
| 48 RootNodeManager* root_; | 49 RootNodeManager* root_; |
| 49 const ChangeType change_type_; | 50 const ChangeType change_type_; |
| 50 | 51 |
| 51 DISALLOW_COPY_AND_ASSIGN(ScopedChange); | 52 DISALLOW_COPY_AND_ASSIGN(ScopedChange); |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 explicit RootNodeManager(Shell* shell); | 55 explicit RootNodeManager(Shell* shell); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 68 ViewManagerConnection* GetConnection(TransportConnectionId connection_id); | 69 ViewManagerConnection* GetConnection(TransportConnectionId connection_id); |
| 69 | 70 |
| 70 // Returns the Node identified by |id|. | 71 // Returns the Node identified by |id|. |
| 71 Node* GetNode(const NodeId& id); | 72 Node* GetNode(const NodeId& id); |
| 72 | 73 |
| 73 // Returns the View identified by |id|. | 74 // Returns the View identified by |id|. |
| 74 View* GetView(const ViewId& id); | 75 View* GetView(const ViewId& id); |
| 75 | 76 |
| 76 Node* root() { return &root_; } | 77 Node* root() { return &root_; } |
| 77 | 78 |
| 79 bool IsProcessingChange() const { return change_source_ != 0; } |
| 80 |
| 81 bool is_processing_delete_node() const { return is_processing_delete_node_; } |
| 82 |
| 78 // These functions trivially delegate to all ViewManagerConnections, which in | 83 // These functions trivially delegate to all ViewManagerConnections, which in |
| 79 // term notify their clients. | 84 // term notify their clients. |
| 80 void NotifyNodeHierarchyChanged(const NodeId& node, | 85 void ProcessNodeHierarchyChanged(const NodeId& node, |
| 81 const NodeId& new_parent, | 86 const NodeId& new_parent, |
| 82 const NodeId& old_parent); | 87 const NodeId& old_parent); |
| 83 void NotifyNodeViewReplaced(const NodeId& node, | 88 void ProcessNodeViewReplaced(const NodeId& node, |
| 84 const ViewId& new_view_id, | 89 const ViewId& new_view_id, |
| 85 const ViewId& old_view_id); | 90 const ViewId& old_view_id); |
| 86 void NotifyNodeDeleted(const NodeId& node); | 91 void ProcessNodeDeleted(const NodeId& node); |
| 87 void NotifyViewDeleted(const ViewId& view); | 92 void ProcessViewDeleted(const ViewId& view); |
| 88 | 93 |
| 89 private: | 94 private: |
| 90 // Used to setup any static state needed by RootNodeManager. | 95 // Used to setup any static state needed by RootNodeManager. |
| 91 struct Context { | 96 struct Context { |
| 92 Context(); | 97 Context(); |
| 93 ~Context(); | 98 ~Context(); |
| 94 }; | 99 }; |
| 95 | 100 |
| 96 typedef std::map<TransportConnectionId, ViewManagerConnection*> ConnectionMap; | 101 typedef std::map<TransportConnectionId, ViewManagerConnection*> ConnectionMap; |
| 97 | 102 |
| 98 // Invoked when a particular connection is about to make a change. | 103 // Invoked when a particular connection is about to make a change. |
| 99 // Subsequently followed by FinishChange() once the change is done. | 104 // Subsequently followed by FinishChange() once the change is done. |
| 100 // | 105 // |
| 101 // Changes should never nest, meaning each PrepareForChange() must be | 106 // Changes should never nest, meaning each PrepareForChange() must be |
| 102 // balanced with a call to FinishChange() with no PrepareForChange() | 107 // balanced with a call to FinishChange() with no PrepareForChange() |
| 103 // in between. | 108 // in between. |
| 104 void PrepareForChange(ViewManagerConnection* connection); | 109 void PrepareForChange(ViewManagerConnection* connection, bool is_delete_node); |
| 105 | 110 |
| 106 // Balances a call to PrepareForChange(). | 111 // Balances a call to PrepareForChange(). |
| 107 void FinishChange(ChangeType change_type); | 112 void FinishChange(ChangeType change_type); |
| 108 | 113 |
| 109 // Returns true if the specified connection should be notified of the current | 114 // Returns true if the specified connection originated the current change. |
| 110 // change. | 115 bool IsChangeSource(TransportConnectionId connection_id) const { |
| 111 bool ShouldNotifyConnection(TransportConnectionId connection_id) const; | 116 return connection_id == change_source_; |
| 117 } |
| 112 | 118 |
| 113 // Overriden from NodeDelegate: | 119 // Overriden from NodeDelegate: |
| 114 virtual void OnNodeHierarchyChanged(const NodeId& node, | 120 virtual void OnNodeHierarchyChanged(const NodeId& node, |
| 115 const NodeId& new_parent, | 121 const NodeId& new_parent, |
| 116 const NodeId& old_parent) OVERRIDE; | 122 const NodeId& old_parent) OVERRIDE; |
| 117 virtual void OnNodeViewReplaced(const NodeId& node, | 123 virtual void OnNodeViewReplaced(const NodeId& node, |
| 118 const ViewId& new_view_id, | 124 const ViewId& new_view_id, |
| 119 const ViewId& old_view_id) OVERRIDE; | 125 const ViewId& old_view_id) OVERRIDE; |
| 120 | 126 |
| 121 Context context_; | 127 Context context_; |
| 122 | 128 |
| 123 // ID to use for next ViewManagerConnection. | 129 // ID to use for next ViewManagerConnection. |
| 124 TransportConnectionId next_connection_id_; | 130 TransportConnectionId next_connection_id_; |
| 125 | 131 |
| 126 TransportChangeId next_server_change_id_; | 132 TransportChangeId next_server_change_id_; |
| 127 | 133 |
| 128 // Set of ViewManagerConnections. | 134 // Set of ViewManagerConnections. |
| 129 ConnectionMap connection_map_; | 135 ConnectionMap connection_map_; |
| 130 | 136 |
| 131 // If non-zero we're processing a change from this client. | 137 // If non-zero we're processing a change from this client. |
| 132 TransportConnectionId change_source_; | 138 TransportConnectionId change_source_; |
| 133 | 139 |
| 140 // True if we're processing a DeleteNode request. |
| 141 bool is_processing_delete_node_; |
| 142 |
| 134 RootViewManager root_view_manager_; | 143 RootViewManager root_view_manager_; |
| 135 | 144 |
| 136 // Root node. | 145 // Root node. |
| 137 Node root_; | 146 Node root_; |
| 138 | 147 |
| 139 DISALLOW_COPY_AND_ASSIGN(RootNodeManager); | 148 DISALLOW_COPY_AND_ASSIGN(RootNodeManager); |
| 140 }; | 149 }; |
| 141 | 150 |
| 142 } // namespace service | 151 } // namespace service |
| 143 } // namespace view_manager | 152 } // namespace view_manager |
| 144 } // namespace mojo | 153 } // namespace mojo |
| 145 | 154 |
| 146 #endif // MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ | 155 #endif // MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ |
| OLD | NEW |