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..ffd2e0ea914b9f15f5906d97424450476df565de |
--- /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); |
sky
2014/04/28 23:04:19
Document who owns view_manager.
|
+ ~ViewManagerSynchronizer(); |
sky
2014/04/28 23:04:19
virtual
|
+ |
+ // API exposed to the node implementation that pushes local changes to the |
+ // service. |
+ int CreateViewTreeNode(); |
+ void AddChild(int child_id, int parent_id); |
sky
2014/04/29 04:14:06
uint16_t for these.
|
+ 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(); |
+ |
+ // Returns true if |change_id| existed in the pending transaction queue and |
+ // was removed. |
+ bool RemovedFromPendingQueue(int change_id); |
+ |
+ ViewManager* view_manager_; |
+ bool connected_; |
+ uint16 connection_id_; |
sky
2014/04/29 04:14:06
uint16_t
|
+ int next_id_; |
sky
2014/04/28 23:04:19
uint16_t.
|
+ int next_change_id_; |
sky
2014/04/28 23:04:19
uint32_t.
|
+ |
+ 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_ |