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 | 9 |
10 namespace mojo { | 10 namespace mojo { |
11 namespace services { | 11 namespace services { |
12 namespace view_manager { | 12 namespace view_manager { |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Id for the root node. | 15 // Id for the root node. |
16 const uint16_t kRootId = 1; | 16 const uint16_t kRootId = 1; |
17 | 17 |
18 } // namespace | 18 } // namespace |
19 | 19 |
20 RootNodeManager::ScopedChange::ScopedChange(ViewManagerConnection* connection, | 20 RootNodeManager::ScopedChange::ScopedChange(ViewManagerConnection* connection, |
21 RootNodeManager* root, | 21 RootNodeManager* root, |
22 int32_t change_id) | 22 ChangeId change_id) |
23 : root_(root) { | 23 : root_(root) { |
24 root_->PrepareForChange(connection, change_id); | 24 root_->PrepareForChange(connection, change_id); |
25 } | 25 } |
26 | 26 |
27 RootNodeManager::ScopedChange::~ScopedChange() { | 27 RootNodeManager::ScopedChange::~ScopedChange() { |
28 root_->FinishChange(); | 28 root_->FinishChange(); |
29 } | 29 } |
30 | 30 |
31 RootNodeManager::RootNodeManager() | 31 RootNodeManager::RootNodeManager() |
32 : next_connection_id_(1), | 32 : next_connection_id_(1), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 View* RootNodeManager::GetView(const ViewId& id) { | 66 View* RootNodeManager::GetView(const ViewId& id) { |
67 ConnectionMap::iterator i = connection_map_.find(id.connection_id); | 67 ConnectionMap::iterator i = connection_map_.find(id.connection_id); |
68 return i == connection_map_.end() ? NULL : i->second->GetView(id); | 68 return i == connection_map_.end() ? NULL : i->second->GetView(id); |
69 } | 69 } |
70 | 70 |
71 void RootNodeManager::NotifyNodeHierarchyChanged(const NodeId& node, | 71 void RootNodeManager::NotifyNodeHierarchyChanged(const NodeId& node, |
72 const NodeId& new_parent, | 72 const NodeId& new_parent, |
73 const NodeId& old_parent) { | 73 const NodeId& old_parent) { |
74 for (ConnectionMap::iterator i = connection_map_.begin(); | 74 for (ConnectionMap::iterator i = connection_map_.begin(); |
75 i != connection_map_.end(); ++i) { | 75 i != connection_map_.end(); ++i) { |
76 const int32_t change_id = (change_ && i->first == change_->connection_id) ? | 76 const ChangeId change_id = (change_ && i->first == change_->connection_id) ? |
77 change_->change_id : 0; | 77 change_->change_id : 0; |
78 i->second->NotifyNodeHierarchyChanged( | 78 i->second->NotifyNodeHierarchyChanged( |
79 node, new_parent, old_parent, change_id); | 79 node, new_parent, old_parent, change_id); |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 void RootNodeManager::NotifyNodeViewReplaced(const NodeId& node, | 83 void RootNodeManager::NotifyNodeViewReplaced(const NodeId& node, |
84 const ViewId& new_view_id, | 84 const ViewId& new_view_id, |
85 const ViewId& old_view_id) { | 85 const ViewId& old_view_id) { |
86 // TODO(sky): make a macro for this. | 86 // TODO(sky): make a macro for this. |
87 for (ConnectionMap::iterator i = connection_map_.begin(); | 87 for (ConnectionMap::iterator i = connection_map_.begin(); |
88 i != connection_map_.end(); ++i) { | 88 i != connection_map_.end(); ++i) { |
89 const int32_t change_id = (change_ && i->first == change_->connection_id) ? | 89 const ChangeId change_id = (change_ && i->first == change_->connection_id) ? |
90 change_->change_id : 0; | 90 change_->change_id : 0; |
91 i->second->NotifyNodeViewReplaced(node, new_view_id, old_view_id, | 91 i->second->NotifyNodeViewReplaced(node, new_view_id, old_view_id, |
92 change_id); | 92 change_id); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 void RootNodeManager::PrepareForChange(ViewManagerConnection* connection, | 96 void RootNodeManager::PrepareForChange(ViewManagerConnection* connection, |
97 int32_t change_id) { | 97 ChangeId change_id) { |
98 DCHECK(!change_.get()); // Should only ever have one change in flight. | 98 DCHECK(!change_.get()); // Should only ever have one change in flight. |
99 change_.reset(new Change(connection->id(), change_id)); | 99 change_.reset(new Change(connection->id(), change_id)); |
100 } | 100 } |
101 | 101 |
102 void RootNodeManager::FinishChange() { | 102 void RootNodeManager::FinishChange() { |
103 DCHECK(change_.get()); // PrepareForChange/FinishChange should be balanced. | 103 DCHECK(change_.get()); // PrepareForChange/FinishChange should be balanced. |
104 change_.reset(); | 104 change_.reset(); |
105 } | 105 } |
106 | 106 |
107 void RootNodeManager::OnCreated() { | 107 void RootNodeManager::OnCreated() { |
(...skipping 18 matching lines...) Expand all Loading... |
126 | 126 |
127 void RootNodeManager::OnNodeViewReplaced(const NodeId& node, | 127 void RootNodeManager::OnNodeViewReplaced(const NodeId& node, |
128 const ViewId& new_view_id, | 128 const ViewId& new_view_id, |
129 const ViewId& old_view_id) { | 129 const ViewId& old_view_id) { |
130 NotifyNodeViewReplaced(node, new_view_id, old_view_id); | 130 NotifyNodeViewReplaced(node, new_view_id, old_view_id); |
131 } | 131 } |
132 | 132 |
133 } // namespace view_manager | 133 } // namespace view_manager |
134 } // namespace services | 134 } // namespace services |
135 } // namespace mojo | 135 } // namespace mojo |
OLD | NEW |