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

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

Issue 308803002: Change type of interface created by mojo:view_manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 6 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/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/services/public/cpp/geometry/geometry_type_converters.h" 8 #include "mojo/services/public/cpp/geometry/geometry_type_converters.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 16 matching lines...) Expand all
27 27
28 std::vector<const Node*> children(node->GetChildren()); 28 std::vector<const Node*> children(node->GetChildren());
29 for (size_t i = 0 ; i < children.size(); ++i) 29 for (size_t i = 0 ; i < children.size(); ++i)
30 GetDescendants(children[i], nodes); 30 GetDescendants(children[i], nodes);
31 } 31 }
32 32
33 } // namespace 33 } // namespace
34 34
35 ViewManagerConnection::ViewManagerConnection(RootNodeManager* root_node_manager) 35 ViewManagerConnection::ViewManagerConnection(RootNodeManager* root_node_manager)
36 : root_node_manager_(root_node_manager), 36 : root_node_manager_(root_node_manager),
37 id_(0) { 37 id_(root_node_manager_->GetAndAdvanceNextConnectionId()),
38 delete_on_connection_error_(false) {
38 } 39 }
39 40
40 ViewManagerConnection::~ViewManagerConnection() { 41 ViewManagerConnection::~ViewManagerConnection() {
41 // Delete any views we own. 42 // Delete any views we own.
42 while (!view_map_.empty()) { 43 while (!view_map_.empty()) {
43 bool result = DeleteViewImpl(this, view_map_.begin()->second->id()); 44 bool result = DeleteViewImpl(this, view_map_.begin()->second->id());
44 DCHECK(result); 45 DCHECK(result);
45 } 46 }
46 47
47 // We're about to destroy all our nodes. Detach any views from them. 48 // We're about to destroy all our nodes. Detach any views from them.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 81
81 const View* ViewManagerConnection::GetView(const ViewId& id) const { 82 const View* ViewManagerConnection::GetView(const ViewId& id) const {
82 if (id_ == id.connection_id) { 83 if (id_ == id.connection_id) {
83 ViewMap::const_iterator i = view_map_.find(id.view_id); 84 ViewMap::const_iterator i = view_map_.find(id.view_id);
84 return i == view_map_.end() ? NULL : i->second; 85 return i == view_map_.end() ? NULL : i->second;
85 } 86 }
86 return root_node_manager_->GetView(id); 87 return root_node_manager_->GetView(id);
87 } 88 }
88 89
89 void ViewManagerConnection::SetRoots(const Array<TransportNodeId>& node_ids) { 90 void ViewManagerConnection::SetRoots(const Array<TransportNodeId>& node_ids) {
90 DCHECK_EQ(0, id_); // Only valid before connection established. 91 DCHECK(roots_.empty());
91 NodeIdSet roots; 92 NodeIdSet roots;
92 for (size_t i = 0; i < node_ids.size(); ++i) { 93 for (size_t i = 0; i < node_ids.size(); ++i) {
93 DCHECK(GetNode(NodeIdFromTransportId(node_ids[i]))); 94 DCHECK(GetNode(NodeIdFromTransportId(node_ids[i])));
94 roots.insert(node_ids[i]); 95 roots.insert(node_ids[i]);
95 } 96 }
96 roots_.swap(roots); 97 roots_.swap(roots);
97 } 98 }
98 99
99 void ViewManagerConnection::ProcessNodeBoundsChanged( 100 void ViewManagerConnection::ProcessNodeBoundsChanged(
100 const Node* node, 101 const Node* node,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } 192 }
192 193
193 void ViewManagerConnection::ProcessViewDeleted(const ViewId& view, 194 void ViewManagerConnection::ProcessViewDeleted(const ViewId& view,
194 bool originated_change) { 195 bool originated_change) {
195 if (originated_change) 196 if (originated_change)
196 return; 197 return;
197 client()->OnViewDeleted(ViewIdToTransportId(view)); 198 client()->OnViewDeleted(ViewIdToTransportId(view));
198 } 199 }
199 200
200 void ViewManagerConnection::OnConnectionError() { 201 void ViewManagerConnection::OnConnectionError() {
201 // TODO(sky): figure out if need to cleanup here if this 202 if (delete_on_connection_error_)
202 // ViewManagerConnection is the result of a Connect(). 203 delete this;
203 } 204 }
204 205
205 bool ViewManagerConnection::CanRemoveNodeFromParent(const Node* node) const { 206 bool ViewManagerConnection::CanRemoveNodeFromParent(const Node* node) const {
206 if (!node) 207 if (!node)
207 return false; 208 return false;
208 209
209 const Node* parent = node->GetParent(); 210 const Node* parent = node->GetParent();
210 if (!parent) 211 if (!parent)
211 return false; 212 return false;
212 213
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 root_node_manager_->ProcessNodeHierarchyChanged(node, new_parent, old_parent); 608 root_node_manager_->ProcessNodeHierarchyChanged(node, new_parent, old_parent);
608 } 609 }
609 610
610 void ViewManagerConnection::OnNodeViewReplaced(const Node* node, 611 void ViewManagerConnection::OnNodeViewReplaced(const Node* node,
611 const View* new_view, 612 const View* new_view,
612 const View* old_view) { 613 const View* old_view) {
613 root_node_manager_->ProcessNodeViewReplaced(node, new_view, old_view); 614 root_node_manager_->ProcessNodeViewReplaced(node, new_view, old_view);
614 } 615 }
615 616
616 void ViewManagerConnection::OnConnectionEstablished() { 617 void ViewManagerConnection::OnConnectionEstablished() {
617 DCHECK_EQ(0, id_); // Should only get OnConnectionEstablished() once.
618
619 id_ = root_node_manager_->GetAndAdvanceNextConnectionId();
620
621 root_node_manager_->AddConnection(this); 618 root_node_manager_->AddConnection(this);
622 619
623 std::vector<const Node*> to_send; 620 std::vector<const Node*> to_send;
624 if (roots_.empty()) { 621 if (roots_.empty()) {
625 GetUnknownNodesFrom(root_node_manager_->root(), &to_send); 622 GetUnknownNodesFrom(root_node_manager_->root(), &to_send);
626 } else { 623 } else {
627 for (NodeIdSet::const_iterator i = roots_.begin(); i != roots_.end(); ++i) 624 for (NodeIdSet::const_iterator i = roots_.begin(); i != roots_.end(); ++i)
628 GetUnknownNodesFrom(GetNode(NodeIdFromTransportId(*i)), &to_send); 625 GetUnknownNodesFrom(GetNode(NodeIdFromTransportId(*i)), &to_send);
629 } 626 }
630 627
631 client()->OnViewManagerConnectionEstablished( 628 client()->OnViewManagerConnectionEstablished(
632 id_, 629 id_,
633 root_node_manager_->next_server_change_id(), 630 root_node_manager_->next_server_change_id(),
634 NodesToINodes(to_send)); 631 NodesToINodes(to_send));
635 } 632 }
636 633
637 } // namespace service 634 } // namespace service
638 } // namespace view_manager 635 } // namespace view_manager
639 } // namespace mojo 636 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/view_manager/view_manager_connection.h ('k') | mojo/services/view_manager/view_manager_connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698