| 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_client_impl.h" | 5 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "mojo/public/cpp/application/application_connection.h" | 9 #include "mojo/public/cpp/application/application_connection.h" |
| 10 #include "mojo/public/cpp/application/connect.h" | 10 #include "mojo/public/cpp/application/connect.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 // Overridden to perform transaction-specific commit actions. | 127 // Overridden to perform transaction-specific commit actions. |
| 128 virtual void DoCommit() = 0; | 128 virtual void DoCommit() = 0; |
| 129 | 129 |
| 130 // Overridden to perform transaction-specific cleanup on commit ack from the | 130 // Overridden to perform transaction-specific cleanup on commit ack from the |
| 131 // service. | 131 // service. |
| 132 virtual void DoActionCompleted(bool success) = 0; | 132 virtual void DoActionCompleted(bool success) = 0; |
| 133 | 133 |
| 134 ViewManagerService* service() { return client_->service_; } | 134 ViewManagerService* service() { return client_->service_; } |
| 135 | 135 |
| 136 Id GetAndAdvanceNextServerChangeId() { | |
| 137 return client_->next_server_change_id_++; | |
| 138 } | |
| 139 | |
| 140 // TODO(sky): nuke this and covert all to new one, then rename | 136 // TODO(sky): nuke this and covert all to new one, then rename |
| 141 // ActionCompletedCallbackWithErrorCode to ActionCompletedCallback. | 137 // ActionCompletedCallbackWithErrorCode to ActionCompletedCallback. |
| 142 base::Callback<void(bool)> ActionCompletedCallback() { | 138 base::Callback<void(bool)> ActionCompletedCallback() { |
| 143 return base::Bind(&ViewManagerTransaction::OnActionCompleted, | 139 return base::Bind(&ViewManagerTransaction::OnActionCompleted, |
| 144 base::Unretained(this)); | 140 base::Unretained(this)); |
| 145 } | 141 } |
| 146 | 142 |
| 147 base::Callback<void(ErrorCode)> ActionCompletedCallbackWithErrorCode() { | 143 base::Callback<void(ErrorCode)> ActionCompletedCallbackWithErrorCode() { |
| 148 return base::Bind(&ViewManagerTransaction::OnActionCompletedWithErrorCode, | 144 return base::Bind(&ViewManagerTransaction::OnActionCompletedWithErrorCode, |
| 149 base::Unretained(this)); | 145 base::Unretained(this)); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 class DestroyNodeTransaction : public ViewManagerTransaction { | 235 class DestroyNodeTransaction : public ViewManagerTransaction { |
| 240 public: | 236 public: |
| 241 DestroyNodeTransaction(Id node_id, ViewManagerClientImpl* client) | 237 DestroyNodeTransaction(Id node_id, ViewManagerClientImpl* client) |
| 242 : ViewManagerTransaction(client), | 238 : ViewManagerTransaction(client), |
| 243 node_id_(node_id) {} | 239 node_id_(node_id) {} |
| 244 virtual ~DestroyNodeTransaction() {} | 240 virtual ~DestroyNodeTransaction() {} |
| 245 | 241 |
| 246 private: | 242 private: |
| 247 // Overridden from ViewManagerTransaction: | 243 // Overridden from ViewManagerTransaction: |
| 248 virtual void DoCommit() OVERRIDE { | 244 virtual void DoCommit() OVERRIDE { |
| 249 service()->DeleteNode(node_id_, | 245 service()->DeleteNode(node_id_, ActionCompletedCallback()); |
| 250 GetAndAdvanceNextServerChangeId(), | |
| 251 ActionCompletedCallback()); | |
| 252 } | 246 } |
| 253 virtual void DoActionCompleted(bool success) OVERRIDE { | 247 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 254 // TODO(beng): recovery? | 248 // TODO(beng): recovery? |
| 255 DCHECK(success); | 249 DCHECK(success); |
| 256 } | 250 } |
| 257 | 251 |
| 258 const Id node_id_; | 252 const Id node_id_; |
| 259 DISALLOW_COPY_AND_ASSIGN(DestroyNodeTransaction); | 253 DISALLOW_COPY_AND_ASSIGN(DestroyNodeTransaction); |
| 260 }; | 254 }; |
| 261 | 255 |
| 262 class AddChildTransaction : public ViewManagerTransaction { | 256 class AddChildTransaction : public ViewManagerTransaction { |
| 263 public: | 257 public: |
| 264 AddChildTransaction(Id child_id, | 258 AddChildTransaction(Id child_id, |
| 265 Id parent_id, | 259 Id parent_id, |
| 266 ViewManagerClientImpl* client) | 260 ViewManagerClientImpl* client) |
| 267 : ViewManagerTransaction(client), | 261 : ViewManagerTransaction(client), |
| 268 child_id_(child_id), | 262 child_id_(child_id), |
| 269 parent_id_(parent_id) {} | 263 parent_id_(parent_id) {} |
| 270 virtual ~AddChildTransaction() {} | 264 virtual ~AddChildTransaction() {} |
| 271 | 265 |
| 272 private: | 266 private: |
| 273 // Overridden from ViewManagerTransaction: | 267 // Overridden from ViewManagerTransaction: |
| 274 virtual void DoCommit() OVERRIDE { | 268 virtual void DoCommit() OVERRIDE { |
| 275 service()->AddNode(parent_id_, | 269 service()->AddNode(parent_id_, child_id_, ActionCompletedCallback()); |
| 276 child_id_, | |
| 277 GetAndAdvanceNextServerChangeId(), | |
| 278 ActionCompletedCallback()); | |
| 279 } | 270 } |
| 280 | 271 |
| 281 virtual void DoActionCompleted(bool success) OVERRIDE { | 272 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 282 // TODO(beng): recovery? | 273 // TODO(beng): recovery? |
| 283 DCHECK(success); | 274 DCHECK(success); |
| 284 } | 275 } |
| 285 | 276 |
| 286 const Id child_id_; | 277 const Id child_id_; |
| 287 const Id parent_id_; | 278 const Id parent_id_; |
| 288 | 279 |
| 289 DISALLOW_COPY_AND_ASSIGN(AddChildTransaction); | 280 DISALLOW_COPY_AND_ASSIGN(AddChildTransaction); |
| 290 }; | 281 }; |
| 291 | 282 |
| 292 class RemoveChildTransaction : public ViewManagerTransaction { | 283 class RemoveChildTransaction : public ViewManagerTransaction { |
| 293 public: | 284 public: |
| 294 RemoveChildTransaction(Id child_id, ViewManagerClientImpl* client) | 285 RemoveChildTransaction(Id child_id, ViewManagerClientImpl* client) |
| 295 : ViewManagerTransaction(client), | 286 : ViewManagerTransaction(client), |
| 296 child_id_(child_id) {} | 287 child_id_(child_id) {} |
| 297 virtual ~RemoveChildTransaction() {} | 288 virtual ~RemoveChildTransaction() {} |
| 298 | 289 |
| 299 private: | 290 private: |
| 300 // Overridden from ViewManagerTransaction: | 291 // Overridden from ViewManagerTransaction: |
| 301 virtual void DoCommit() OVERRIDE { | 292 virtual void DoCommit() OVERRIDE { |
| 302 service()->RemoveNodeFromParent( | 293 service()->RemoveNodeFromParent(child_id_, ActionCompletedCallback()); |
| 303 child_id_, | |
| 304 GetAndAdvanceNextServerChangeId(), | |
| 305 ActionCompletedCallback()); | |
| 306 } | 294 } |
| 307 | 295 |
| 308 virtual void DoActionCompleted(bool success) OVERRIDE { | 296 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 309 // TODO(beng): recovery? | 297 // TODO(beng): recovery? |
| 310 DCHECK(success); | 298 DCHECK(success); |
| 311 } | 299 } |
| 312 | 300 |
| 313 const Id child_id_; | 301 const Id child_id_; |
| 314 | 302 |
| 315 DISALLOW_COPY_AND_ASSIGN(RemoveChildTransaction); | 303 DISALLOW_COPY_AND_ASSIGN(RemoveChildTransaction); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 326 relative_id_(relative_id), | 314 relative_id_(relative_id), |
| 327 direction_(direction) {} | 315 direction_(direction) {} |
| 328 virtual ~ReorderNodeTransaction() {} | 316 virtual ~ReorderNodeTransaction() {} |
| 329 | 317 |
| 330 private: | 318 private: |
| 331 // Overridden from ViewManagerTransaction: | 319 // Overridden from ViewManagerTransaction: |
| 332 virtual void DoCommit() OVERRIDE { | 320 virtual void DoCommit() OVERRIDE { |
| 333 service()->ReorderNode(node_id_, | 321 service()->ReorderNode(node_id_, |
| 334 relative_id_, | 322 relative_id_, |
| 335 direction_, | 323 direction_, |
| 336 GetAndAdvanceNextServerChangeId(), | |
| 337 ActionCompletedCallback()); | 324 ActionCompletedCallback()); |
| 338 } | 325 } |
| 339 | 326 |
| 340 virtual void DoActionCompleted(bool success) OVERRIDE { | 327 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 341 // TODO(beng): recovery? | 328 // TODO(beng): recovery? |
| 342 DCHECK(success); | 329 DCHECK(success); |
| 343 } | 330 } |
| 344 | 331 |
| 345 const Id node_id_; | 332 const Id node_id_; |
| 346 const Id relative_id_; | 333 const Id relative_id_; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 Id node_id, | 458 Id node_id, |
| 472 ViewManagerClientImpl* client) | 459 ViewManagerClientImpl* client) |
| 473 : ViewManagerTransaction(client), | 460 : ViewManagerTransaction(client), |
| 474 url_(url), | 461 url_(url), |
| 475 node_id_(node_id) {} | 462 node_id_(node_id) {} |
| 476 virtual ~EmbedTransaction() {} | 463 virtual ~EmbedTransaction() {} |
| 477 | 464 |
| 478 private: | 465 private: |
| 479 // Overridden from ViewManagerTransaction: | 466 // Overridden from ViewManagerTransaction: |
| 480 virtual void DoCommit() OVERRIDE { | 467 virtual void DoCommit() OVERRIDE { |
| 481 GetAndAdvanceNextServerChangeId(); | |
| 482 service()->Embed(url_, node_id_, ActionCompletedCallback()); | 468 service()->Embed(url_, node_id_, ActionCompletedCallback()); |
| 483 } | 469 } |
| 484 virtual void DoActionCompleted(bool success) OVERRIDE { | 470 virtual void DoActionCompleted(bool success) OVERRIDE { |
| 485 // TODO(beng): recovery? | 471 // TODO(beng): recovery? |
| 486 } | 472 } |
| 487 | 473 |
| 488 const String url_; | 474 const String url_; |
| 489 const Id node_id_; | 475 const Id node_id_; |
| 490 | 476 |
| 491 DISALLOW_COPY_AND_ASSIGN(EmbedTransaction); | 477 DISALLOW_COPY_AND_ASSIGN(EmbedTransaction); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 const bool visible_; | 521 const bool visible_; |
| 536 | 522 |
| 537 DISALLOW_COPY_AND_ASSIGN(SetVisibleTransaction); | 523 DISALLOW_COPY_AND_ASSIGN(SetVisibleTransaction); |
| 538 }; | 524 }; |
| 539 | 525 |
| 540 ViewManagerClientImpl::ViewManagerClientImpl(ApplicationConnection* connection, | 526 ViewManagerClientImpl::ViewManagerClientImpl(ApplicationConnection* connection, |
| 541 ViewManagerDelegate* delegate) | 527 ViewManagerDelegate* delegate) |
| 542 : connected_(false), | 528 : connected_(false), |
| 543 connection_id_(0), | 529 connection_id_(0), |
| 544 next_id_(1), | 530 next_id_(1), |
| 545 next_server_change_id_(0), | |
| 546 delegate_(delegate), | 531 delegate_(delegate), |
| 547 dispatcher_(NULL) {} | 532 dispatcher_(NULL) {} |
| 548 | 533 |
| 549 ViewManagerClientImpl::~ViewManagerClientImpl() { | 534 ViewManagerClientImpl::~ViewManagerClientImpl() { |
| 550 delegate_->OnViewManagerDisconnected(this); | 535 delegate_->OnViewManagerDisconnected(this); |
| 551 while (!nodes_.empty()) { | 536 while (!nodes_.empty()) { |
| 552 IdToNodeMap::iterator it = nodes_.begin(); | 537 IdToNodeMap::iterator it = nodes_.begin(); |
| 553 if (OwnsNode(it->second->id())) | 538 if (OwnsNode(it->second->id())) |
| 554 it->second->Destroy(); | 539 it->second->Destroy(); |
| 555 else | 540 else |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 void ViewManagerClientImpl::OnConnectionEstablished() { | 711 void ViewManagerClientImpl::OnConnectionEstablished() { |
| 727 service_ = client(); | 712 service_ = client(); |
| 728 } | 713 } |
| 729 | 714 |
| 730 //////////////////////////////////////////////////////////////////////////////// | 715 //////////////////////////////////////////////////////////////////////////////// |
| 731 // ViewManagerClientImpl, ViewManagerClient implementation: | 716 // ViewManagerClientImpl, ViewManagerClient implementation: |
| 732 | 717 |
| 733 void ViewManagerClientImpl::OnViewManagerConnectionEstablished( | 718 void ViewManagerClientImpl::OnViewManagerConnectionEstablished( |
| 734 ConnectionSpecificId connection_id, | 719 ConnectionSpecificId connection_id, |
| 735 const String& creator_url, | 720 const String& creator_url, |
| 736 Id next_server_change_id, | |
| 737 Array<NodeDataPtr> nodes) { | 721 Array<NodeDataPtr> nodes) { |
| 738 connected_ = true; | 722 connected_ = true; |
| 739 connection_id_ = connection_id; | 723 connection_id_ = connection_id; |
| 740 creator_url_ = TypeConverter<String, std::string>::ConvertFrom(creator_url); | 724 creator_url_ = TypeConverter<String, std::string>::ConvertFrom(creator_url); |
| 741 next_server_change_id_ = next_server_change_id; | |
| 742 | 725 |
| 743 DCHECK(pending_transactions_.empty()); | 726 DCHECK(pending_transactions_.empty()); |
| 744 AddRoot(BuildNodeTree(this, nodes)); | 727 AddRoot(BuildNodeTree(this, nodes)); |
| 745 } | 728 } |
| 746 | 729 |
| 747 void ViewManagerClientImpl::OnRootAdded(Array<NodeDataPtr> nodes) { | 730 void ViewManagerClientImpl::OnRootAdded(Array<NodeDataPtr> nodes) { |
| 748 AddRoot(BuildNodeTree(this, nodes)); | 731 AddRoot(BuildNodeTree(this, nodes)); |
| 749 } | 732 } |
| 750 | 733 |
| 751 void ViewManagerClientImpl::OnServerChangeIdAdvanced( | |
| 752 Id next_server_change_id) { | |
| 753 next_server_change_id_ = next_server_change_id; | |
| 754 } | |
| 755 | |
| 756 void ViewManagerClientImpl::OnNodeBoundsChanged(Id node_id, | 734 void ViewManagerClientImpl::OnNodeBoundsChanged(Id node_id, |
| 757 RectPtr old_bounds, | 735 RectPtr old_bounds, |
| 758 RectPtr new_bounds) { | 736 RectPtr new_bounds) { |
| 759 Node* node = GetNodeById(node_id); | 737 Node* node = GetNodeById(node_id); |
| 760 NodePrivate(node).LocalSetBounds(old_bounds.To<gfx::Rect>(), | 738 NodePrivate(node).LocalSetBounds(old_bounds.To<gfx::Rect>(), |
| 761 new_bounds.To<gfx::Rect>()); | 739 new_bounds.To<gfx::Rect>()); |
| 762 } | 740 } |
| 763 | 741 |
| 764 void ViewManagerClientImpl::OnNodeHierarchyChanged( | 742 void ViewManagerClientImpl::OnNodeHierarchyChanged( |
| 765 Id node_id, | 743 Id node_id, |
| 766 Id new_parent_id, | 744 Id new_parent_id, |
| 767 Id old_parent_id, | 745 Id old_parent_id, |
| 768 Id server_change_id, | |
| 769 mojo::Array<NodeDataPtr> nodes) { | 746 mojo::Array<NodeDataPtr> nodes) { |
| 770 next_server_change_id_ = server_change_id + 1; | |
| 771 | |
| 772 BuildNodeTree(this, nodes); | 747 BuildNodeTree(this, nodes); |
| 773 | 748 |
| 774 Node* new_parent = GetNodeById(new_parent_id); | 749 Node* new_parent = GetNodeById(new_parent_id); |
| 775 Node* old_parent = GetNodeById(old_parent_id); | 750 Node* old_parent = GetNodeById(old_parent_id); |
| 776 Node* node = GetNodeById(node_id); | 751 Node* node = GetNodeById(node_id); |
| 777 if (new_parent) | 752 if (new_parent) |
| 778 NodePrivate(new_parent).LocalAddChild(node); | 753 NodePrivate(new_parent).LocalAddChild(node); |
| 779 else | 754 else |
| 780 NodePrivate(old_parent).LocalRemoveChild(node); | 755 NodePrivate(old_parent).LocalRemoveChild(node); |
| 781 } | 756 } |
| 782 | 757 |
| 783 void ViewManagerClientImpl::OnNodeReordered(Id node_id, | 758 void ViewManagerClientImpl::OnNodeReordered(Id node_id, |
| 784 Id relative_node_id, | 759 Id relative_node_id, |
| 785 OrderDirection direction, | 760 OrderDirection direction) { |
| 786 Id server_change_id) { | |
| 787 next_server_change_id_ = server_change_id + 1; | |
| 788 | |
| 789 Node* node = GetNodeById(node_id); | 761 Node* node = GetNodeById(node_id); |
| 790 Node* relative_node = GetNodeById(relative_node_id); | 762 Node* relative_node = GetNodeById(relative_node_id); |
| 791 if (node && relative_node) { | 763 if (node && relative_node) |
| 792 NodePrivate(node).LocalReorder(relative_node, direction); | 764 NodePrivate(node).LocalReorder(relative_node, direction); |
| 793 } | |
| 794 } | 765 } |
| 795 | 766 |
| 796 void ViewManagerClientImpl::OnNodeDeleted(Id node_id, Id server_change_id) { | 767 void ViewManagerClientImpl::OnNodeDeleted(Id node_id) { |
| 797 next_server_change_id_ = server_change_id + 1; | |
| 798 | |
| 799 Node* node = GetNodeById(node_id); | 768 Node* node = GetNodeById(node_id); |
| 800 if (node) | 769 if (node) |
| 801 NodePrivate(node).LocalDestroy(); | 770 NodePrivate(node).LocalDestroy(); |
| 802 } | 771 } |
| 803 | 772 |
| 804 void ViewManagerClientImpl::OnNodeViewReplaced(Id node_id, | 773 void ViewManagerClientImpl::OnNodeViewReplaced(Id node_id, |
| 805 Id new_view_id, | 774 Id new_view_id, |
| 806 Id old_view_id) { | 775 Id old_view_id) { |
| 807 Node* node = GetNodeById(node_id); | 776 Node* node = GetNodeById(node_id); |
| 808 View* new_view = GetViewById(new_view_id); | 777 View* new_view = GetViewById(new_view_id); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 | 878 |
| 910 // static | 879 // static |
| 911 void ViewManager::ConfigureIncomingConnection( | 880 void ViewManager::ConfigureIncomingConnection( |
| 912 ApplicationConnection* connection, | 881 ApplicationConnection* connection, |
| 913 ViewManagerDelegate* delegate) { | 882 ViewManagerDelegate* delegate) { |
| 914 connection->AddService<ViewManagerClientImpl>(delegate); | 883 connection->AddService<ViewManagerClientImpl>(delegate); |
| 915 } | 884 } |
| 916 | 885 |
| 917 } // namespace view_manager | 886 } // namespace view_manager |
| 918 } // namespace mojo | 887 } // namespace mojo |
| OLD | NEW |