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 { | |
15 | |
16 // Id for the root node. | |
17 const TransportConnectionSpecificNodeId kRootId = 1; | |
18 | |
19 // Used to identify an invalid connection. | |
20 const TransportConnectionId kNoConnection = 0; | |
21 | |
22 } // namespace | |
23 | 14 |
24 RootNodeManager::ScopedChange::ScopedChange( | 15 RootNodeManager::ScopedChange::ScopedChange( |
25 ViewManagerConnection* connection, | 16 ViewManagerConnection* connection, |
26 RootNodeManager* root, | 17 RootNodeManager* root, |
27 RootNodeManager::ChangeType change_type, | 18 RootNodeManager::ChangeType change_type, |
28 bool is_delete_node) | 19 bool is_delete_node) |
29 : root_(root), | 20 : root_(root), |
30 change_type_(change_type) { | 21 change_type_(change_type) { |
31 root_->PrepareForChange(connection, is_delete_node); | 22 root_->PrepareForChange(connection, is_delete_node); |
32 } | 23 } |
33 | 24 |
34 RootNodeManager::ScopedChange::~ScopedChange() { | 25 RootNodeManager::ScopedChange::~ScopedChange() { |
35 root_->FinishChange(change_type_); | 26 root_->FinishChange(change_type_); |
36 } | 27 } |
37 | 28 |
38 RootNodeManager::Context::Context() { | 29 RootNodeManager::Context::Context() { |
39 // Pass in false as native viewport creates the PlatformEventSource. | 30 // Pass in false as native viewport creates the PlatformEventSource. |
40 aura::Env::CreateInstance(false); | 31 aura::Env::CreateInstance(false); |
41 } | 32 } |
42 | 33 |
43 RootNodeManager::Context::~Context() { | 34 RootNodeManager::Context::~Context() { |
44 } | 35 } |
45 | 36 |
46 RootNodeManager::RootNodeManager(Shell* shell) | 37 RootNodeManager::RootNodeManager(Shell* shell) |
47 : next_connection_id_(1), | 38 : next_connection_id_(1), |
48 next_server_change_id_(1), | 39 next_server_change_id_(1), |
49 change_source_(kNoConnection), | 40 change_source_(kRootConnection), |
50 is_processing_delete_node_(false), | 41 is_processing_delete_node_(false), |
51 root_view_manager_(shell, this), | 42 root_view_manager_(shell, this), |
52 root_(this, NodeId(0, kRootId)) { | 43 root_(this, RootNodeId()) { |
53 } | 44 } |
54 | 45 |
55 RootNodeManager::~RootNodeManager() { | 46 RootNodeManager::~RootNodeManager() { |
56 // All the connections should have been destroyed. | 47 // All the connections should have been destroyed. |
57 DCHECK(connection_map_.empty()); | 48 DCHECK(connection_map_.empty()); |
58 } | 49 } |
59 | 50 |
60 TransportConnectionId RootNodeManager::GetAndAdvanceNextConnectionId() { | 51 TransportConnectionId RootNodeManager::GetAndAdvanceNextConnectionId() { |
61 const TransportConnectionId id = next_connection_id_++; | 52 const TransportConnectionId id = next_connection_id_++; |
62 DCHECK_LT(id, next_connection_id_); | 53 DCHECK_LT(id, next_connection_id_); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 void RootNodeManager::ProcessViewDeleted(const ViewId& view) { | 113 void RootNodeManager::ProcessViewDeleted(const ViewId& view) { |
123 for (ConnectionMap::iterator i = connection_map_.begin(); | 114 for (ConnectionMap::iterator i = connection_map_.begin(); |
124 i != connection_map_.end(); ++i) { | 115 i != connection_map_.end(); ++i) { |
125 i->second->ProcessViewDeleted(view, IsChangeSource(i->first)); | 116 i->second->ProcessViewDeleted(view, IsChangeSource(i->first)); |
126 } | 117 } |
127 } | 118 } |
128 | 119 |
129 void RootNodeManager::PrepareForChange(ViewManagerConnection* connection, | 120 void RootNodeManager::PrepareForChange(ViewManagerConnection* connection, |
130 bool is_delete_node) { | 121 bool is_delete_node) { |
131 // Should only ever have one change in flight. | 122 // Should only ever have one change in flight. |
132 DCHECK_EQ(kNoConnection, change_source_); | 123 DCHECK_EQ(kRootConnection, change_source_); |
133 change_source_ = connection->id(); | 124 change_source_ = connection->id(); |
134 is_processing_delete_node_ = is_delete_node; | 125 is_processing_delete_node_ = is_delete_node; |
135 } | 126 } |
136 | 127 |
137 void RootNodeManager::FinishChange(ChangeType change_type) { | 128 void RootNodeManager::FinishChange(ChangeType change_type) { |
138 // PrepareForChange/FinishChange should be balanced. | 129 // PrepareForChange/FinishChange should be balanced. |
139 DCHECK_NE(kNoConnection, change_source_); | 130 DCHECK_NE(kRootConnection, change_source_); |
140 change_source_ = 0; | 131 change_source_ = 0; |
141 is_processing_delete_node_ = false; | 132 is_processing_delete_node_ = false; |
142 if (change_type == CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID) | 133 if (change_type == CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID) |
143 next_server_change_id_++; | 134 next_server_change_id_++; |
144 } | 135 } |
145 | 136 |
146 void RootNodeManager::OnNodeHierarchyChanged(const Node* node, | 137 void RootNodeManager::OnNodeHierarchyChanged(const Node* node, |
147 const Node* new_parent, | 138 const Node* new_parent, |
148 const Node* old_parent) { | 139 const Node* old_parent) { |
149 if (!root_view_manager_.in_setup()) | 140 if (!root_view_manager_.in_setup()) |
150 ProcessNodeHierarchyChanged(node, new_parent, old_parent); | 141 ProcessNodeHierarchyChanged(node, new_parent, old_parent); |
151 } | 142 } |
152 | 143 |
153 void RootNodeManager::OnNodeViewReplaced(const Node* node, | 144 void RootNodeManager::OnNodeViewReplaced(const Node* node, |
154 const View* new_view, | 145 const View* new_view, |
155 const View* old_view) { | 146 const View* old_view) { |
156 ProcessNodeViewReplaced(node, new_view, old_view); | 147 ProcessNodeViewReplaced(node, new_view, old_view); |
157 } | 148 } |
158 | 149 |
159 } // namespace service | 150 } // namespace service |
160 } // namespace view_manager | 151 } // namespace view_manager |
161 } // namespace mojo | 152 } // namespace mojo |
OLD | NEW |