Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: blimp/net/helium/syncable.h

Issue 2382533002: Helium: Initial proto and Syncable interface definition (Closed)
Patch Set: Addressing initial feedback Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_SYNCABLE_H_
6 #define BLIMP_NET_HELIUM_SYNCABLE_H_
7
8 #include <stdint.h>
9
10 #include "base/callback.h"
11 #include "blimp/common/proto/helium.pb.h"
12 #include "blimp/net/helium/vector_clock.h"
13
14 namespace blimp {
15
16 // SyncableObject and SyncableMember are conceptually very similar.
17 // Both are objects that will be synchronized between client and engine.
18 //
19 // 1. There is a one-to-one relationship between instances on the client and
20 // instances on the engine.
21 // 2. The values stored in client-engine pairs should eventually be equal.
22 //
23 // The main difference is that SyncableObject owns its lifetime, whereas
24 // Syncable depends on its SyncableObject parent.
Brian Goldman 2016/09/29 23:18:03 Replace "Syncable" with "SyncableMember" here.
scf 2016/09/30 17:26:23 #goodcatch
25 //
26 // An example for GeoLocation would be:
27 // GeoLocation : SyncableObject {
28 // * Frequency : SyncableMember
29 // * Position : SyncableMember
30 // }
31 //
32 // VectorClocks from a SyncableMember can be compared with the VectorClock from
33 // the SyncableObject. This reduces the amount of state that needs to be kept.
34
35 template <class ChangesetType>
36 class Syncable {
37 public:
38 using CreateChangesetCallback =
39 base::Callback<void(std::unique_ptr<ChangesetType>)>;
40
41 Syncable(){}
42 virtual ~Syncable(){}
43
44 // Constructs a changeset between the |from| revision and its current state.
45 // The Sync layer will encapsulate the changeset with details since |from|,
46 // but the Object is responsible for including any revision information
47 // additional to that expressed by the VectorClocks, that is necessary to
48 // detect and resolve conflicts.
49 // The computed changeset is returned asynchronously via |response_callback|.
50 virtual void CreateChangesetToCurrent(
51 const VectorClock& from,
52 const CreateChangesetCallback& response_callback) = 0;
53
54 // Applies a |changeset| given as parameter to the contents of the
55 // Syncable.
56 // The VectorClocks |from| and |to| can be used to detect and resolve
57 // concurrent change conflicts.
58 // The closure |done| its called when the state is applied.
59 virtual void ApplyChangeset(const VectorClock& from,
60 const VectorClock& to,
61 const ChangesetType& changeset,
62 const base::Closure& done) = 0;
63
64 // Gives a chance for the Syncable to delete any old data previous to the
65 // |checkpoint|. This is a pretty important method that will remove some
66 // memory pressure for example from the UniqueSet CRDTs. They need to keep
67 // a growing list of added/removed elements over time. With this checkpoint
68 // info they can delete those elements prior to the vector clock specified in
69 // |checkpoint|.
70 virtual void ReleaseCheckpointsBefore(const VectorClock& checkpoint) = 0;
71 };
72
73 class SyncableObject : public Syncable<helium::Changeset> {
74 public:
75 explicit SyncableObject(const VectorClock& clock);
76 ~SyncableObject() override {}
77
78 VectorClock& get_clock() { return clock_; }
79
80 protected:
81 // The clock is needed in order for the |SyncableMember| objects whenever
82 // they modify their state they update their |last_modified_| value.
83 // The rationale here is use a "global" per SyncableObject clock which makes
84 // state management a lot simpler.
85 VectorClock clock_;
86 };
87
88 template <class ChangesetType>
89 class SyncableMember : public Syncable<ChangesetType> {
90 public:
91 explicit SyncableMember(SyncableObject* parent);
92 ~SyncableMember() override {}
93
94 // Returns true if the object have been modified since |from|
95 virtual bool ModifiedSince(const VectorClock& from) = 0;
96
97 protected:
98 // Increments the parent clock and returns the new value. Should be used
99 // whenever a SyncableMember updates its state.
100 VectorClock IncrementParentClock();
101
102 SyncableObject* parent_;
103 };
104
105 } // namespace blimp
106
107 #endif // BLIMP_NET_HELIUM_SYNCABLE_H_
OLDNEW
« no previous file with comments | « blimp/net/BUILD.gn ('k') | blimp/net/helium/syncable.cc » ('j') | blimp/net/helium/syncable.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698