| 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/public/interfaces/service_provider/service_provider.mojom.h" | 8 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
| 9 #include "mojo/services/view_manager/view_manager_connection.h" | 9 #include "mojo/services/view_manager/view_manager_connection.h" |
| 10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 RootNodeManager::ScopedChange::~ScopedChange() { | 26 RootNodeManager::ScopedChange::~ScopedChange() { |
| 27 root_->FinishChange(change_type_); | 27 root_->FinishChange(change_type_); |
| 28 } | 28 } |
| 29 | 29 |
| 30 RootNodeManager::Context::Context() { | 30 RootNodeManager::Context::Context() { |
| 31 // Pass in false as native viewport creates the PlatformEventSource. | 31 // Pass in false as native viewport creates the PlatformEventSource. |
| 32 aura::Env::CreateInstance(false); | 32 aura::Env::CreateInstance(false); |
| 33 } | 33 } |
| 34 | 34 |
| 35 RootNodeManager::Context::~Context() { | 35 RootNodeManager::Context::~Context() { |
| 36 aura::Env::DeleteInstance(); |
| 36 } | 37 } |
| 37 | 38 |
| 38 RootNodeManager::RootNodeManager(ServiceProvider* service_provider) | 39 RootNodeManager::RootNodeManager(ServiceProvider* service_provider, |
| 40 RootViewManagerDelegate* view_manager_delegate) |
| 39 : service_provider_(service_provider), | 41 : service_provider_(service_provider), |
| 40 next_connection_id_(1), | 42 next_connection_id_(1), |
| 41 next_server_change_id_(1), | 43 next_server_change_id_(1), |
| 42 change_source_(kRootConnection), | 44 change_source_(kRootConnection), |
| 43 is_processing_delete_node_(false), | 45 is_processing_delete_node_(false), |
| 44 root_view_manager_(service_provider, this), | 46 root_view_manager_(service_provider, this, view_manager_delegate), |
| 45 root_(this, RootNodeId()) { | 47 root_(this, RootNodeId()) { |
| 46 } | 48 } |
| 47 | 49 |
| 48 RootNodeManager::~RootNodeManager() { | 50 RootNodeManager::~RootNodeManager() { |
| 49 while (!connections_created_by_connect_.empty()) | 51 while (!connections_created_by_connect_.empty()) |
| 50 delete *(connections_created_by_connect_.begin()); | 52 delete *(connections_created_by_connect_.begin()); |
| 51 // All the connections should have been destroyed. | 53 // All the connections should have been destroyed. |
| 52 DCHECK(connection_map_.empty()); | 54 DCHECK(connection_map_.empty()); |
| 53 } | 55 } |
| 54 | 56 |
| 55 TransportConnectionId RootNodeManager::GetAndAdvanceNextConnectionId() { | 57 TransportConnectionId RootNodeManager::GetAndAdvanceNextConnectionId() { |
| 56 const TransportConnectionId id = next_connection_id_++; | 58 const TransportConnectionId id = next_connection_id_++; |
| 57 DCHECK_LT(id, next_connection_id_); | 59 DCHECK_LT(id, next_connection_id_); |
| 58 return id; | 60 return id; |
| 59 } | 61 } |
| 60 | 62 |
| 61 void RootNodeManager::AddConnection(ViewManagerConnection* connection) { | 63 void RootNodeManager::AddConnection(ViewManagerConnection* connection) { |
| 62 DCHECK_EQ(0u, connection_map_.count(connection->id())); | 64 DCHECK_EQ(0u, connection_map_.count(connection->id())); |
| 63 connection_map_[connection->id()] = connection; | 65 connection_map_[connection->id()] = connection; |
| 64 } | 66 } |
| 65 | 67 |
| 66 void RootNodeManager::RemoveConnection(ViewManagerConnection* connection) { | 68 void RootNodeManager::RemoveConnection(ViewManagerConnection* connection) { |
| 67 connection_map_.erase(connection->id()); | 69 connection_map_.erase(connection->id()); |
| 68 connections_created_by_connect_.erase(connection); | 70 connections_created_by_connect_.erase(connection); |
| 69 } | 71 } |
| 70 | 72 |
| 73 void RootNodeManager::InitialConnect(const std::string& url) { |
| 74 CHECK(connection_map_.empty()); |
| 75 Array<TransportNodeId> roots(0); |
| 76 ConnectImpl(String::From(url), roots); |
| 77 } |
| 78 |
| 71 void RootNodeManager::Connect(const String& url, | 79 void RootNodeManager::Connect(const String& url, |
| 72 const Array<TransportNodeId>& node_ids) { | 80 const Array<TransportNodeId>& node_ids) { |
| 73 MessagePipe pipe; | 81 CHECK_GT(node_ids.size(), 0u); |
| 74 service_provider_->ConnectToService(url, pipe.handle1.Pass()); | 82 ConnectImpl(url, node_ids)->set_delete_on_connection_error(); |
| 75 ViewManagerConnection* connection = new ViewManagerConnection(this); | |
| 76 connection->SetRoots(node_ids); | |
| 77 BindToPipe(connection, pipe.handle0.Pass()); | |
| 78 connections_created_by_connect_.insert(connection); | |
| 79 } | 83 } |
| 80 | 84 |
| 81 ViewManagerConnection* RootNodeManager::GetConnection( | 85 ViewManagerConnection* RootNodeManager::GetConnection( |
| 82 TransportConnectionId connection_id) { | 86 TransportConnectionId connection_id) { |
| 83 ConnectionMap::iterator i = connection_map_.find(connection_id); | 87 ConnectionMap::iterator i = connection_map_.find(connection_id); |
| 84 return i == connection_map_.end() ? NULL : i->second; | 88 return i == connection_map_.end() ? NULL : i->second; |
| 85 } | 89 } |
| 86 | 90 |
| 87 Node* RootNodeManager::GetNode(const NodeId& id) { | 91 Node* RootNodeManager::GetNode(const NodeId& id) { |
| 88 if (id == root_.id()) | 92 if (id == root_.id()) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 156 |
| 153 void RootNodeManager::FinishChange(ChangeType change_type) { | 157 void RootNodeManager::FinishChange(ChangeType change_type) { |
| 154 // PrepareForChange/FinishChange should be balanced. | 158 // PrepareForChange/FinishChange should be balanced. |
| 155 DCHECK_NE(kRootConnection, change_source_); | 159 DCHECK_NE(kRootConnection, change_source_); |
| 156 change_source_ = 0; | 160 change_source_ = 0; |
| 157 is_processing_delete_node_ = false; | 161 is_processing_delete_node_ = false; |
| 158 if (change_type == CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID) | 162 if (change_type == CHANGE_TYPE_ADVANCE_SERVER_CHANGE_ID) |
| 159 next_server_change_id_++; | 163 next_server_change_id_++; |
| 160 } | 164 } |
| 161 | 165 |
| 166 ViewManagerConnection* RootNodeManager::ConnectImpl( |
| 167 const String& url, |
| 168 const Array<TransportNodeId>& node_ids) { |
| 169 MessagePipe pipe; |
| 170 service_provider_->ConnectToService(url, pipe.handle1.Pass()); |
| 171 ViewManagerConnection* connection = new ViewManagerConnection(this); |
| 172 connection->SetRoots(node_ids); |
| 173 BindToPipe(connection, pipe.handle0.Pass()); |
| 174 connections_created_by_connect_.insert(connection); |
| 175 return connection; |
| 176 } |
| 177 |
| 162 void RootNodeManager::OnNodeHierarchyChanged(const Node* node, | 178 void RootNodeManager::OnNodeHierarchyChanged(const Node* node, |
| 163 const Node* new_parent, | 179 const Node* new_parent, |
| 164 const Node* old_parent) { | 180 const Node* old_parent) { |
| 165 if (!root_view_manager_.in_setup()) | 181 if (!root_view_manager_.in_setup()) |
| 166 ProcessNodeHierarchyChanged(node, new_parent, old_parent); | 182 ProcessNodeHierarchyChanged(node, new_parent, old_parent); |
| 167 } | 183 } |
| 168 | 184 |
| 169 void RootNodeManager::OnNodeViewReplaced(const Node* node, | 185 void RootNodeManager::OnNodeViewReplaced(const Node* node, |
| 170 const View* new_view, | 186 const View* new_view, |
| 171 const View* old_view) { | 187 const View* old_view) { |
| 172 ProcessNodeViewReplaced(node, new_view, old_view); | 188 ProcessNodeViewReplaced(node, new_view, old_view); |
| 173 } | 189 } |
| 174 | 190 |
| 175 } // namespace service | 191 } // namespace service |
| 176 } // namespace view_manager | 192 } // namespace view_manager |
| 177 } // namespace mojo | 193 } // namespace mojo |
| OLD | NEW |