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

Side by Side Diff: mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.cc

Issue 294833002: Mojo: more idiomatic C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows bustage 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/public/cpp/view_manager/lib/view_manager_synchronizer.h" 5 #include "mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "mojo/public/cpp/shell/connect.h" 9 #include "mojo/public/cpp/shell/connect.h"
10 #include "mojo/public/interfaces/shell/shell.mojom.h" 10 #include "mojo/public/interfaces/shell/shell.mojom.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 private_view.set_node(node); 47 private_view.set_node(node);
48 // TODO(beng): this broadcasts notifications locally... do we want this? I 48 // TODO(beng): this broadcasts notifications locally... do we want this? I
49 // don't think so. same story for LocalAddChild above! 49 // don't think so. same story for LocalAddChild above!
50 private_node.LocalSetActiveView(view); 50 private_node.LocalSetActiveView(view);
51 private_manager.AddView(view->id(), view); 51 private_manager.AddView(view->id(), view);
52 } 52 }
53 return node; 53 return node;
54 } 54 }
55 55
56 ViewTreeNode* BuildNodeTree(ViewManager* manager, 56 ViewTreeNode* BuildNodeTree(ViewManager* manager,
57 const Array<INode>& nodes) { 57 const Array<INodePtr>& nodes) {
58 std::vector<ViewTreeNode*> parents; 58 std::vector<ViewTreeNode*> parents;
59 ViewTreeNode* root = NULL; 59 ViewTreeNode* root = NULL;
60 ViewTreeNode* last_node = NULL; 60 ViewTreeNode* last_node = NULL;
61 for (size_t i = 0; i < nodes.size(); ++i) { 61 for (size_t i = 0; i < nodes.size(); ++i) {
62 if (last_node && nodes[i].parent_id() == last_node->id()) { 62 if (last_node && nodes[i]->parent_id == last_node->id()) {
63 parents.push_back(last_node); 63 parents.push_back(last_node);
64 } else if (!parents.empty()) { 64 } else if (!parents.empty()) {
65 while (parents.back()->id() != nodes[i].parent_id()) 65 while (parents.back()->id() != nodes[i]->parent_id)
66 parents.pop_back(); 66 parents.pop_back();
67 } 67 }
68 ViewTreeNode* node = AddNodeToViewManager( 68 ViewTreeNode* node = AddNodeToViewManager(
69 manager, 69 manager,
70 !parents.empty() ? parents.back() : NULL, 70 !parents.empty() ? parents.back() : NULL,
71 nodes[i].node_id(), 71 nodes[i]->node_id,
72 nodes[i].view_id()); 72 nodes[i]->view_id);
73 if (!last_node) 73 if (!last_node)
74 root = node; 74 root = node;
75 last_node = node; 75 last_node = node;
76 } 76 }
77 return root; 77 return root;
78 } 78 }
79 79
80 class ViewManagerTransaction { 80 class ViewManagerTransaction {
81 public: 81 public:
82 virtual ~ViewManagerTransaction() {} 82 virtual ~ViewManagerTransaction() {}
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 const gfx::Rect& bounds, 317 const gfx::Rect& bounds,
318 ViewManagerSynchronizer* synchronizer) 318 ViewManagerSynchronizer* synchronizer)
319 : ViewManagerTransaction(TYPE_SET_BOUNDS, synchronizer), 319 : ViewManagerTransaction(TYPE_SET_BOUNDS, synchronizer),
320 node_id_(node_id), 320 node_id_(node_id),
321 bounds_(bounds) {} 321 bounds_(bounds) {}
322 virtual ~SetBoundsTransaction() {} 322 virtual ~SetBoundsTransaction() {}
323 323
324 private: 324 private:
325 // Overridden from ViewManagerTransaction: 325 // Overridden from ViewManagerTransaction:
326 virtual void DoCommit() OVERRIDE { 326 virtual void DoCommit() OVERRIDE {
327 AllocationScope scope; 327 service()->SetNodeBounds(
328 service()->SetNodeBounds(node_id_, bounds_, ActionCompletedCallback()); 328 node_id_, Rect::From(bounds_), ActionCompletedCallback());
329 } 329 }
330 virtual void DoActionCompleted(bool success) OVERRIDE { 330 virtual void DoActionCompleted(bool success) OVERRIDE {
331 // TODO(beng): recovery? 331 // TODO(beng): recovery?
332 } 332 }
333 333
334 const TransportNodeId node_id_; 334 const TransportNodeId node_id_;
335 const gfx::Rect bounds_; 335 const gfx::Rect bounds_;
336 336
337 DISALLOW_COPY_AND_ASSIGN(SetBoundsTransaction); 337 DISALLOW_COPY_AND_ASSIGN(SetBoundsTransaction);
338 }; 338 };
(...skipping 18 matching lines...) Expand all
357 ScopedSharedBufferHandle duped; 357 ScopedSharedBufferHandle duped;
358 bool result = CreateMapAndDupSharedBuffer(data.size(), 358 bool result = CreateMapAndDupSharedBuffer(data.size(),
359 &memory, 359 &memory,
360 &shared_state_handle_, 360 &shared_state_handle_,
361 &duped); 361 &duped);
362 if (!result) 362 if (!result)
363 return; 363 return;
364 364
365 memcpy(memory, &data[0], data.size()); 365 memcpy(memory, &data[0], data.size());
366 366
367 AllocationScope scope;
368 service()->SetViewContents(view_id_, duped.Pass(), 367 service()->SetViewContents(view_id_, duped.Pass(),
369 static_cast<uint32_t>(data.size()), 368 static_cast<uint32_t>(data.size()),
370 ActionCompletedCallback()); 369 ActionCompletedCallback());
371 } 370 }
372 virtual void DoActionCompleted(bool success) OVERRIDE { 371 virtual void DoActionCompleted(bool success) OVERRIDE {
373 // TODO(beng): recovery? 372 // TODO(beng): recovery?
374 } 373 }
375 374
376 bool CreateMapAndDupSharedBuffer(size_t size, 375 bool CreateMapAndDupSharedBuffer(size_t size,
377 void** memory, 376 void** memory,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 new SetViewContentsTransaction(view_id, contents, this)); 511 new SetViewContentsTransaction(view_id, contents, this));
513 Sync(); 512 Sync();
514 } 513 }
515 514
516 //////////////////////////////////////////////////////////////////////////////// 515 ////////////////////////////////////////////////////////////////////////////////
517 // ViewManagerSynchronizer, IViewManagerClient implementation: 516 // ViewManagerSynchronizer, IViewManagerClient implementation:
518 517
519 void ViewManagerSynchronizer::OnViewManagerConnectionEstablished( 518 void ViewManagerSynchronizer::OnViewManagerConnectionEstablished(
520 TransportConnectionId connection_id, 519 TransportConnectionId connection_id,
521 TransportChangeId next_server_change_id, 520 TransportChangeId next_server_change_id,
522 const Array<INode>& nodes) { 521 mojo::Array<INodePtr> nodes) {
523 connected_ = true; 522 connected_ = true;
524 connection_id_ = connection_id; 523 connection_id_ = connection_id;
525 next_server_change_id_ = next_server_change_id; 524 next_server_change_id_ = next_server_change_id;
526 525
527 ViewManagerPrivate(view_manager_).set_root( 526 ViewManagerPrivate(view_manager_).set_root(
528 BuildNodeTree(view_manager_, nodes)); 527 BuildNodeTree(view_manager_, nodes));
529 if (init_loop_) 528 if (init_loop_)
530 init_loop_->Quit(); 529 init_loop_->Quit();
531 530
532 Sync(); 531 Sync();
533 } 532 }
534 533
535 void ViewManagerSynchronizer::OnServerChangeIdAdvanced( 534 void ViewManagerSynchronizer::OnServerChangeIdAdvanced(
536 uint32_t next_server_change_id) { 535 uint32_t next_server_change_id) {
537 next_server_change_id_ = next_server_change_id; 536 next_server_change_id_ = next_server_change_id;
538 } 537 }
539 538
540 void ViewManagerSynchronizer::OnNodeBoundsChanged(uint32 node_id, 539 void ViewManagerSynchronizer::OnNodeBoundsChanged(uint32 node_id,
541 const Rect& old_bounds, 540 RectPtr old_bounds,
542 const Rect& new_bounds) { 541 RectPtr new_bounds) {
543 ViewTreeNode* node = view_manager_->GetNodeById(node_id); 542 ViewTreeNode* node = view_manager_->GetNodeById(node_id);
544 ViewTreeNodePrivate(node).LocalSetBounds(old_bounds, new_bounds); 543 ViewTreeNodePrivate(node).LocalSetBounds(old_bounds.To<gfx::Rect>(),
544 new_bounds.To<gfx::Rect>());
545 } 545 }
546 546
547 void ViewManagerSynchronizer::OnNodeHierarchyChanged( 547 void ViewManagerSynchronizer::OnNodeHierarchyChanged(
548 uint32_t node_id, 548 uint32_t node_id,
549 uint32_t new_parent_id, 549 uint32_t new_parent_id,
550 uint32_t old_parent_id, 550 uint32_t old_parent_id,
551 TransportChangeId server_change_id, 551 TransportChangeId server_change_id,
552 const Array<INode>& nodes) { 552 mojo::Array<INodePtr> nodes) {
553 // TODO: deal with |nodes|. 553 // TODO: deal with |nodes|.
554 next_server_change_id_ = server_change_id + 1; 554 next_server_change_id_ = server_change_id + 1;
555 555
556 BuildNodeTree(view_manager_, nodes); 556 BuildNodeTree(view_manager_, nodes);
557 557
558 ViewTreeNode* new_parent = view_manager_->GetNodeById(new_parent_id); 558 ViewTreeNode* new_parent = view_manager_->GetNodeById(new_parent_id);
559 ViewTreeNode* old_parent = view_manager_->GetNodeById(old_parent_id); 559 ViewTreeNode* old_parent = view_manager_->GetNodeById(old_parent_id);
560 ViewTreeNode* node = view_manager_->GetNodeById(node_id); 560 ViewTreeNode* node = view_manager_->GetNodeById(node_id);
561 if (new_parent) 561 if (new_parent)
562 ViewTreeNodePrivate(new_parent).LocalAddChild(node); 562 ViewTreeNodePrivate(new_parent).LocalAddChild(node);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 void ViewManagerSynchronizer::RemoveFromPendingQueue( 617 void ViewManagerSynchronizer::RemoveFromPendingQueue(
618 ViewManagerTransaction* transaction) { 618 ViewManagerTransaction* transaction) {
619 DCHECK_EQ(transaction, pending_transactions_.front()); 619 DCHECK_EQ(transaction, pending_transactions_.front());
620 pending_transactions_.erase(pending_transactions_.begin()); 620 pending_transactions_.erase(pending_transactions_.begin());
621 if (pending_transactions_.empty() && !changes_acked_callback_.is_null()) 621 if (pending_transactions_.empty() && !changes_acked_callback_.is_null())
622 changes_acked_callback_.Run(); 622 changes_acked_callback_.Run();
623 } 623 }
624 624
625 } // namespace view_manager 625 } // namespace view_manager
626 } // namespace mojo 626 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698