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

Unified Diff: blimp/helium/compound_syncable.h

Issue 2402153002: Add CompoundSyncable class for synchronizing containers of Syncables. (Closed)
Patch Set: make literal unsigned 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blimp/helium/BUILD.gn ('k') | blimp/helium/compound_syncable.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/helium/compound_syncable.h
diff --git a/blimp/helium/compound_syncable.h b/blimp/helium/compound_syncable.h
new file mode 100644
index 0000000000000000000000000000000000000000..519507276b188621992d47042c38ba34bbfa7332
--- /dev/null
+++ b/blimp/helium/compound_syncable.h
@@ -0,0 +1,88 @@
+// 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_HELIUM_COMPOUND_SYNCABLE_H_
+#define BLIMP_HELIUM_COMPOUND_SYNCABLE_H_
+
+#include <stdint.h>
+#include <memory>
+#include <utility>
+#include <vector>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "blimp/helium/blimp_helium_export.h"
+#include "blimp/helium/syncable.h"
+
+namespace blimp {
+namespace helium {
+
+// Handles the creation and tracking of member Syncable objects.
+// Is the exclusive creator of RegisteredMember container objects, which
+// enforces the convention that all child Syncables must be created with, and
+// therefore known to, a MemberRegistry.
+
+// Base class for composite Syncable objects.
+// Manages the fan-out of all Syncable operations to registered member
+// Syncables. Member syncables are created by calling
+// CreateAndRegister(<ctor args>).
+class BLIMP_HELIUM_EXPORT CompoundSyncable : public Syncable {
+ public:
+ CompoundSyncable();
+ ~CompoundSyncable() override;
+
+ // Syncable implementation.
+ void CreateChangesetToCurrent(
+ Revision from,
+ google::protobuf::io::CodedOutputStream* output_stream) override;
+ Result ApplyChangeset(
+ Revision to,
+ google::protobuf::io::CodedInputStream* changeset) override;
+ void ReleaseBefore(Revision from) override;
+ VersionVector GetVersionVector() const override;
+
+ protected:
+ template <typename T>
+ class RegisteredMember {
+ public:
+ ~RegisteredMember() = default;
+ RegisteredMember(RegisteredMember<T>&& other) = default;
+
+ T* get() const { return member_.get(); }
+ T& operator->() const { return *member_; }
+
+ private:
+ friend class CompoundSyncable;
+
+ // Make class only constructable by CompoundSyncable, so that there is a
+ // strong guarantee that a RegisteredMember was created by
+ // MemberRegistry::CreateAndRegister().
+ explicit RegisteredMember(std::unique_ptr<T> member)
+ : member_(std::move(member)) {}
+
+ std::unique_ptr<T> member_;
+
+ DISALLOW_COPY_AND_ASSIGN(RegisteredMember<T>);
+ };
+
+ template <typename T, typename... ConstructorArgs>
+ RegisteredMember<T> CreateAndRegister(ConstructorArgs... args) {
+ std::unique_ptr<T> new_member =
+ base::MakeUnique<T>(std::forward<ConstructorArgs>(args)...);
+ members_.push_back(new_member.get());
+ return RegisteredMember<T>(std::move(new_member));
+ }
+
+ private:
+ // Tracks all Syncables* which have been created with CreateAndRegister().
+ std::vector<Syncable*> members_;
+
+ DISALLOW_COPY_AND_ASSIGN(CompoundSyncable);
+};
+
+} // namespace helium
+} // namespace blimp
+
+#endif // BLIMP_HELIUM_COMPOUND_SYNCABLE_H_
« no previous file with comments | « blimp/helium/BUILD.gn ('k') | blimp/helium/compound_syncable.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698