| 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/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/service.h" | 9 #include "mojo/public/cpp/shell/service.h" |
| 10 #include "mojo/public/interfaces/shell/shell.mojom.h" | 10 #include "mojo/public/interfaces/shell/shell.mojom.h" |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 connected_(false), | 299 connected_(false), |
| 300 connection_id_(0), | 300 connection_id_(0), |
| 301 next_id_(1), | 301 next_id_(1), |
| 302 next_server_change_id_(0), | 302 next_server_change_id_(0), |
| 303 sync_factory_(this), | 303 sync_factory_(this), |
| 304 init_loop_(NULL) { | 304 init_loop_(NULL) { |
| 305 ConnectTo(ViewManagerPrivate(view_manager_).shell(), "mojo:mojo_view_manager", | 305 ConnectTo(ViewManagerPrivate(view_manager_).shell(), "mojo:mojo_view_manager", |
| 306 &service_); | 306 &service_); |
| 307 service_->SetClient(this); | 307 service_->SetClient(this); |
| 308 | 308 |
| 309 AllocationScope scope; | 309 // Start a runloop. This loop is quit when the server tells us about the |
| 310 service_->GetNodeTree( | 310 // connection (OnConnectionEstablished()). |
| 311 1, | |
| 312 base::Bind(&ViewManagerSynchronizer::OnRootTreeReceived, | |
| 313 base::Unretained(this))); | |
| 314 | |
| 315 base::RunLoop loop; | 311 base::RunLoop loop; |
| 316 init_loop_ = &loop; | 312 init_loop_ = &loop; |
| 317 init_loop_->Run(); | 313 init_loop_->Run(); |
| 318 init_loop_ = NULL; | 314 init_loop_ = NULL; |
| 319 } | 315 } |
| 320 | 316 |
| 321 ViewManagerSynchronizer::~ViewManagerSynchronizer() { | 317 ViewManagerSynchronizer::~ViewManagerSynchronizer() { |
| 322 Sync(); | 318 Sync(); |
| 323 } | 319 } |
| 324 | 320 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 pending_transactions_.push_back( | 386 pending_transactions_.push_back( |
| 391 new SetActiveViewTransaction(node_id, view_id, this)); | 387 new SetActiveViewTransaction(node_id, view_id, this)); |
| 392 Sync(); | 388 Sync(); |
| 393 } | 389 } |
| 394 | 390 |
| 395 //////////////////////////////////////////////////////////////////////////////// | 391 //////////////////////////////////////////////////////////////////////////////// |
| 396 // ViewManagerSynchronizer, IViewManagerClient implementation: | 392 // ViewManagerSynchronizer, IViewManagerClient implementation: |
| 397 | 393 |
| 398 void ViewManagerSynchronizer::OnConnectionEstablished( | 394 void ViewManagerSynchronizer::OnConnectionEstablished( |
| 399 TransportConnectionId connection_id, | 395 TransportConnectionId connection_id, |
| 400 TransportChangeId next_server_change_id) { | 396 TransportChangeId next_server_change_id, |
| 397 const mojo::Array<INode>& nodes) { |
| 401 connected_ = true; | 398 connected_ = true; |
| 402 connection_id_ = connection_id; | 399 connection_id_ = connection_id; |
| 403 next_server_change_id_ = next_server_change_id; | 400 next_server_change_id_ = next_server_change_id; |
| 401 |
| 402 ViewManagerPrivate private_manager(view_manager_); |
| 403 std::vector<ViewTreeNode*> parents; |
| 404 ViewTreeNode* root = NULL; |
| 405 ViewTreeNode* last_node = NULL; |
| 406 for (size_t i = 0; i < nodes.size(); ++i) { |
| 407 if (last_node && nodes[i].parent_id() == last_node->id()) { |
| 408 parents.push_back(last_node); |
| 409 } else if (!parents.empty()) { |
| 410 while (parents.back()->id() != nodes[i].parent_id()) |
| 411 parents.pop_back(); |
| 412 } |
| 413 ViewTreeNode* node = |
| 414 AddNodeToViewManager(view_manager_, |
| 415 !parents.empty() ? parents.back() : NULL, |
| 416 nodes[i].node_id(), |
| 417 nodes[i].view_id()); |
| 418 if (!last_node) |
| 419 root = node; |
| 420 last_node = node; |
| 421 } |
| 422 private_manager.set_root(root); |
| 423 if (init_loop_) |
| 424 init_loop_->Quit(); |
| 425 |
| 404 Sync(); | 426 Sync(); |
| 405 } | 427 } |
| 406 | 428 |
| 429 void ViewManagerSynchronizer::OnServerChangeIdAdvanced( |
| 430 uint32_t next_server_change_id) { |
| 431 next_server_change_id_ = next_server_change_id; |
| 432 } |
| 433 |
| 407 void ViewManagerSynchronizer::OnNodeHierarchyChanged( | 434 void ViewManagerSynchronizer::OnNodeHierarchyChanged( |
| 408 uint32_t node_id, | 435 uint32_t node_id, |
| 409 uint32_t new_parent_id, | 436 uint32_t new_parent_id, |
| 410 uint32_t old_parent_id, | 437 uint32_t old_parent_id, |
| 411 TransportChangeId server_change_id) { | 438 TransportChangeId server_change_id, |
| 439 const mojo::Array<INode>& nodes) { |
| 440 // TODO: deal with |nodes|. |
| 412 next_server_change_id_ = server_change_id + 1; | 441 next_server_change_id_ = server_change_id + 1; |
| 413 | 442 |
| 414 ViewTreeNode* new_parent = | 443 ViewTreeNode* new_parent = |
| 415 view_manager_->tree()->GetChildById(new_parent_id); | 444 view_manager_->tree()->GetChildById(new_parent_id); |
| 416 ViewTreeNode* old_parent = | 445 ViewTreeNode* old_parent = |
| 417 view_manager_->tree()->GetChildById(old_parent_id); | 446 view_manager_->tree()->GetChildById(old_parent_id); |
| 418 ViewTreeNode* node = NULL; | 447 ViewTreeNode* node = NULL; |
| 419 if (old_parent) { | 448 if (old_parent) { |
| 420 // Existing node, mapped in this connection's tree. | 449 // Existing node, mapped in this connection's tree. |
| 421 // TODO(beng): verify this is actually true. | 450 // TODO(beng): verify this is actually true. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 (*it)->Commit(); | 515 (*it)->Commit(); |
| 487 } | 516 } |
| 488 } | 517 } |
| 489 | 518 |
| 490 void ViewManagerSynchronizer::RemoveFromPendingQueue( | 519 void ViewManagerSynchronizer::RemoveFromPendingQueue( |
| 491 ViewManagerTransaction* transaction) { | 520 ViewManagerTransaction* transaction) { |
| 492 DCHECK_EQ(transaction, pending_transactions_.front()); | 521 DCHECK_EQ(transaction, pending_transactions_.front()); |
| 493 pending_transactions_.erase(pending_transactions_.begin()); | 522 pending_transactions_.erase(pending_transactions_.begin()); |
| 494 } | 523 } |
| 495 | 524 |
| 496 void ViewManagerSynchronizer::OnRootTreeReceived( | |
| 497 const Array<INode>& nodes) { | |
| 498 ViewManagerPrivate private_manager(view_manager_); | |
| 499 std::vector<ViewTreeNode*> parents; | |
| 500 ViewTreeNode* root = NULL; | |
| 501 ViewTreeNode* last_node = NULL; | |
| 502 for (size_t i = 0; i < nodes.size(); ++i) { | |
| 503 if (last_node && nodes[i].parent_id() == last_node->id()) { | |
| 504 parents.push_back(last_node); | |
| 505 } else if (!parents.empty()) { | |
| 506 while (parents.back()->id() != nodes[i].parent_id()) | |
| 507 parents.pop_back(); | |
| 508 } | |
| 509 ViewTreeNode* node = | |
| 510 AddNodeToViewManager(view_manager_, | |
| 511 !parents.empty() ? parents.back() : NULL, | |
| 512 nodes[i].node_id(), | |
| 513 nodes[i].view_id()); | |
| 514 if (!last_node) | |
| 515 root = node; | |
| 516 last_node = node; | |
| 517 } | |
| 518 private_manager.set_root(root); | |
| 519 if (init_loop_) | |
| 520 init_loop_->Quit(); | |
| 521 } | |
| 522 | |
| 523 } // namespace view_manager | 525 } // namespace view_manager |
| 524 } // namespace mojo | 526 } // namespace mojo |
| OLD | NEW |