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

Unified Diff: blimp/net/helium/syncable.h

Issue 2382533002: Helium: Initial proto and Syncable interface definition (Closed)
Patch Set: Initial proto and Syncable interface definition Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: blimp/net/helium/syncable.h
diff --git a/blimp/net/helium/syncable.h b/blimp/net/helium/syncable.h
new file mode 100644
index 0000000000000000000000000000000000000000..f4014199b5596a9d8ba670b9dbe45d6f642d066e
--- /dev/null
+++ b/blimp/net/helium/syncable.h
@@ -0,0 +1,112 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BLIMP_NET_HELIUM_SYNCABLE_H_
+#define BLIMP_NET_HELIUM_SYNCABLE_H_
+
+#include <stdint.h>
+
+#include "base/callback.h"
+#include "blimp/common/proto/helium.pb.h"
+
+#include "vector_clock.h"
CJ 2016/09/29 20:36:55 Nit: I think you want to give the full path to vec
scf 2016/09/29 23:13:39 Done.
+
+namespace blimp {
+
+// SyncableObject and Syncable are conceptually very similar. Both are objects
Sriram 2016/09/29 18:52:21 Not to bikeshed with names but I find SyncableObje
Brian Goldman 2016/09/29 19:31:28 Seconded that it's confusing. For me it's because
scf 2016/09/29 23:13:38 Not bikeshed at all. I was not super happy with th
+// that will be synchronized between client server.
Brian Goldman 2016/09/29 19:31:28 Maybe a little more detail here on what it means t
scf 2016/09/29 23:13:39 Done.
+//
+// The main difference is that SyncableObject owns its lifetime, whereas
Kevin M 2016/09/29 20:01:16 The lifetime is managed by an arbitrary entity whi
scf 2016/09/29 23:13:39 I find this a bit vague. Not entirely sure what yo
+// Syncable depends on its SyncableObject parent.
+//
+// An example for GeoLocation would be:
+// GeoLocation : SyncableObject {
+// * Frequency : Syncable
+// * Position : Syncable
+// }
+//
+// VectorClocks from a Syncable can be compared with the vector clock from
CJ 2016/09/29 20:36:55 This a bit confusing as well. Is the vector clock
scf 2016/09/29 23:13:39 Done.
+// the SyncableObject. This reduces the amount of state that can be kept.
+
+class SyncableObject {
Sriram 2016/09/29 18:52:21 A SyncableObject does not control how often it is
scf 2016/09/29 23:13:39 There will be a notification mechanism to tell the
+ public:
+ using CreateChangesetCallback =
+ base::Callback<void(std::unique_ptr<helium::Changeset> changeset)>;
Kevin M 2016/09/29 20:01:16 In general we don't specify parameter names in fun
scf 2016/09/29 23:13:38 Done.
+
+ explicit SyncableObject(const VectorClock& clock) : clock_(clock) {}
+
+ virtual ~SyncableObject(){}
+
+ // Constructs a changeset between the |from| revision and its current state.
+ // The Sync layer will encapsulate the changeset with details since |from|,
+ // but the Object is responsible for including any revision information
+ // additional to that expressed by the VectorClocks, that is necessary to
+ // detect and resolve conflicts.
+ // The computed changeset is returned asynchronously via |response_callback|.
+ virtual void CreateChangesetToCurrent(
Kevin M 2016/09/29 20:01:16 Shouldn't these be overrides of Syncable instead o
scf 2016/09/29 23:13:38 I thought about making the interfaces different as
+ const VectorClock& from,
+ const CreateChangesetCallback& response_callback) = 0;
+
+ // Applies a |changeset| given as parameter to the contents of the
+ // Object. The VectorClocks |from| and |to| can be used to detect and resolve
CJ 2016/09/29 20:36:55 Not following when u say "the Object". If you mean
scf 2016/09/29 23:13:38 Done.
+ // concurrent change conflicts.
+ // The closure |done| its called when the state is applied.
+ virtual void ApplyChangeset(const VectorClock& from,
+ const VectorClock& to,
+ const helium::Changeset& changeset,
+ const base::Closure& done) = 0;
+
+ // This call is an optimization that allows the source of the change
Kevin M 2016/09/29 20:01:16 * This isn't a mere optimization; it's actually qu
scf 2016/09/29 23:13:39 Done.
+ // delete anything before a given checkpoint. Lets say we know the receiver
+ // already received the change for VectorClock (2,3). The source now can
+ // delete any state that it needed to create a changeset from x to (2,3).
+ virtual void ReleaseCheckpointsBefore(const VectorClock& checkpoint) = 0;
+
+ VectorClock get_clock() { return clock_; }
scf 2016/09/29 18:26:53 This is needed in order for the |Syncacle| objects
Kevin M 2016/09/29 20:01:16 You are returning the clock by-value, which means
CJ 2016/09/29 20:36:55 Maybe put a little of this rationale in a comment,
scf 2016/09/29 23:13:39 Done.
+
+ protected:
+ VectorClock clock_;
+};
+
+template <class ChangesetType>
+class Syncable {
+ public:
+ explicit Syncable(VectorClock* parent_clock) : parent_clock_(parent_clock) {}
Kevin M 2016/09/29 20:01:16 There's a circular dependency in that we have a "p
scf 2016/09/29 23:13:39 completely agree
+ virtual ~Syncable(){}
+
+ // Returns true if the object have been modified since |from|
+ virtual bool ModifiedSince(const VectorClock& from) = 0;
+
+ // See above definition in |SyncableObject|, the only difference is that
+ // this is a blocking call
Kevin M 2016/09/29 20:01:16 Why are these all blocking?
scf 2016/09/29 23:13:39 I should have checked with you offline before I wr
+ virtual void CreateChangesetToCurrent(const VectorClock& from,
+ ChangesetType* changeset) = 0;
+
+ // See above definition in |SyncableObject|, the only difference is that
+ // this is a blocking call
+ virtual void ApplyChangeset(const VectorClock& from,
+ const VectorClock& to,
+ const ChangesetType& changeset) = 0;
+
+ // See above definition in |SyncableObject|, the only difference is that
+ // this is a blocking call
+ virtual void ReleaseCheckpointsBefore(const VectorClock& checkpoint) = 0;
+
+ protected:
+ // Increments the parent clock and returns the new value. Should be used
+ // whenever a Syncable updates its state.
+ VectorClock IncrementParentClock() {
+ parent_clock_->IncrementLocal();
+ return *parent_clock_;
+ }
+
+ VectorClock parent_clock() { return *parent_clock_; }
Kevin M 2016/09/29 20:01:16 Should return a pointer
scf 2016/09/29 23:13:39 Done.
+
+ private:
+ VectorClock* parent_clock_;
+};
+
+} // namespace blimp
+
+#endif // BLIMP_NET_HELIUM_SYNCABLE_H_

Powered by Google App Engine
This is Rietveld 408576698