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 20 matching lines...) Expand all Loading... |
31 class RootViewManagerDelegate; | 31 class RootViewManagerDelegate; |
32 class View; | 32 class View; |
33 class ViewManagerServiceImpl; | 33 class ViewManagerServiceImpl; |
34 | 34 |
35 // RootNodeManager is responsible for managing the set of | 35 // RootNodeManager is responsible for managing the set of |
36 // ViewManagerServiceImpls as well as providing the root of the node hierarchy. | 36 // ViewManagerServiceImpls as well as providing the root of the node hierarchy. |
37 class MOJO_VIEW_MANAGER_EXPORT RootNodeManager | 37 class MOJO_VIEW_MANAGER_EXPORT RootNodeManager |
38 : public NodeDelegate, | 38 : public NodeDelegate, |
39 public aura::client::FocusChangeObserver { | 39 public aura::client::FocusChangeObserver { |
40 public: | 40 public: |
41 // Used to indicate if the server id should be incremented after notifiying | |
42 // clients of the change. | |
43 enum ChangeType { | |
44 CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID, | |
45 CHANGE_TYPE_DONT_ADVANCE_SERVER_CHANGE_ID, | |
46 }; | |
47 | |
48 // Create when a ViewManagerServiceImpl is about to make a change. Ensures | 41 // Create when a ViewManagerServiceImpl is about to make a change. Ensures |
49 // clients are notified of the correct change id. | 42 // clients are notified of the correct change id. |
50 class ScopedChange { | 43 class ScopedChange { |
51 public: | 44 public: |
52 ScopedChange(ViewManagerServiceImpl* connection, | 45 ScopedChange(ViewManagerServiceImpl* connection, |
53 RootNodeManager* root, | 46 RootNodeManager* root, |
54 RootNodeManager::ChangeType change_type, | |
55 bool is_delete_node); | 47 bool is_delete_node); |
56 ~ScopedChange(); | 48 ~ScopedChange(); |
57 | 49 |
58 ConnectionSpecificId connection_id() const { return connection_id_; } | 50 ConnectionSpecificId connection_id() const { return connection_id_; } |
59 ChangeType change_type() const { return change_type_; } | |
60 bool is_delete_node() const { return is_delete_node_; } | 51 bool is_delete_node() const { return is_delete_node_; } |
61 | 52 |
62 // Marks the connection with the specified id as having seen a message. | 53 // Marks the connection with the specified id as having seen a message. |
63 void MarkConnectionAsMessaged(ConnectionSpecificId connection_id) { | 54 void MarkConnectionAsMessaged(ConnectionSpecificId connection_id) { |
64 message_ids_.insert(connection_id); | 55 message_ids_.insert(connection_id); |
65 } | 56 } |
66 | 57 |
67 // Returns true if MarkConnectionAsMessaged(connection_id) was invoked. | 58 // Returns true if MarkConnectionAsMessaged(connection_id) was invoked. |
68 bool DidMessageConnection(ConnectionSpecificId connection_id) const { | 59 bool DidMessageConnection(ConnectionSpecificId connection_id) const { |
69 return message_ids_.count(connection_id) > 0; | 60 return message_ids_.count(connection_id) > 0; |
70 } | 61 } |
71 | 62 |
72 // Sends OnServerChangeIdAdvanced() to all connections that have not yet | |
73 // been messaged. | |
74 void SendServerChangeIdAdvanced(); | |
75 | |
76 private: | 63 private: |
77 RootNodeManager* root_; | 64 RootNodeManager* root_; |
78 const ConnectionSpecificId connection_id_; | 65 const ConnectionSpecificId connection_id_; |
79 const ChangeType change_type_; | |
80 const bool is_delete_node_; | 66 const bool is_delete_node_; |
81 | 67 |
82 // See description of MarkConnectionAsMessaged/DidMessageConnection. | 68 // See description of MarkConnectionAsMessaged/DidMessageConnection. |
83 std::set<ConnectionSpecificId> message_ids_; | 69 std::set<ConnectionSpecificId> message_ids_; |
84 | 70 |
85 DISALLOW_COPY_AND_ASSIGN(ScopedChange); | 71 DISALLOW_COPY_AND_ASSIGN(ScopedChange); |
86 }; | 72 }; |
87 | 73 |
88 RootNodeManager(ApplicationConnection* app_connection, | 74 RootNodeManager(ApplicationConnection* app_connection, |
89 RootViewManagerDelegate* view_manager_delegate, | 75 RootViewManagerDelegate* view_manager_delegate, |
90 const Callback<void()>& native_viewport_closed_callback); | 76 const Callback<void()>& native_viewport_closed_callback); |
91 virtual ~RootNodeManager(); | 77 virtual ~RootNodeManager(); |
92 | 78 |
93 // Returns the id for the next ViewManagerServiceImpl. | 79 // Returns the id for the next ViewManagerServiceImpl. |
94 ConnectionSpecificId GetAndAdvanceNextConnectionId(); | 80 ConnectionSpecificId GetAndAdvanceNextConnectionId(); |
95 | 81 |
96 Id next_server_change_id() const { | |
97 return next_server_change_id_; | |
98 } | |
99 | |
100 void AddConnection(ViewManagerServiceImpl* connection); | 82 void AddConnection(ViewManagerServiceImpl* connection); |
101 void RemoveConnection(ViewManagerServiceImpl* connection); | 83 void RemoveConnection(ViewManagerServiceImpl* connection); |
102 | 84 |
103 // Establishes the initial client. Similar to Connect(), but the resulting | 85 // Establishes the initial client. Similar to Connect(), but the resulting |
104 // client is allowed to do anything. | 86 // client is allowed to do anything. |
105 void EmbedRoot(const std::string& url); | 87 void EmbedRoot(const std::string& url); |
106 | 88 |
107 // See description of ViewManagerService::Embed() for details. This assumes | 89 // See description of ViewManagerService::Embed() for details. This assumes |
108 // |transport_node_id| is valid. | 90 // |transport_node_id| is valid. |
109 void Embed(ConnectionSpecificId creator_id, | 91 void Embed(ConnectionSpecificId creator_id, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 // by FinishChange() once the change is done. | 160 // by FinishChange() once the change is done. |
179 // | 161 // |
180 // Changes should never nest, meaning each PrepareForChange() must be | 162 // Changes should never nest, meaning each PrepareForChange() must be |
181 // balanced with a call to FinishChange() with no PrepareForChange() | 163 // balanced with a call to FinishChange() with no PrepareForChange() |
182 // in between. | 164 // in between. |
183 void PrepareForChange(ScopedChange* change); | 165 void PrepareForChange(ScopedChange* change); |
184 | 166 |
185 // Balances a call to PrepareForChange(). | 167 // Balances a call to PrepareForChange(). |
186 void FinishChange(); | 168 void FinishChange(); |
187 | 169 |
188 // See description in ScopedChange. | |
189 void SendServerChangeIdAdvanced(); | |
190 | |
191 // Returns true if the specified connection originated the current change. | 170 // Returns true if the specified connection originated the current change. |
192 bool IsChangeSource(ConnectionSpecificId connection_id) const { | 171 bool IsChangeSource(ConnectionSpecificId connection_id) const { |
193 return current_change_ && current_change_->connection_id() == connection_id; | 172 return current_change_ && current_change_->connection_id() == connection_id; |
194 } | 173 } |
195 | 174 |
196 // Implementation of the two embed variants. | 175 // Implementation of the two embed variants. |
197 ViewManagerServiceImpl* EmbedImpl(ConnectionSpecificId creator_id, | 176 ViewManagerServiceImpl* EmbedImpl(ConnectionSpecificId creator_id, |
198 const String& url, | 177 const String& url, |
199 const NodeId& root_id); | 178 const NodeId& root_id); |
200 | 179 |
(...skipping 11 matching lines...) Expand all Loading... |
212 virtual void OnViewInputEvent(const View* view, | 191 virtual void OnViewInputEvent(const View* view, |
213 const ui::Event* event) OVERRIDE; | 192 const ui::Event* event) OVERRIDE; |
214 | 193 |
215 Context context_; | 194 Context context_; |
216 | 195 |
217 ApplicationConnection* app_connection_; | 196 ApplicationConnection* app_connection_; |
218 | 197 |
219 // ID to use for next ViewManagerServiceImpl. | 198 // ID to use for next ViewManagerServiceImpl. |
220 ConnectionSpecificId next_connection_id_; | 199 ConnectionSpecificId next_connection_id_; |
221 | 200 |
222 Id next_server_change_id_; | |
223 | |
224 // Set of ViewManagerServiceImpls. | 201 // Set of ViewManagerServiceImpls. |
225 ConnectionMap connection_map_; | 202 ConnectionMap connection_map_; |
226 | 203 |
227 RootViewManager root_view_manager_; | 204 RootViewManager root_view_manager_; |
228 | 205 |
229 // Root node. | 206 // Root node. |
230 scoped_ptr<Node> root_; | 207 scoped_ptr<Node> root_; |
231 | 208 |
232 // Set of ViewManagerServiceImpls created by way of Connect(). These have to | 209 // Set of ViewManagerServiceImpls created by way of Connect(). These have to |
233 // be explicitly destroyed. | 210 // be explicitly destroyed. |
234 std::set<ViewManagerServiceImpl*> connections_created_by_connect_; | 211 std::set<ViewManagerServiceImpl*> connections_created_by_connect_; |
235 | 212 |
236 // If non-null we're processing a change. The ScopedChange is not owned by us | 213 // If non-null we're processing a change. The ScopedChange is not owned by us |
237 // (it's created on the stack by ViewManagerServiceImpl). | 214 // (it's created on the stack by ViewManagerServiceImpl). |
238 ScopedChange* current_change_; | 215 ScopedChange* current_change_; |
239 | 216 |
240 DISALLOW_COPY_AND_ASSIGN(RootNodeManager); | 217 DISALLOW_COPY_AND_ASSIGN(RootNodeManager); |
241 }; | 218 }; |
242 | 219 |
243 } // namespace service | 220 } // namespace service |
244 } // namespace view_manager | 221 } // namespace view_manager |
245 } // namespace mojo | 222 } // namespace mojo |
246 | 223 |
247 #endif // MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ | 224 #endif // MOJO_SERVICES_VIEW_MANAGER_ROOT_NODE_MANAGER_H_ |
OLD | NEW |