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

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

Issue 2382533002: Helium: Initial proto and Syncable interface definition (Closed)
Patch Set: Couple minor tweaks 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 // SyncableMember depends on its SyncableObject parent.
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() {}
Kevin M 2016/09/30 18:34:36 Don't need to add ctor - class doesn't have any co
scf 2016/09/30 22:13:24 Done.
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;
Kevin M 2016/09/30 18:34:37 Sorry - it now occurs to me that this should proba
scf 2016/09/30 22:13:24 Done.
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,
Kevin M 2016/09/30 18:34:36 We should take this as a unique_ptr so that we can
scf 2016/09/30 22:13:23 Done.
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);
Kevin M 2016/09/30 18:34:36 Maybe add a no-arg constructor that just uses a ze
scf 2016/09/30 22:13:24 Done.
76 ~SyncableObject() override {}
77
78 VectorClock& get_clock() { return clock_; }
Kevin M 2016/09/30 18:34:36 * Inline getters don't need a get_ prefix. * Refer
scf 2016/09/30 22:13:24 done. using the proto convention (mutable_name)
79
80 protected:
81 // The clock is needed in order for the |SyncableMember| objects whenever
Kevin M 2016/09/30 18:34:36 Remove space before The
scf 2016/09/30 22:13:24 Done.
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_;
Kevin M 2016/09/30 18:34:36 Add DISALLOW_COPY_AND_ASSIGN(SyncableObject);
scf 2016/09/30 22:13:24 Done.
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_;
Kevin M 2016/09/30 18:34:36 DISALLOW_COPY_AND_ASSIGN
scf 2016/09/30 22:13:24 Done.
103 };
104
105 } // namespace blimp
106
107 #endif // BLIMP_NET_HELIUM_SYNCABLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698