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 #include "mojo/services/view_manager/root_node_manager.h" | 5 #include "mojo/services/view_manager/root_node_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "mojo/services/view_manager/view_manager_connection.h" | 8 #include "mojo/services/view_manager/view_manager_connection.h" |
9 #include "ui/aura/env.h" | 9 #include "ui/aura/env.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 namespace services { | 12 namespace services { |
13 namespace view_manager { | 13 namespace view_manager { |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Id for the root node. | 16 // Id for the root node. |
17 const TransportConnectionSpecificNodeId kRootId = 1; | 17 const TransportConnectionSpecificNodeId kRootId = 1; |
18 | 18 |
19 } // namespace | 19 } // namespace |
20 | 20 |
| 21 RootNodeManager::ScopedChange::ScopedChange( |
| 22 ViewManagerConnection* connection, |
| 23 RootNodeManager* root, |
| 24 TransportChangeId change_id, |
| 25 RootNodeManager::ChangeType change_type) |
| 26 : root_(root), |
| 27 change_type_(change_type) { |
| 28 root_->PrepareForChange(connection, change_id); |
| 29 } |
| 30 |
| 31 RootNodeManager::ScopedChange::~ScopedChange() { |
| 32 root_->FinishChange(change_type_); |
| 33 } |
| 34 |
21 RootNodeManager::Context::Context() { | 35 RootNodeManager::Context::Context() { |
22 // Pass in false as native viewport creates the PlatformEventSource. | 36 // Pass in false as native viewport creates the PlatformEventSource. |
23 aura::Env::CreateInstance(false); | 37 aura::Env::CreateInstance(false); |
24 } | 38 } |
25 | 39 |
26 RootNodeManager::Context::~Context() { | 40 RootNodeManager::Context::~Context() { |
27 } | 41 } |
28 | 42 |
29 RootNodeManager::ScopedChange::ScopedChange(ViewManagerConnection* connection, | |
30 RootNodeManager* root, | |
31 TransportChangeId change_id) | |
32 : root_(root) { | |
33 root_->PrepareForChange(connection, change_id); | |
34 } | |
35 | |
36 RootNodeManager::ScopedChange::~ScopedChange() { | |
37 root_->FinishChange(); | |
38 } | |
39 | |
40 RootNodeManager::RootNodeManager(Shell* shell) | 43 RootNodeManager::RootNodeManager(Shell* shell) |
41 : next_connection_id_(1), | 44 : next_connection_id_(1), |
| 45 next_server_change_id_(1), |
42 root_view_manager_(shell, this), | 46 root_view_manager_(shell, this), |
43 root_(this, NodeId(0, kRootId)) { | 47 root_(this, NodeId(0, kRootId)) { |
44 } | 48 } |
45 | 49 |
46 RootNodeManager::~RootNodeManager() { | 50 RootNodeManager::~RootNodeManager() { |
47 // All the connections should have been destroyed. | 51 // All the connections should have been destroyed. |
48 DCHECK(connection_map_.empty()); | 52 DCHECK(connection_map_.empty()); |
49 } | 53 } |
50 | 54 |
51 TransportConnectionId RootNodeManager::GetAndAdvanceNextConnectionId() { | 55 TransportConnectionId RootNodeManager::GetAndAdvanceNextConnectionId() { |
(...skipping 27 matching lines...) Expand all Loading... |
79 View* RootNodeManager::GetView(const ViewId& id) { | 83 View* RootNodeManager::GetView(const ViewId& id) { |
80 ConnectionMap::iterator i = connection_map_.find(id.connection_id); | 84 ConnectionMap::iterator i = connection_map_.find(id.connection_id); |
81 return i == connection_map_.end() ? NULL : i->second->GetView(id); | 85 return i == connection_map_.end() ? NULL : i->second->GetView(id); |
82 } | 86 } |
83 | 87 |
84 void RootNodeManager::NotifyNodeHierarchyChanged(const NodeId& node, | 88 void RootNodeManager::NotifyNodeHierarchyChanged(const NodeId& node, |
85 const NodeId& new_parent, | 89 const NodeId& new_parent, |
86 const NodeId& old_parent) { | 90 const NodeId& old_parent) { |
87 for (ConnectionMap::iterator i = connection_map_.begin(); | 91 for (ConnectionMap::iterator i = connection_map_.begin(); |
88 i != connection_map_.end(); ++i) { | 92 i != connection_map_.end(); ++i) { |
89 const TransportChangeId change_id = | |
90 (change_ && i->first == change_->connection_id) ? | |
91 change_->change_id : 0; | |
92 i->second->NotifyNodeHierarchyChanged( | 93 i->second->NotifyNodeHierarchyChanged( |
93 node, new_parent, old_parent, change_id); | 94 node, new_parent, old_parent, next_server_change_id_, |
| 95 GetClientChangeId(i->first)); |
94 } | 96 } |
95 } | 97 } |
96 | 98 |
97 void RootNodeManager::NotifyNodeViewReplaced(const NodeId& node, | 99 void RootNodeManager::NotifyNodeViewReplaced(const NodeId& node, |
98 const ViewId& new_view_id, | 100 const ViewId& new_view_id, |
99 const ViewId& old_view_id) { | 101 const ViewId& old_view_id) { |
100 // TODO(sky): make a macro for this. | 102 // TODO(sky): make a macro for this. |
101 for (ConnectionMap::iterator i = connection_map_.begin(); | 103 for (ConnectionMap::iterator i = connection_map_.begin(); |
102 i != connection_map_.end(); ++i) { | 104 i != connection_map_.end(); ++i) { |
103 const TransportChangeId change_id = | |
104 (change_ && i->first == change_->connection_id) ? | |
105 change_->change_id : 0; | |
106 i->second->NotifyNodeViewReplaced(node, new_view_id, old_view_id, | 105 i->second->NotifyNodeViewReplaced(node, new_view_id, old_view_id, |
107 change_id); | 106 GetClientChangeId(i->first)); |
108 } | 107 } |
109 } | 108 } |
110 | 109 |
111 void RootNodeManager::NotifyNodeDeleted(const NodeId& node) { | 110 void RootNodeManager::NotifyNodeDeleted(const NodeId& node) { |
| 111 // TODO(sky): make a macro for this. |
112 for (ConnectionMap::iterator i = connection_map_.begin(); | 112 for (ConnectionMap::iterator i = connection_map_.begin(); |
113 i != connection_map_.end(); ++i) { | 113 i != connection_map_.end(); ++i) { |
114 const TransportChangeId change_id = | 114 i->second->NotifyNodeDeleted(node, next_server_change_id_, |
115 (change_ && i->first == change_->connection_id) ? | 115 GetClientChangeId(i->first)); |
116 change_->change_id : 0; | |
117 i->second->NotifyNodeDeleted(node, change_id); | |
118 } | 116 } |
119 } | 117 } |
120 | 118 |
121 void RootNodeManager::PrepareForChange(ViewManagerConnection* connection, | 119 void RootNodeManager::PrepareForChange(ViewManagerConnection* connection, |
122 TransportChangeId change_id) { | 120 TransportChangeId change_id) { |
123 DCHECK(!change_.get()); // Should only ever have one change in flight. | 121 DCHECK(!change_.get()); // Should only ever have one change in flight. |
124 change_.reset(new Change(connection->id(), change_id)); | 122 change_.reset(new Change(connection->id(), change_id)); |
125 } | 123 } |
126 | 124 |
127 void RootNodeManager::FinishChange() { | 125 void RootNodeManager::FinishChange(ChangeType change_type) { |
128 DCHECK(change_.get()); // PrepareForChange/FinishChange should be balanced. | 126 DCHECK(change_.get()); // PrepareForChange/FinishChange should be balanced. |
129 change_.reset(); | 127 change_.reset(); |
| 128 if (change_type == CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID) |
| 129 next_server_change_id_++; |
| 130 } |
| 131 |
| 132 TransportChangeId RootNodeManager::GetClientChangeId( |
| 133 TransportConnectionId connection_id) const { |
| 134 return (change_ && connection_id == change_->connection_id) ? |
| 135 change_->client_change_id : 0; |
130 } | 136 } |
131 | 137 |
132 void RootNodeManager::OnNodeHierarchyChanged(const NodeId& node, | 138 void RootNodeManager::OnNodeHierarchyChanged(const NodeId& node, |
133 const NodeId& new_parent, | 139 const NodeId& new_parent, |
134 const NodeId& old_parent) { | 140 const NodeId& old_parent) { |
135 if (!root_view_manager_.in_setup()) | 141 if (!root_view_manager_.in_setup()) |
136 NotifyNodeHierarchyChanged(node, new_parent, old_parent); | 142 NotifyNodeHierarchyChanged(node, new_parent, old_parent); |
137 } | 143 } |
138 | 144 |
139 void RootNodeManager::OnNodeViewReplaced(const NodeId& node, | 145 void RootNodeManager::OnNodeViewReplaced(const NodeId& node, |
140 const ViewId& new_view_id, | 146 const ViewId& new_view_id, |
141 const ViewId& old_view_id) { | 147 const ViewId& old_view_id) { |
142 NotifyNodeViewReplaced(node, new_view_id, old_view_id); | 148 NotifyNodeViewReplaced(node, new_view_id, old_view_id); |
143 } | 149 } |
144 | 150 |
145 } // namespace view_manager | 151 } // namespace view_manager |
146 } // namespace services | 152 } // namespace services |
147 } // namespace mojo | 153 } // namespace mojo |
OLD | NEW |