OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H_ |
| 6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_vector.h" |
| 10 #include "mojo/public/cpp/bindings/remote_ptr.h" |
| 11 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
| 12 |
| 13 namespace mojo { |
| 14 namespace services { |
| 15 namespace view_manager { |
| 16 |
| 17 class ViewManager; |
| 18 class ViewManagerTransaction; |
| 19 |
| 20 // Manages the connection with the View Manager service. |
| 21 class ViewManagerSynchronizer : public IViewManagerClient { |
| 22 public: |
| 23 explicit ViewManagerSynchronizer(ViewManager* view_manager); |
| 24 virtual ~ViewManagerSynchronizer(); |
| 25 |
| 26 // API exposed to the node implementation that pushes local changes to the |
| 27 // service. |
| 28 uint16_t CreateViewTreeNode(); |
| 29 void AddChild(uint16_t child_id, uint16_t parent_id); |
| 30 void RemoveChild(uint16_t child_id, uint16_t parent_id); |
| 31 |
| 32 private: |
| 33 friend class ViewManagerTransaction; |
| 34 typedef ScopedVector<ViewManagerTransaction> Transactions; |
| 35 |
| 36 // Overridden from IViewManagerClient: |
| 37 virtual void OnConnectionEstablished(uint16 connection_id) OVERRIDE; |
| 38 virtual void OnNodeHierarchyChanged(uint32 node, |
| 39 uint32 new_parent, |
| 40 uint32 old_parent, |
| 41 uint32 change_id) OVERRIDE; |
| 42 virtual void OnNodeViewReplaced(uint32_t node, |
| 43 uint32_t new_view_id, |
| 44 uint32_t old_view_id, |
| 45 uint32_t change_id) OVERRIDE; |
| 46 |
| 47 // Called to schedule a sync of the client model with the service after a |
| 48 // return to the message loop. |
| 49 void ScheduleSync(); |
| 50 |
| 51 // Sync the client model with the service by enumerating the pending |
| 52 // transaction queue and applying them in order. |
| 53 void DoSync(); |
| 54 |
| 55 // Used by individual transactions to generate a connection-specific change |
| 56 // id. |
| 57 // TODO(beng): What happens when there are more than sizeof(int) changes in |
| 58 // the queue? |
| 59 uint32_t GetNextChangeId(); |
| 60 |
| 61 // Removes |transaction| from the pending queue. |transaction| must be at the |
| 62 // front of the queue. |
| 63 void RemoveFromPendingQueue(ViewManagerTransaction* transaction); |
| 64 |
| 65 ViewManager* view_manager_; |
| 66 bool connected_; |
| 67 uint16_t connection_id_; |
| 68 uint16_t next_id_; |
| 69 uint32_t next_change_id_; |
| 70 |
| 71 Transactions pending_transactions_; |
| 72 |
| 73 RemotePtr<IViewManager> service_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(ViewManagerSynchronizer); |
| 76 }; |
| 77 |
| 78 } // namespace view_manager |
| 79 } // namespace services |
| 80 } // namespace mojo |
| 81 |
| 82 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H
_ |
OLD | NEW |