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 #ifndef MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H_ | 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_ | 6 #define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
10 #include "mojo/public/cpp/bindings/remote_ptr.h" | 10 #include "mojo/public/cpp/bindings/remote_ptr.h" |
| 11 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" |
11 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 12 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
12 | 13 |
13 namespace mojo { | 14 namespace mojo { |
14 namespace services { | 15 namespace services { |
15 namespace view_manager { | 16 namespace view_manager { |
16 | 17 |
17 class ViewManager; | 18 class ViewManager; |
18 class ViewManagerTransaction; | 19 class ViewManagerTransaction; |
19 | 20 |
20 // Manages the connection with the View Manager service. | 21 // Manages the connection with the View Manager service. |
21 class ViewManagerSynchronizer : public IViewManagerClient { | 22 class ViewManagerSynchronizer : public IViewManagerClient { |
22 public: | 23 public: |
23 explicit ViewManagerSynchronizer(ViewManager* view_manager); | 24 explicit ViewManagerSynchronizer(ViewManager* view_manager); |
24 virtual ~ViewManagerSynchronizer(); | 25 virtual ~ViewManagerSynchronizer(); |
25 | 26 |
| 27 bool connected() const { return connected_; } |
| 28 |
26 // API exposed to the node implementation that pushes local changes to the | 29 // API exposed to the node implementation that pushes local changes to the |
27 // service. | 30 // service. |
28 uint16_t CreateViewTreeNode(); | 31 uint16_t CreateViewTreeNode(); |
29 void AddChild(uint16_t child_id, uint16_t parent_id); | 32 void DestroyViewTreeNode(TransportNodeId node_id); |
30 void RemoveChild(uint16_t child_id, uint16_t parent_id); | 33 |
| 34 // These methods take TransportIds. For views owned by the current connection, |
| 35 // the connection id high word can be zero. In all cases, the TransportId 0x1 |
| 36 // refers to the root node. |
| 37 void AddChild(TransportNodeId child_id, TransportNodeId parent_id); |
| 38 void RemoveChild(TransportNodeId child_id, TransportNodeId parent_id); |
| 39 |
| 40 void BuildNodeTree(const Callback<void()>& callback); |
31 | 41 |
32 private: | 42 private: |
33 friend class ViewManagerTransaction; | 43 friend class ViewManagerTransaction; |
34 typedef ScopedVector<ViewManagerTransaction> Transactions; | 44 typedef ScopedVector<ViewManagerTransaction> Transactions; |
35 | 45 |
36 // Overridden from IViewManagerClient: | 46 // Overridden from IViewManagerClient: |
37 virtual void OnConnectionEstablished(uint16 connection_id) OVERRIDE; | 47 virtual void OnConnectionEstablished(uint16 connection_id) OVERRIDE; |
38 virtual void OnNodeHierarchyChanged(uint32 node, | 48 virtual void OnNodeHierarchyChanged(uint32 node, |
39 uint32 new_parent, | 49 uint32 new_parent, |
40 uint32 old_parent, | 50 uint32 old_parent, |
(...skipping 10 matching lines...) Expand all Loading... |
51 // Sync the client model with the service by enumerating the pending | 61 // Sync the client model with the service by enumerating the pending |
52 // transaction queue and applying them in order. | 62 // transaction queue and applying them in order. |
53 void DoSync(); | 63 void DoSync(); |
54 | 64 |
55 // Used by individual transactions to generate a connection-specific change | 65 // Used by individual transactions to generate a connection-specific change |
56 // id. | 66 // id. |
57 // TODO(beng): What happens when there are more than sizeof(int) changes in | 67 // TODO(beng): What happens when there are more than sizeof(int) changes in |
58 // the queue? | 68 // the queue? |
59 uint32_t GetNextChangeId(); | 69 uint32_t GetNextChangeId(); |
60 | 70 |
| 71 // Called from transactions to notify when a commit is made to the service and |
| 72 // when a response is received. |
| 73 void NotifyCommit(); |
| 74 void NotifyCommitResponse(bool success); |
| 75 |
61 // Removes |transaction| from the pending queue. |transaction| must be at the | 76 // Removes |transaction| from the pending queue. |transaction| must be at the |
62 // front of the queue. | 77 // front of the queue. |
63 void RemoveFromPendingQueue(ViewManagerTransaction* transaction); | 78 void RemoveFromPendingQueue(ViewManagerTransaction* transaction); |
64 | 79 |
| 80 void OnTreeReceived(const Callback<void()>& callback, |
| 81 const Array<INode>& data); |
| 82 |
65 ViewManager* view_manager_; | 83 ViewManager* view_manager_; |
66 bool connected_; | 84 bool connected_; |
67 uint16_t connection_id_; | 85 uint16_t connection_id_; |
68 uint16_t next_id_; | 86 uint16_t next_id_; |
69 uint32_t next_change_id_; | 87 uint32_t next_change_id_; |
70 | 88 |
71 Transactions pending_transactions_; | 89 Transactions pending_transactions_; |
72 | 90 |
73 RemotePtr<IViewManager> service_; | 91 RemotePtr<IViewManager> service_; |
74 | 92 |
75 DISALLOW_COPY_AND_ASSIGN(ViewManagerSynchronizer); | 93 DISALLOW_COPY_AND_ASSIGN(ViewManagerSynchronizer); |
76 }; | 94 }; |
77 | 95 |
78 } // namespace view_manager | 96 } // namespace view_manager |
79 } // namespace services | 97 } // namespace services |
80 } // namespace mojo | 98 } // namespace mojo |
81 | 99 |
82 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H
_ | 100 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H
_ |
OLD | NEW |