| 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_); | 85 client_->OnConnectionEstablished(id_); |
| 90 } | 86 } |
| 91 | 87 |
| 92 Node* ViewManagerConnection::GetNode(const NodeId& id) { | 88 Node* ViewManagerConnection::GetNode(const NodeId& id) { |
| 93 if (id_ == id.connection_id) { | 89 if (id_ == id.connection_id) { |
| 94 NodeMap::iterator i = node_map_.find(id.node_id); | 90 NodeMap::iterator i = node_map_.find(id.node_id); |
| 95 return i == node_map_.end() ? NULL : i->second; | 91 return i == node_map_.end() ? NULL : i->second; |
| 96 } | 92 } |
| 97 return context()->GetNode(id); | 93 return context()->GetNode(id); |
| 98 } | 94 } |
| 99 | 95 |
| 100 View* ViewManagerConnection::GetView(const ViewId& id) { | 96 View* ViewManagerConnection::GetView(const ViewId& id) { |
| 101 if (id_ == id.connection_id) { | 97 if (id_ == id.connection_id) { |
| 102 ViewMap::const_iterator i = view_map_.find(id.view_id); | 98 ViewMap::const_iterator i = view_map_.find(id.view_id); |
| 103 return i == view_map_.end() ? NULL : i->second; | 99 return i == view_map_.end() ? NULL : i->second; |
| 104 } | 100 } |
| 105 return context()->GetView(id); | 101 return context()->GetView(id); |
| 106 } | 102 } |
| 107 | 103 |
| 108 void ViewManagerConnection::NotifyNodeHierarchyChanged( | 104 void ViewManagerConnection::NotifyNodeHierarchyChanged( |
| 109 const NodeId& node, | 105 const NodeId& node, |
| 110 const NodeId& new_parent, | 106 const NodeId& new_parent, |
| 111 const NodeId& old_parent, | 107 const NodeId& old_parent, |
| 112 TransportChangeId change_id) { | 108 TransportChangeId change_id) { |
| 113 client()->OnNodeHierarchyChanged(NodeIdToTransportId(node), | 109 client_->OnNodeHierarchyChanged(NodeIdToTransportId(node), |
| 114 NodeIdToTransportId(new_parent), | 110 NodeIdToTransportId(new_parent), |
| 115 NodeIdToTransportId(old_parent), | 111 NodeIdToTransportId(old_parent), |
| 116 change_id); | 112 change_id); |
| 117 } | 113 } |
| 118 | 114 |
| 119 void ViewManagerConnection::NotifyNodeViewReplaced( | 115 void ViewManagerConnection::NotifyNodeViewReplaced( |
| 120 const NodeId& node, | 116 const NodeId& node, |
| 121 const ViewId& new_view_id, | 117 const ViewId& new_view_id, |
| 122 const ViewId& old_view_id, | 118 const ViewId& old_view_id, |
| 123 TransportChangeId change_id) { | 119 TransportChangeId change_id) { |
| 124 client()->OnNodeViewReplaced(NodeIdToTransportId(node), | 120 client_->OnNodeViewReplaced(NodeIdToTransportId(node), |
| 125 ViewIdToTransportId(new_view_id), | 121 ViewIdToTransportId(new_view_id), |
| 126 ViewIdToTransportId(old_view_id), | 122 ViewIdToTransportId(old_view_id), |
| 127 change_id); | 123 change_id); |
| 128 } | 124 } |
| 129 | 125 |
| 130 bool ViewManagerConnection::DeleteNodeImpl(ViewManagerConnection* source, | 126 bool ViewManagerConnection::DeleteNodeImpl(ViewManagerConnection* source, |
| 131 const NodeId& node_id, | 127 const NodeId& node_id, |
| 132 TransportChangeId change_id) { | 128 TransportChangeId change_id) { |
| 133 DCHECK_EQ(node_id.connection_id, id_); | 129 DCHECK_EQ(node_id.connection_id, id_); |
| 134 Node* node = GetNode(node_id); | 130 Node* node = GetNode(node_id); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 if (!node) | 164 if (!node) |
| 169 return false; | 165 return false; |
| 170 View* view = GetView(view_id); | 166 View* view = GetView(view_id); |
| 171 if (!view && view_id != ViewId()) | 167 if (!view && view_id != ViewId()) |
| 172 return false; | 168 return false; |
| 173 RootNodeManager::ScopedChange change(this, context(), change_id); | 169 RootNodeManager::ScopedChange change(this, context(), change_id); |
| 174 node->SetView(view); | 170 node->SetView(view); |
| 175 return true; | 171 return true; |
| 176 } | 172 } |
| 177 | 173 |
| 174 void ViewManagerConnection::SetClient(IViewManagerClient* client) { |
| 175 client_ = client; |
| 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 |