Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Side by Side Diff: mojo/services/view_manager/root_node_manager.cc

Issue 288313002: Tweaks to ViewManager: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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)
28 : root_(root), 29 : root_(root),
29 change_type_(change_type) { 30 change_type_(change_type) {
30 root_->PrepareForChange(connection); 31 root_->PrepareForChange(connection, is_delete_node);
31 } 32 }
32 33
33 RootNodeManager::ScopedChange::~ScopedChange() { 34 RootNodeManager::ScopedChange::~ScopedChange() {
34 root_->FinishChange(change_type_); 35 root_->FinishChange(change_type_);
35 } 36 }
36 37
37 RootNodeManager::Context::Context() { 38 RootNodeManager::Context::Context() {
38 // Pass in false as native viewport creates the PlatformEventSource. 39 // Pass in false as native viewport creates the PlatformEventSource.
39 aura::Env::CreateInstance(false); 40 aura::Env::CreateInstance(false);
40 } 41 }
41 42
42 RootNodeManager::Context::~Context() { 43 RootNodeManager::Context::~Context() {
43 } 44 }
44 45
45 RootNodeManager::RootNodeManager(Shell* shell) 46 RootNodeManager::RootNodeManager(Shell* shell)
46 : next_connection_id_(1), 47 : next_connection_id_(1),
47 next_server_change_id_(1), 48 next_server_change_id_(1),
48 change_source_(kNoConnection), 49 change_source_(kNoConnection),
50 is_processing_delete_node_(false),
49 root_view_manager_(shell, this), 51 root_view_manager_(shell, this),
50 root_(this, NodeId(0, kRootId)) { 52 root_(this, NodeId(0, kRootId)) {
51 } 53 }
52 54
53 RootNodeManager::~RootNodeManager() { 55 RootNodeManager::~RootNodeManager() {
54 // All the connections should have been destroyed. 56 // All the connections should have been destroyed.
55 DCHECK(connection_map_.empty()); 57 DCHECK(connection_map_.empty());
56 } 58 }
57 59
58 TransportConnectionId RootNodeManager::GetAndAdvanceNextConnectionId() { 60 TransportConnectionId RootNodeManager::GetAndAdvanceNextConnectionId() {
(...skipping 22 matching lines...) Expand all
81 return &root_; 83 return &root_;
82 ConnectionMap::iterator i = connection_map_.find(id.connection_id); 84 ConnectionMap::iterator i = connection_map_.find(id.connection_id);
83 return i == connection_map_.end() ? NULL : i->second->GetNode(id); 85 return i == connection_map_.end() ? NULL : i->second->GetNode(id);
84 } 86 }
85 87
86 View* RootNodeManager::GetView(const ViewId& id) { 88 View* RootNodeManager::GetView(const ViewId& id) {
87 ConnectionMap::iterator i = connection_map_.find(id.connection_id); 89 ConnectionMap::iterator i = connection_map_.find(id.connection_id);
88 return i == connection_map_.end() ? NULL : i->second->GetView(id); 90 return i == connection_map_.end() ? NULL : i->second->GetView(id);
89 } 91 }
90 92
91 void RootNodeManager::NotifyNodeHierarchyChanged(const NodeId& node, 93 void RootNodeManager::ProcessNodeHierarchyChanged(const NodeId& node,
92 const NodeId& new_parent, 94 const NodeId& new_parent,
93 const NodeId& old_parent) { 95 const NodeId& old_parent) {
94 // TODO(sky): make a macro for this. 96 // TODO(sky): make a macro for this.
95 for (ConnectionMap::iterator i = connection_map_.begin(); 97 for (ConnectionMap::iterator i = connection_map_.begin();
96 i != connection_map_.end(); ++i) { 98 i != connection_map_.end(); ++i) {
97 if (ShouldNotifyConnection(i->first)) { 99 i->second->ProcessNodeHierarchyChanged(
98 i->second->NotifyNodeHierarchyChanged( 100 node, new_parent, old_parent, next_server_change_id_,
99 node, new_parent, old_parent, next_server_change_id_); 101 IsChangeSource(i->first));
100 }
101 } 102 }
102 } 103 }
103 104
104 void RootNodeManager::NotifyNodeViewReplaced(const NodeId& node, 105 void RootNodeManager::ProcessNodeViewReplaced(const NodeId& node,
105 const ViewId& new_view_id, 106 const ViewId& new_view_id,
106 const ViewId& old_view_id) { 107 const ViewId& old_view_id) {
107 // TODO(sky): make a macro for this. 108 // TODO(sky): make a macro for this.
108 for (ConnectionMap::iterator i = connection_map_.begin(); 109 for (ConnectionMap::iterator i = connection_map_.begin();
109 i != connection_map_.end(); ++i) { 110 i != connection_map_.end(); ++i) {
110 if (ShouldNotifyConnection(i->first)) 111 i->second->ProcessNodeViewReplaced(node, new_view_id, old_view_id,
111 i->second->NotifyNodeViewReplaced(node, new_view_id, old_view_id); 112 IsChangeSource(i->first));
112 } 113 }
113 } 114 }
114 115
115 void RootNodeManager::NotifyNodeDeleted(const NodeId& node) { 116 void RootNodeManager::ProcessNodeDeleted(const NodeId& node) {
116 // TODO(sky): make a macro for this. 117 // TODO(sky): make a macro for this.
117 for (ConnectionMap::iterator i = connection_map_.begin(); 118 for (ConnectionMap::iterator i = connection_map_.begin();
118 i != connection_map_.end(); ++i) { 119 i != connection_map_.end(); ++i) {
119 if (ShouldNotifyConnection(i->first)) 120 i->second->ProcessNodeDeleted(node, next_server_change_id_,
120 i->second->NotifyNodeDeleted(node, next_server_change_id_); 121 IsChangeSource(i->first));
121 } 122 }
122 } 123 }
123 124
124 void RootNodeManager::NotifyViewDeleted(const ViewId& view) { 125 void RootNodeManager::ProcessViewDeleted(const ViewId& view) {
125 // TODO(sky): make a macro for this. 126 // TODO(sky): make a macro for this.
126 for (ConnectionMap::iterator i = connection_map_.begin(); 127 for (ConnectionMap::iterator i = connection_map_.begin();
127 i != connection_map_.end(); ++i) { 128 i != connection_map_.end(); ++i) {
128 if (ShouldNotifyConnection(i->first)) 129 i->second->ProcessViewDeleted(view, IsChangeSource(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) {
134 // Should only ever have one change in flight. 135 // Should only ever have one change in flight.
135 DCHECK_EQ(kNoConnection, change_source_); 136 DCHECK_EQ(kNoConnection, change_source_);
136 change_source_ = connection->id(); 137 change_source_ = connection->id();
138 is_processing_delete_node_ = is_delete_node;
137 } 139 }
138 140
139 void RootNodeManager::FinishChange(ChangeType change_type) { 141 void RootNodeManager::FinishChange(ChangeType change_type) {
140 // PrepareForChange/FinishChange should be balanced. 142 // PrepareForChange/FinishChange should be balanced.
141 DCHECK_NE(kNoConnection, change_source_); 143 DCHECK_NE(kNoConnection, change_source_);
142 change_source_ = 0; 144 change_source_ = 0;
145 is_processing_delete_node_ = false;
143 if (change_type == CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID) 146 if (change_type == CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID)
144 next_server_change_id_++; 147 next_server_change_id_++;
145 } 148 }
146 149
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
153 void RootNodeManager::OnNodeHierarchyChanged(const NodeId& node, 150 void RootNodeManager::OnNodeHierarchyChanged(const NodeId& node,
154 const NodeId& new_parent, 151 const NodeId& new_parent,
155 const NodeId& old_parent) { 152 const NodeId& old_parent) {
156 if (!root_view_manager_.in_setup()) 153 if (!root_view_manager_.in_setup())
157 NotifyNodeHierarchyChanged(node, new_parent, old_parent); 154 ProcessNodeHierarchyChanged(node, new_parent, old_parent);
158 } 155 }
159 156
160 void RootNodeManager::OnNodeViewReplaced(const NodeId& node, 157 void RootNodeManager::OnNodeViewReplaced(const NodeId& node,
161 const ViewId& new_view_id, 158 const ViewId& new_view_id,
162 const ViewId& old_view_id) { 159 const ViewId& old_view_id) {
163 NotifyNodeViewReplaced(node, new_view_id, old_view_id); 160 ProcessNodeViewReplaced(node, new_view_id, old_view_id);
164 } 161 }
165 162
166 } // namespace service 163 } // namespace service
167 } // namespace view_manager 164 } // namespace view_manager
168 } // namespace mojo 165 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698