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 view_manager { | 12 namespace view_manager { |
13 namespace service { | 13 namespace service { |
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 // Used to identify an invalid connection. | 19 // Used to identify an invalid connection. |
20 const TransportConnectionId kNoConnection = 0; | 20 const TransportConnectionId kNoConnection = 0; |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 RootNodeManager::ScopedChange::ScopedChange( | 24 RootNodeManager::ScopedChange::ScopedChange( |
25 ViewManagerConnection* connection, | 25 ViewManagerConnection* connection, |
26 RootNodeManager* root, | 26 RootNodeManager* root, |
27 RootNodeManager::ChangeType change_type, | 27 RootNodeManager::ChangeType change_type) |
28 bool is_delete_node) | |
29 : root_(root), | 28 : root_(root), |
30 change_type_(change_type) { | 29 change_type_(change_type) { |
31 root_->PrepareForChange(connection, is_delete_node); | 30 root_->PrepareForChange(connection); |
32 } | 31 } |
33 | 32 |
34 RootNodeManager::ScopedChange::~ScopedChange() { | 33 RootNodeManager::ScopedChange::~ScopedChange() { |
35 root_->FinishChange(change_type_); | 34 root_->FinishChange(change_type_); |
36 } | 35 } |
37 | 36 |
38 RootNodeManager::Context::Context() { | 37 RootNodeManager::Context::Context() { |
39 // Pass in false as native viewport creates the PlatformEventSource. | 38 // Pass in false as native viewport creates the PlatformEventSource. |
40 aura::Env::CreateInstance(false); | 39 aura::Env::CreateInstance(false); |
41 } | 40 } |
42 | 41 |
43 RootNodeManager::Context::~Context() { | 42 RootNodeManager::Context::~Context() { |
44 } | 43 } |
45 | 44 |
46 RootNodeManager::RootNodeManager(Shell* shell) | 45 RootNodeManager::RootNodeManager(Shell* shell) |
47 : next_connection_id_(1), | 46 : next_connection_id_(1), |
48 next_server_change_id_(1), | 47 next_server_change_id_(1), |
49 change_source_(kNoConnection), | 48 change_source_(kNoConnection), |
50 is_processing_delete_node_(false), | |
51 root_view_manager_(shell, this), | 49 root_view_manager_(shell, this), |
52 root_(this, NodeId(0, kRootId)) { | 50 root_(this, NodeId(0, kRootId)) { |
53 } | 51 } |
54 | 52 |
55 RootNodeManager::~RootNodeManager() { | 53 RootNodeManager::~RootNodeManager() { |
56 // All the connections should have been destroyed. | 54 // All the connections should have been destroyed. |
57 DCHECK(connection_map_.empty()); | 55 DCHECK(connection_map_.empty()); |
58 } | 56 } |
59 | 57 |
60 TransportConnectionId RootNodeManager::GetAndAdvanceNextConnectionId() { | 58 TransportConnectionId RootNodeManager::GetAndAdvanceNextConnectionId() { |
(...skipping 22 matching lines...) Expand all Loading... |
83 return &root_; | 81 return &root_; |
84 ConnectionMap::iterator i = connection_map_.find(id.connection_id); | 82 ConnectionMap::iterator i = connection_map_.find(id.connection_id); |
85 return i == connection_map_.end() ? NULL : i->second->GetNode(id); | 83 return i == connection_map_.end() ? NULL : i->second->GetNode(id); |
86 } | 84 } |
87 | 85 |
88 View* RootNodeManager::GetView(const ViewId& id) { | 86 View* RootNodeManager::GetView(const ViewId& id) { |
89 ConnectionMap::iterator i = connection_map_.find(id.connection_id); | 87 ConnectionMap::iterator i = connection_map_.find(id.connection_id); |
90 return i == connection_map_.end() ? NULL : i->second->GetView(id); | 88 return i == connection_map_.end() ? NULL : i->second->GetView(id); |
91 } | 89 } |
92 | 90 |
93 void RootNodeManager::ProcessNodeHierarchyChanged(const NodeId& node, | 91 void RootNodeManager::NotifyNodeHierarchyChanged(const NodeId& node, |
94 const NodeId& new_parent, | 92 const NodeId& new_parent, |
95 const NodeId& old_parent) { | 93 const NodeId& old_parent) { |
96 // TODO(sky): make a macro for this. | 94 // TODO(sky): make a macro for this. |
97 for (ConnectionMap::iterator i = connection_map_.begin(); | 95 for (ConnectionMap::iterator i = connection_map_.begin(); |
98 i != connection_map_.end(); ++i) { | 96 i != connection_map_.end(); ++i) { |
99 i->second->ProcessNodeHierarchyChanged( | 97 if (ShouldNotifyConnection(i->first)) { |
100 node, new_parent, old_parent, next_server_change_id_, | 98 i->second->NotifyNodeHierarchyChanged( |
101 IsChangeSource(i->first)); | 99 node, new_parent, old_parent, next_server_change_id_); |
| 100 } |
102 } | 101 } |
103 } | 102 } |
104 | 103 |
105 void RootNodeManager::ProcessNodeViewReplaced(const NodeId& node, | 104 void RootNodeManager::NotifyNodeViewReplaced(const NodeId& node, |
106 const ViewId& new_view_id, | 105 const ViewId& new_view_id, |
107 const ViewId& old_view_id) { | 106 const ViewId& old_view_id) { |
108 // TODO(sky): make a macro for this. | 107 // TODO(sky): make a macro for this. |
109 for (ConnectionMap::iterator i = connection_map_.begin(); | 108 for (ConnectionMap::iterator i = connection_map_.begin(); |
110 i != connection_map_.end(); ++i) { | 109 i != connection_map_.end(); ++i) { |
111 i->second->ProcessNodeViewReplaced(node, new_view_id, old_view_id, | 110 if (ShouldNotifyConnection(i->first)) |
112 IsChangeSource(i->first)); | 111 i->second->NotifyNodeViewReplaced(node, new_view_id, old_view_id); |
113 } | 112 } |
114 } | 113 } |
115 | 114 |
116 void RootNodeManager::ProcessNodeDeleted(const NodeId& node) { | 115 void RootNodeManager::NotifyNodeDeleted(const NodeId& node) { |
117 // TODO(sky): make a macro for this. | 116 // TODO(sky): make a macro for this. |
118 for (ConnectionMap::iterator i = connection_map_.begin(); | 117 for (ConnectionMap::iterator i = connection_map_.begin(); |
119 i != connection_map_.end(); ++i) { | 118 i != connection_map_.end(); ++i) { |
120 i->second->ProcessNodeDeleted(node, next_server_change_id_, | 119 if (ShouldNotifyConnection(i->first)) |
121 IsChangeSource(i->first)); | 120 i->second->NotifyNodeDeleted(node, next_server_change_id_); |
122 } | 121 } |
123 } | 122 } |
124 | 123 |
125 void RootNodeManager::ProcessViewDeleted(const ViewId& view) { | 124 void RootNodeManager::NotifyViewDeleted(const ViewId& view) { |
126 // TODO(sky): make a macro for this. | 125 // TODO(sky): make a macro for this. |
127 for (ConnectionMap::iterator i = connection_map_.begin(); | 126 for (ConnectionMap::iterator i = connection_map_.begin(); |
128 i != connection_map_.end(); ++i) { | 127 i != connection_map_.end(); ++i) { |
129 i->second->ProcessViewDeleted(view, IsChangeSource(i->first)); | 128 if (ShouldNotifyConnection(i->first)) |
| 129 i->second->NotifyViewDeleted(view); |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
133 void RootNodeManager::PrepareForChange(ViewManagerConnection* connection, | 133 void RootNodeManager::PrepareForChange(ViewManagerConnection* connection) { |
134 bool is_delete_node) { | |
135 // Should only ever have one change in flight. | 134 // Should only ever have one change in flight. |
136 DCHECK_EQ(kNoConnection, change_source_); | 135 DCHECK_EQ(kNoConnection, change_source_); |
137 change_source_ = connection->id(); | 136 change_source_ = connection->id(); |
138 is_processing_delete_node_ = is_delete_node; | |
139 } | 137 } |
140 | 138 |
141 void RootNodeManager::FinishChange(ChangeType change_type) { | 139 void RootNodeManager::FinishChange(ChangeType change_type) { |
142 // PrepareForChange/FinishChange should be balanced. | 140 // PrepareForChange/FinishChange should be balanced. |
143 DCHECK_NE(kNoConnection, change_source_); | 141 DCHECK_NE(kNoConnection, change_source_); |
144 change_source_ = 0; | 142 change_source_ = 0; |
145 is_processing_delete_node_ = false; | |
146 if (change_type == CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID) | 143 if (change_type == CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID) |
147 next_server_change_id_++; | 144 next_server_change_id_++; |
148 } | 145 } |
149 | 146 |
| 147 bool RootNodeManager::ShouldNotifyConnection( |
| 148 TransportConnectionId connection_id) const { |
| 149 // Don't notify the source that originated the change. |
| 150 return connection_id != change_source_; |
| 151 } |
| 152 |
150 void RootNodeManager::OnNodeHierarchyChanged(const NodeId& node, | 153 void RootNodeManager::OnNodeHierarchyChanged(const NodeId& node, |
151 const NodeId& new_parent, | 154 const NodeId& new_parent, |
152 const NodeId& old_parent) { | 155 const NodeId& old_parent) { |
153 if (!root_view_manager_.in_setup()) | 156 if (!root_view_manager_.in_setup()) |
154 ProcessNodeHierarchyChanged(node, new_parent, old_parent); | 157 NotifyNodeHierarchyChanged(node, new_parent, old_parent); |
155 } | 158 } |
156 | 159 |
157 void RootNodeManager::OnNodeViewReplaced(const NodeId& node, | 160 void RootNodeManager::OnNodeViewReplaced(const NodeId& node, |
158 const ViewId& new_view_id, | 161 const ViewId& new_view_id, |
159 const ViewId& old_view_id) { | 162 const ViewId& old_view_id) { |
160 ProcessNodeViewReplaced(node, new_view_id, old_view_id); | 163 NotifyNodeViewReplaced(node, new_view_id, old_view_id); |
161 } | 164 } |
162 | 165 |
163 } // namespace service | 166 } // namespace service |
164 } // namespace view_manager | 167 } // namespace view_manager |
165 } // namespace mojo | 168 } // namespace mojo |
OLD | NEW |