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 10 matching lines...) Expand all Loading... |
21 namespace services { | 21 namespace services { |
22 namespace view_manager { | 22 namespace view_manager { |
23 | 23 |
24 class View; | 24 class View; |
25 class ViewManagerConnection; | 25 class ViewManagerConnection; |
26 | 26 |
27 // RootNodeManager is responsible for managing the set of ViewManagerConnections | 27 // RootNodeManager is responsible for managing the set of ViewManagerConnections |
28 // as well as providing the root of the node hierarchy. | 28 // as well as providing the root of the node hierarchy. |
29 class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate { | 29 class MOJO_VIEW_MANAGER_EXPORT RootNodeManager : public NodeDelegate { |
30 public: | 30 public: |
| 31 // Used to indicate if the server id should be incremented after notifiying |
| 32 // clients of the change. |
| 33 enum ChangeType { |
| 34 CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID, |
| 35 CHANGE_TYPE_DONT_ADVANCE_SERVER_CHANGE_ID, |
| 36 }; |
| 37 |
31 // Create when a ViewManagerConnection is about to make a change. Ensures | 38 // Create when a ViewManagerConnection is about to make a change. Ensures |
32 // clients are notified of the correct change id. | 39 // clients are notified of the correct change id. |
33 class ScopedChange { | 40 class ScopedChange { |
34 public: | 41 public: |
35 ScopedChange(ViewManagerConnection* connection, | 42 ScopedChange(ViewManagerConnection* connection, |
36 RootNodeManager* root, | 43 RootNodeManager* root, |
37 TransportChangeId change_id); | 44 TransportChangeId change_id, |
| 45 RootNodeManager::ChangeType change_type); |
38 ~ScopedChange(); | 46 ~ScopedChange(); |
39 | 47 |
40 private: | 48 private: |
41 RootNodeManager* root_; | 49 RootNodeManager* root_; |
| 50 const ChangeType change_type_; |
42 | 51 |
43 DISALLOW_COPY_AND_ASSIGN(ScopedChange); | 52 DISALLOW_COPY_AND_ASSIGN(ScopedChange); |
44 }; | 53 }; |
45 | 54 |
46 explicit RootNodeManager(Shell* shell); | 55 explicit RootNodeManager(Shell* shell); |
47 virtual ~RootNodeManager(); | 56 virtual ~RootNodeManager(); |
48 | 57 |
49 // Returns the id for the next ViewManagerConnection. | 58 // Returns the id for the next ViewManagerConnection. |
50 TransportConnectionId GetAndAdvanceNextConnectionId(); | 59 TransportConnectionId GetAndAdvanceNextConnectionId(); |
51 | 60 |
| 61 TransportChangeId next_server_change_id() const { |
| 62 return next_server_change_id_; |
| 63 } |
| 64 |
52 void AddConnection(ViewManagerConnection* connection); | 65 void AddConnection(ViewManagerConnection* connection); |
53 void RemoveConnection(ViewManagerConnection* connection); | 66 void RemoveConnection(ViewManagerConnection* connection); |
54 | 67 |
55 // Returns the connection by id. | 68 // Returns the connection by id. |
56 ViewManagerConnection* GetConnection(TransportConnectionId connection_id); | 69 ViewManagerConnection* GetConnection(TransportConnectionId connection_id); |
57 | 70 |
58 // Returns the Node identified by |id|. | 71 // Returns the Node identified by |id|. |
59 Node* GetNode(const NodeId& id); | 72 Node* GetNode(const NodeId& id); |
60 | 73 |
61 // Returns the View identified by |id|. | 74 // Returns the View identified by |id|. |
(...skipping 13 matching lines...) Expand all Loading... |
75 | 88 |
76 private: | 89 private: |
77 // Used to setup any static state needed by RootNodeManager. | 90 // Used to setup any static state needed by RootNodeManager. |
78 struct Context { | 91 struct Context { |
79 Context(); | 92 Context(); |
80 ~Context(); | 93 ~Context(); |
81 }; | 94 }; |
82 | 95 |
83 // Tracks a change. | 96 // Tracks a change. |
84 struct Change { | 97 struct Change { |
85 Change(TransportConnectionId connection_id, TransportChangeId change_id) | 98 Change(TransportConnectionId connection_id, |
| 99 TransportChangeId client_change_id) |
86 : connection_id(connection_id), | 100 : connection_id(connection_id), |
87 change_id(change_id) { | 101 client_change_id(client_change_id) { |
88 } | 102 } |
89 | 103 |
90 TransportConnectionId connection_id; | 104 TransportConnectionId connection_id; |
91 TransportChangeId change_id; | 105 TransportChangeId client_change_id; |
92 }; | 106 }; |
93 | 107 |
94 typedef std::map<TransportConnectionId, ViewManagerConnection*> ConnectionMap; | 108 typedef std::map<TransportConnectionId, ViewManagerConnection*> ConnectionMap; |
95 | 109 |
96 // Invoked when a particular connection is about to make a change. Records | 110 // Invoked when a particular connection is about to make a change. Records |
97 // the |change_id| so that it can be supplied to the clients by way of | 111 // the |change_id| so that it can be supplied to the clients by way of |
98 // OnNodeHierarchyChanged(). | 112 // OnNodeHierarchyChanged(). |
99 // Changes should never nest, meaning each PrepareForChange() must be | 113 // Changes should never nest, meaning each PrepareForChange() must be |
100 // balanced with a call to FinishChange() with no PrepareForChange() | 114 // balanced with a call to FinishChange() with no PrepareForChange() |
101 // in between. | 115 // in between. |
102 void PrepareForChange(ViewManagerConnection* connection, | 116 void PrepareForChange(ViewManagerConnection* connection, |
103 TransportChangeId change_id); | 117 TransportChangeId change_id); |
104 | 118 |
105 // Balances a call to PrepareForChange(). | 119 // Balances a call to PrepareForChange(). |
106 void FinishChange(); | 120 void FinishChange(ChangeType change_type); |
| 121 |
| 122 TransportChangeId GetClientChangeId( |
| 123 TransportConnectionId connection_id) const; |
107 | 124 |
108 // Overriden from NodeDelegate: | 125 // Overriden from NodeDelegate: |
109 virtual void OnNodeHierarchyChanged(const NodeId& node, | 126 virtual void OnNodeHierarchyChanged(const NodeId& node, |
110 const NodeId& new_parent, | 127 const NodeId& new_parent, |
111 const NodeId& old_parent) OVERRIDE; | 128 const NodeId& old_parent) OVERRIDE; |
112 virtual void OnNodeViewReplaced(const NodeId& node, | 129 virtual void OnNodeViewReplaced(const NodeId& node, |
113 const ViewId& new_view_id, | 130 const ViewId& new_view_id, |
114 const ViewId& old_view_id) OVERRIDE; | 131 const ViewId& old_view_id) OVERRIDE; |
115 | 132 |
116 Context context_; | 133 Context context_; |
117 | 134 |
118 // ID to use for next ViewManagerConnection. | 135 // ID to use for next ViewManagerConnection. |
119 TransportConnectionId next_connection_id_; | 136 TransportConnectionId next_connection_id_; |
120 | 137 |
| 138 TransportChangeId next_server_change_id_; |
| 139 |
121 // Set of ViewManagerConnections. | 140 // Set of ViewManagerConnections. |
122 ConnectionMap connection_map_; | 141 ConnectionMap connection_map_; |
123 | 142 |
124 // If non-null we're processing a change. | 143 // If non-null we're processing a change. |
125 scoped_ptr<Change> change_; | 144 scoped_ptr<Change> change_; |
126 | 145 |
127 RootViewManager root_view_manager_; | 146 RootViewManager root_view_manager_; |
128 | 147 |
129 // Root node. | 148 // Root node. |
130 Node root_; | 149 Node root_; |
131 | 150 |
132 DISALLOW_COPY_AND_ASSIGN(RootNodeManager); | 151 DISALLOW_COPY_AND_ASSIGN(RootNodeManager); |
133 }; | 152 }; |
134 | 153 |
135 } // namespace view_manager | 154 } // namespace view_manager |
136 } // namespace services | 155 } // namespace services |
137 } // namespace mojo | 156 } // namespace mojo |
138 | 157 |
139 #endif // MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ | 158 #endif // MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ |
OLD | NEW |