| 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/view_manager_connection.h" | 5 #include "mojo/services/view_manager/view_manager_connection.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "mojo/public/cpp/bindings/allocation_scope.h" | 8 #include "mojo/public/cpp/bindings/allocation_scope.h" |
| 9 #include "mojo/services/view_manager/node.h" | 9 #include "mojo/services/view_manager/node.h" |
| 10 #include "mojo/services/view_manager/root_node_manager.h" | 10 #include "mojo/services/view_manager/root_node_manager.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 std::vector<Node*> children(node->GetChildren()); | 50 std::vector<Node*> children(node->GetChildren()); |
| 51 for (size_t i = 0 ; i < children.size(); ++i) { | 51 for (size_t i = 0 ; i < children.size(); ++i) { |
| 52 (*index)++; | 52 (*index)++; |
| 53 NodeToINode(children[i], array_builder, index); | 53 NodeToINode(children[i], array_builder, index); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 ViewManagerConnection::ViewManagerConnection() : id_(0) { | 59 ViewManagerConnection::ViewManagerConnection() : client_(NULL), id_(0) { |
| 60 } | 60 } |
| 61 | 61 |
| 62 ViewManagerConnection::~ViewManagerConnection() { | 62 ViewManagerConnection::~ViewManagerConnection() { |
| 63 // Delete any views we own. | 63 // Delete any views we own. |
| 64 while (!view_map_.empty()) { | 64 while (!view_map_.empty()) { |
| 65 bool result = DeleteViewImpl(this, view_map_.begin()->second->id(), 0); | 65 bool result = DeleteViewImpl(this, view_map_.begin()->second->id(), 0); |
| 66 DCHECK(result); | 66 DCHECK(result); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // We're about to destroy all our nodes. Detach any views from them. | 69 // We're about to destroy all our nodes. Detach any views from them. |
| 70 for (NodeMap::iterator i = node_map_.begin(); i != node_map_.end(); ++i) { | 70 for (NodeMap::iterator i = node_map_.begin(); i != node_map_.end(); ++i) { |
| 71 if (i->second->view()) { | 71 if (i->second->view()) { |
| 72 bool result = SetViewImpl(i->second->id(), ViewId(), 0); | 72 bool result = SetViewImpl(i->second->id(), ViewId(), 0); |
| 73 DCHECK(result); | 73 DCHECK(result); |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 STLDeleteContainerPairSecondPointers(node_map_.begin(), node_map_.end()); | 77 STLDeleteContainerPairSecondPointers(node_map_.begin(), node_map_.end()); |
| 78 context()->RemoveConnection(this); | 78 context()->RemoveConnection(this); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void ViewManagerConnection::Initialize( | 81 void ViewManagerConnection::Initialize() { |
| 82 ServiceConnector<ViewManagerConnection, RootNodeManager>* service_factory, | |
| 83 ScopedMessagePipeHandle client_handle) { | |
| 84 DCHECK_EQ(0, id_); // Should only get Initialize() once. | 82 DCHECK_EQ(0, id_); // Should only get Initialize() once. |
| 85 ServiceConnection<IViewManager, ViewManagerConnection, RootNodeManager>:: | |
| 86 Initialize(service_factory, client_handle.Pass()); | |
| 87 id_ = context()->GetAndAdvanceNextConnectionId(); | 83 id_ = context()->GetAndAdvanceNextConnectionId(); |
| 88 context()->AddConnection(this); | 84 context()->AddConnection(this); |
| 89 client()->OnConnectionEstablished(id_); | |
| 90 } | 85 } |
| 91 | 86 |
| 92 Node* ViewManagerConnection::GetNode(const NodeId& id) { | 87 Node* ViewManagerConnection::GetNode(const NodeId& id) { |
| 93 if (id_ == id.connection_id) { | 88 if (id_ == id.connection_id) { |
| 94 NodeMap::iterator i = node_map_.find(id.node_id); | 89 NodeMap::iterator i = node_map_.find(id.node_id); |
| 95 return i == node_map_.end() ? NULL : i->second; | 90 return i == node_map_.end() ? NULL : i->second; |
| 96 } | 91 } |
| 97 return context()->GetNode(id); | 92 return context()->GetNode(id); |
| 98 } | 93 } |
| 99 | 94 |
| 100 View* ViewManagerConnection::GetView(const ViewId& id) { | 95 View* ViewManagerConnection::GetView(const ViewId& id) { |
| 101 if (id_ == id.connection_id) { | 96 if (id_ == id.connection_id) { |
| 102 ViewMap::const_iterator i = view_map_.find(id.view_id); | 97 ViewMap::const_iterator i = view_map_.find(id.view_id); |
| 103 return i == view_map_.end() ? NULL : i->second; | 98 return i == view_map_.end() ? NULL : i->second; |
| 104 } | 99 } |
| 105 return context()->GetView(id); | 100 return context()->GetView(id); |
| 106 } | 101 } |
| 107 | 102 |
| 108 void ViewManagerConnection::NotifyNodeHierarchyChanged( | 103 void ViewManagerConnection::NotifyNodeHierarchyChanged( |
| 109 const NodeId& node, | 104 const NodeId& node, |
| 110 const NodeId& new_parent, | 105 const NodeId& new_parent, |
| 111 const NodeId& old_parent, | 106 const NodeId& old_parent, |
| 112 TransportChangeId change_id) { | 107 TransportChangeId change_id) { |
| 113 client()->OnNodeHierarchyChanged(NodeIdToTransportId(node), | 108 client_->OnNodeHierarchyChanged(NodeIdToTransportId(node), |
| 114 NodeIdToTransportId(new_parent), | 109 NodeIdToTransportId(new_parent), |
| 115 NodeIdToTransportId(old_parent), | 110 NodeIdToTransportId(old_parent), |
| 116 change_id); | 111 change_id); |
| 117 } | 112 } |
| 118 | 113 |
| 119 void ViewManagerConnection::NotifyNodeViewReplaced( | 114 void ViewManagerConnection::NotifyNodeViewReplaced( |
| 120 const NodeId& node, | 115 const NodeId& node, |
| 121 const ViewId& new_view_id, | 116 const ViewId& new_view_id, |
| 122 const ViewId& old_view_id, | 117 const ViewId& old_view_id, |
| 123 TransportChangeId change_id) { | 118 TransportChangeId change_id) { |
| 124 client()->OnNodeViewReplaced(NodeIdToTransportId(node), | 119 client_->OnNodeViewReplaced(NodeIdToTransportId(node), |
| 125 ViewIdToTransportId(new_view_id), | 120 ViewIdToTransportId(new_view_id), |
| 126 ViewIdToTransportId(old_view_id), | 121 ViewIdToTransportId(old_view_id), |
| 127 change_id); | 122 change_id); |
| 128 } | 123 } |
| 129 | 124 |
| 130 bool ViewManagerConnection::DeleteNodeImpl(ViewManagerConnection* source, | 125 bool ViewManagerConnection::DeleteNodeImpl(ViewManagerConnection* source, |
| 131 const NodeId& node_id, | 126 const NodeId& node_id, |
| 132 TransportChangeId change_id) { | 127 TransportChangeId change_id) { |
| 133 DCHECK_EQ(node_id.connection_id, id_); | 128 DCHECK_EQ(node_id.connection_id, id_); |
| 134 Node* node = GetNode(node_id); | 129 Node* node = GetNode(node_id); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 if (!node) | 163 if (!node) |
| 169 return false; | 164 return false; |
| 170 View* view = GetView(view_id); | 165 View* view = GetView(view_id); |
| 171 if (!view && view_id != ViewId()) | 166 if (!view && view_id != ViewId()) |
| 172 return false; | 167 return false; |
| 173 RootNodeManager::ScopedChange change(this, context(), change_id); | 168 RootNodeManager::ScopedChange change(this, context(), change_id); |
| 174 node->SetView(view); | 169 node->SetView(view); |
| 175 return true; | 170 return true; |
| 176 } | 171 } |
| 177 | 172 |
| 173 void ViewManagerConnection::SetClient(IViewManagerClient* client) { |
| 174 client_ = client; |
| 175 client_->OnConnectionEstablished(id_); |
| 176 } |
| 177 |
| 178 void ViewManagerConnection::CreateNode( | 178 void ViewManagerConnection::CreateNode( |
| 179 TransportConnectionSpecificNodeId node_id, | 179 TransportConnectionSpecificNodeId node_id, |
| 180 const Callback<void(bool)>& callback) { | 180 const Callback<void(bool)>& callback) { |
| 181 // Negative values are reserved. | 181 // Negative values are reserved. |
| 182 if (node_map_.find(node_id) != node_map_.end()) { | 182 if (node_map_.find(node_id) != node_map_.end()) { |
| 183 callback.Run(false); | 183 callback.Run(false); |
| 184 return; | 184 return; |
| 185 } | 185 } |
| 186 node_map_[node_id] = new Node(this, NodeId(id_, node_id)); | 186 node_map_[node_id] = new Node(this, NodeId(id_, node_id)); |
| 187 callback.Run(true); | 187 callback.Run(true); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 279 |
| 280 void ViewManagerConnection::OnNodeViewReplaced(const NodeId& node, | 280 void ViewManagerConnection::OnNodeViewReplaced(const NodeId& node, |
| 281 const ViewId& new_view_id, | 281 const ViewId& new_view_id, |
| 282 const ViewId& old_view_id) { | 282 const ViewId& old_view_id) { |
| 283 context()->NotifyNodeViewReplaced(node, new_view_id, old_view_id); | 283 context()->NotifyNodeViewReplaced(node, new_view_id, old_view_id); |
| 284 } | 284 } |
| 285 | 285 |
| 286 } // namespace view_manager | 286 } // namespace view_manager |
| 287 } // namespace services | 287 } // namespace services |
| 288 } // namespace mojo | 288 } // namespace mojo |
| OLD | NEW |