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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « blimp/helium/BUILD.gn ('k') | blimp/helium/compound_syncable.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_HELIUM_COMPOUND_SYNCABLE_H_
6 #define BLIMP_HELIUM_COMPOUND_SYNCABLE_H_
7
8 #include <stdint.h>
9 #include <memory>
10 #include <utility>
11 #include <vector>
12
13 #include "base/callback.h"
14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h"
16 #include "blimp/helium/blimp_helium_export.h"
17 #include "blimp/helium/syncable.h"
18
19 namespace blimp {
20 namespace helium {
21
22 // Handles the creation and tracking of member Syncable objects.
23 // Is the exclusive creator of RegisteredMember container objects, which
24 // enforces the convention that all child Syncables must be created with, and
25 // therefore known to, a MemberRegistry.
26
27 // Base class for composite Syncable objects.
28 // Manages the fan-out of all Syncable operations to registered member
29 // Syncables. Member syncables are created by calling
30 // CreateAndRegister(<ctor args>).
31 class BLIMP_HELIUM_EXPORT CompoundSyncable : public Syncable {
32 public:
33 CompoundSyncable();
34 ~CompoundSyncable() override;
35
36 // Syncable implementation.
37 void CreateChangesetToCurrent(
38 Revision from,
39 google::protobuf::io::CodedOutputStream* output_stream) override;
40 Result ApplyChangeset(
41 Revision to,
42 google::protobuf::io::CodedInputStream* changeset) override;
43 void ReleaseBefore(Revision from) override;
44 VersionVector GetVersionVector() const override;
45
46 protected:
47 template <typename T>
48 class RegisteredMember {
49 public:
50 ~RegisteredMember() = default;
51 RegisteredMember(RegisteredMember<T>&& other) = default;
52
53 T* get() const { return member_.get(); }
54 T& operator->() const { return *member_; }
55
56 private:
57 friend class CompoundSyncable;
58
59 // Make class only constructable by CompoundSyncable, so that there is a
60 // strong guarantee that a RegisteredMember was created by
61 // MemberRegistry::CreateAndRegister().
62 explicit RegisteredMember(std::unique_ptr<T> member)
63 : member_(std::move(member)) {}
64
65 std::unique_ptr<T> member_;
66
67 DISALLOW_COPY_AND_ASSIGN(RegisteredMember<T>);
68 };
69
70 template <typename T, typename... ConstructorArgs>
71 RegisteredMember<T> CreateAndRegister(ConstructorArgs... args) {
72 std::unique_ptr<T> new_member =
73 base::MakeUnique<T>(std::forward<ConstructorArgs>(args)...);
74 members_.push_back(new_member.get());
75 return RegisteredMember<T>(std::move(new_member));
76 }
77
78 private:
79 // Tracks all Syncables* which have been created with CreateAndRegister().
80 std::vector<Syncable*> members_;
81
82 DISALLOW_COPY_AND_ASSIGN(CompoundSyncable);
83 };
84
85 } // namespace helium
86 } // namespace blimp
87
88 #endif // BLIMP_HELIUM_COMPOUND_SYNCABLE_H_
OLDNEW
« 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