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 "base/memory/weak_ptr.h" |
10 #include "mojo/public/cpp/bindings/remote_ptr.h" | 11 #include "mojo/public/cpp/bindings/remote_ptr.h" |
11 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" | 12 #include "mojo/services/public/cpp/view_manager/view_manager_types.h" |
12 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" | 13 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" |
13 | 14 |
14 namespace base { | 15 namespace base { |
15 class RunLoop; | 16 class RunLoop; |
16 } | 17 } |
17 | 18 |
18 namespace mojo { | 19 namespace mojo { |
19 namespace services { | 20 namespace services { |
(...skipping 14 matching lines...) Expand all Loading... |
34 // service. | 35 // service. |
35 TransportNodeId CreateViewTreeNode(); | 36 TransportNodeId CreateViewTreeNode(); |
36 void DestroyViewTreeNode(TransportNodeId node_id); | 37 void DestroyViewTreeNode(TransportNodeId node_id); |
37 | 38 |
38 // These methods take TransportIds. For views owned by the current connection, | 39 // These methods take TransportIds. For views owned by the current connection, |
39 // the connection id high word can be zero. In all cases, the TransportId 0x1 | 40 // the connection id high word can be zero. In all cases, the TransportId 0x1 |
40 // refers to the root node. | 41 // refers to the root node. |
41 void AddChild(TransportNodeId child_id, TransportNodeId parent_id); | 42 void AddChild(TransportNodeId child_id, TransportNodeId parent_id); |
42 void RemoveChild(TransportNodeId child_id, TransportNodeId parent_id); | 43 void RemoveChild(TransportNodeId child_id, TransportNodeId parent_id); |
43 | 44 |
| 45 bool OwnsNode(TransportNodeId id) const; |
| 46 |
44 private: | 47 private: |
45 friend class ViewManagerTransaction; | 48 friend class ViewManagerTransaction; |
46 typedef ScopedVector<ViewManagerTransaction> Transactions; | 49 typedef ScopedVector<ViewManagerTransaction> Transactions; |
47 | 50 |
48 // Overridden from IViewManagerClient: | 51 // Overridden from IViewManagerClient: |
49 virtual void OnConnectionEstablished(uint16 connection_id) OVERRIDE; | 52 virtual void OnConnectionEstablished(uint16 connection_id) OVERRIDE; |
50 virtual void OnNodeHierarchyChanged(uint32 node_id, | 53 virtual void OnNodeHierarchyChanged(uint32 node_id, |
51 uint32 new_parent_id, | 54 uint32 new_parent_id, |
52 uint32 old_parent_id, | 55 uint32 old_parent_id, |
53 uint32 change_id) OVERRIDE; | 56 uint32 change_id) OVERRIDE; |
54 virtual void OnNodeViewReplaced(uint32_t node, | 57 virtual void OnNodeViewReplaced(uint32_t node, |
55 uint32_t new_view_id, | 58 uint32_t new_view_id, |
56 uint32_t old_view_id, | 59 uint32_t old_view_id, |
57 uint32_t change_id) OVERRIDE; | 60 uint32_t change_id) OVERRIDE; |
| 61 virtual void OnNodeDeleted(uint32_t node_id, uint32_t change_id) OVERRIDE; |
58 | 62 |
59 // Called to schedule a sync of the client model with the service after a | 63 // Called to schedule a sync of the client model with the service after a |
60 // return to the message loop. | 64 // return to the message loop. |
61 void ScheduleSync(); | 65 void ScheduleSync(); |
62 | 66 |
63 // Sync the client model with the service by enumerating the pending | 67 // Sync the client model with the service by enumerating the pending |
64 // transaction queue and applying them in order. | 68 // transaction queue and applying them in order. |
65 void DoSync(); | 69 void DoSync(); |
66 | 70 |
67 // Used by individual transactions to generate a connection-specific change | 71 // Used by individual transactions to generate a connection-specific change |
68 // id. | 72 // id. |
69 // TODO(beng): What happens when there are more than sizeof(int) changes in | 73 // TODO(beng): What happens when there are more than sizeof(int) changes in |
70 // the queue? | 74 // the queue? |
71 uint32_t GetNextChangeId(); | 75 uint32_t GetNextChangeId(); |
72 | 76 |
73 // Removes |transaction| from the pending queue. |transaction| must be at the | 77 // Removes |transaction| from the pending queue. |transaction| must be at the |
74 // front of the queue. | 78 // front of the queue. |
75 void RemoveFromPendingQueue(ViewManagerTransaction* transaction); | 79 void RemoveFromPendingQueue(ViewManagerTransaction* transaction); |
76 | 80 |
77 void OnRootTreeReceived(const Array<INode>& data); | 81 void OnRootTreeReceived(const Array<INode>& data); |
78 | 82 |
79 ViewManager* view_manager_; | 83 ViewManager* view_manager_; |
80 bool connected_; | 84 bool connected_; |
81 uint16_t connection_id_; | 85 uint16_t connection_id_; |
82 uint16_t next_id_; | 86 uint16_t next_id_; |
83 uint32_t next_change_id_; | 87 uint32_t next_change_id_; |
84 | 88 |
85 Transactions pending_transactions_; | 89 Transactions pending_transactions_; |
86 | 90 |
| 91 base::WeakPtrFactory<ViewManagerSynchronizer> sync_factory_; |
| 92 |
87 // Non-NULL while blocking on the connection to |service_| during | 93 // Non-NULL while blocking on the connection to |service_| during |
88 // construction. | 94 // construction. |
89 base::RunLoop* init_loop_; | 95 base::RunLoop* init_loop_; |
90 | 96 |
91 RemotePtr<IViewManager> service_; | 97 RemotePtr<IViewManager> service_; |
92 | 98 |
93 DISALLOW_COPY_AND_ASSIGN(ViewManagerSynchronizer); | 99 DISALLOW_COPY_AND_ASSIGN(ViewManagerSynchronizer); |
94 }; | 100 }; |
95 | 101 |
96 } // namespace view_manager | 102 } // namespace view_manager |
97 } // namespace services | 103 } // namespace services |
98 } // namespace mojo | 104 } // namespace mojo |
99 | 105 |
100 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H
_ | 106 #endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_LIB_VIEW_MANAGER_SYNCHRONIZER_H
_ |
OLD | NEW |