OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 BLIMP_NET_HELIUM_HELIUM_SYNC_MANAGER_H_ | |
6 #define BLIMP_NET_HELIUM_HELIUM_SYNC_MANAGER_H_ | |
7 | |
8 #include <stdint.h> | |
9 #include <memory> | |
10 | |
11 #include "base/macros.h" | |
12 | |
13 namespace blimp { | |
14 | |
15 class HeliumObject; | |
16 class HeliumTransport; | |
17 class Syncable; | |
18 | |
19 using HeliumObjectId = uint32_t; | |
20 | |
21 // TODO(kmarshall): Define this type. | |
scf
2016/09/28 17:18:00
put bug#?
| |
22 class HeliumTransport {}; | |
23 | |
24 class HeliumSyncManager { | |
25 public: | |
26 // RAII object for managing the sync control and registration status of a | |
27 // Syncable. When a Syncable is registered, it should hold onto the resulting | |
28 // SyncRegistration object. | |
29 // | |
30 // When the Syncable is destroyed, it will delete the | |
31 // SyncRegistration along with it, which will automatically unregister the | |
32 // object from the SyncManager. | |
33 // | |
34 // If a Syncable wishes to halt synchronization for any reason (e.g. a tab | |
35 // is hidden on the Client), it may call SyncRegistration::Pause(), which will | |
36 // tell the SyncManager to exclude or include the Syncable in state sync. | |
37 class SyncRegistration { | |
38 public: | |
39 explicit SyncRegistration(HeliumSyncManager* sync_manager, | |
40 HeliumObjectId id); | |
41 ~SyncRegistration(); | |
42 | |
43 // Tells the HeliumSyncManager to pause or unpause synchronization for the | |
44 // HeliumObject associated with |this|. | |
45 void Pause(bool paused); | |
46 | |
47 HeliumObjectId id() { return id_; } | |
48 | |
49 private: | |
50 HeliumObjectId id_; | |
51 HeliumSyncManager* sync_manager_; | |
52 | |
53 DISALLOW_COPY_AND_ASSIGN(SyncRegistration); | |
54 }; | |
55 | |
56 virtual ~HeliumSyncManager() {} | |
57 | |
58 // Returns a concrete implementation of HeliumSyncManager. | |
59 static std::unique_ptr<HeliumSyncManager> Create( | |
perumaal
2016/09/28 23:31:30
Consider: A member function such as HeliumTranspor
Kevin M
2016/09/29 00:06:28
I think that would invert the dependency order. Sy
| |
60 std::unique_ptr<HeliumTransport> transport); | |
scf
2016/09/28 17:18:00
don't we need an api to get the current HeliumSync
Kevin M
2016/09/29 00:06:28
Which classes would rely on such an accessor? Is t
scf
2016/10/03 17:59:33
make sense
| |
61 | |
62 // Registers a new Syncable for synchronization. The Sync layer allocates a | |
63 // unique identifier to the Object (including guaranteeing no clashes between | |
64 // Client & Engine). | |
65 // The identifier may be used by other Objects to refer to |object|. E.g. the | |
66 // tab-list Object might include the Id for each tab’s Object. | |
67 virtual std::unique_ptr<SyncRegistration> Register(Syncable* syncable) = 0; | |
68 | |
69 // Registers a Syncable for synchronization with a pre-existing ID. | |
70 // This form is used when the remote peer has created a new Syncable, to | |
71 // register our local equivalent. | |
72 virtual std::unique_ptr<SyncRegistration> RegisterExisting( | |
73 HeliumObjectId id, | |
74 Syncable* syncable) = 0; | |
75 | |
76 // Tells the HeliumSyncManager to pause or unpause synchronization for the | |
77 // HeliumObject associated with |this|. | |
78 virtual void Pause(HeliumObjectId id, bool paused) = 0; | |
scf
2016/09/28 17:18:00
move this under the protected section too?
Kevin M
2016/09/29 00:06:28
OK. In the future we might want to make it public
| |
79 | |
80 protected: | |
81 friend class HeliumSyncManager::SyncRegistration; | |
82 | |
83 // Indicates that a Syncable is being destroyed, and should no longer be | |
84 // synchronized. | |
85 // Because the Syncable is being destroyed, it is assumed that in-flight | |
86 // messages | |
87 // about it are now irrelevant, and the Sync layer should tear down underlying | |
88 // resources, such as the HeliumStream, immediately. | |
89 virtual void Unregister(HeliumObjectId id) = 0; | |
90 }; | |
91 | |
92 } // namespace blimp | |
93 | |
94 #endif // BLIMP_NET_HELIUM_HELIUM_SYNC_MANAGER_H_ | |
OLD | NEW |