Index: mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h |
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2a81724b81f833b876623c90920c0503044f1924 |
--- /dev/null |
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_synchronizer.h |
@@ -0,0 +1,82 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H_ |
+#define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H_ |
+ |
+#include "base/basictypes.h" |
+#include "base/memory/scoped_vector.h" |
+#include "mojo/public/cpp/bindings/remote_ptr.h" |
+#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
+ |
+namespace mojo { |
+namespace services { |
+namespace view_manager { |
+ |
+class ViewManager; |
+class ViewManagerTransaction; |
+ |
+// Manages the connection with the View Manager service. |
+class ViewManagerSynchronizer : public IViewManagerClient { |
+ public: |
+ explicit ViewManagerSynchronizer(ViewManager* view_manager); |
+ virtual ~ViewManagerSynchronizer(); |
+ |
+ // API exposed to the node implementation that pushes local changes to the |
+ // service. |
+ int CreateViewTreeNode(); |
+ void AddChild(int child_id, int parent_id); |
+ void RemoveChild(int child_id, int parent_id); |
+ |
+ private: |
+ friend class ViewManagerTransaction; |
+ typedef ScopedVector<ViewManagerTransaction> Transactions; |
+ |
+ // Overridden from IViewManagerClient: |
+ virtual void OnConnectionEstablished(uint16 connection_id) OVERRIDE; |
+ virtual void OnNodeHierarchyChanged(uint32 node, |
+ uint32 new_parent, |
+ uint32 old_parent, |
+ int32 change_id) OVERRIDE; |
+ virtual void OnNodeViewReplaced(uint32_t node, |
+ uint32_t new_view_id, |
+ uint32_t old_view_id, |
+ int32_t change_id) OVERRIDE; |
+ |
+ // Called to schedule a sync of the client model with the service after a |
+ // return to the message loop. |
+ void ScheduleSync(); |
+ |
+ // Sync the client model with the service by enumerating the pending |
+ // transaction queue and applying them in order. |
+ void DoSync(); |
+ |
+ // Used by individual transactions to generate a connection-specific change |
+ // id. |
+ // TODO(beng): What happens when there are more than sizeof(int) changes in |
+ // the queue? |
+ int GetNextChangeId(); |
sky
2014/04/29 04:14:06
uint32_t
|
+ |
+ // Removes |transaction| from the pending queue. |transaction| must be at the |
+ // front of the queue. |
+ void RemoveFromPendingQueue(ViewManagerTransaction* transaction); |
+ |
+ ViewManager* view_manager_; |
+ bool connected_; |
+ uint16_t connection_id_; |
+ uint16_t next_id_; |
+ uint32_t next_change_id_; |
+ |
+ Transactions pending_transactions_; |
+ |
+ RemotePtr<IViewManager> service_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ViewManagerSynchronizer); |
+}; |
+ |
+} // namespace view_manager |
+} // namespace services |
+} // namespace mojo |
+ |
+#endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H_ |