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

Side by Side Diff: sync/api/sync_data.h

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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 | « sync/api/sync_change_unittest.cc ('k') | sync/api/sync_data.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 2012 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 SYNC_API_SYNC_DATA_H_
6 #define SYNC_API_SYNC_DATA_H_
7
8 #include <stdint.h>
9
10 #include <iosfwd>
11 #include <string>
12 #include <vector>
13
14 #include "base/callback.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/stl_util.h"
17 #include "base/time/time.h"
18 #include "sync/api/attachments/attachment_id.h"
19 #include "sync/base/sync_export.h"
20 #include "sync/internal_api/public/attachments/attachment_service_proxy.h"
21 #include "sync/internal_api/public/base/model_type.h"
22 #include "sync/internal_api/public/util/immutable.h"
23 #include "sync/internal_api/public/util/weak_handle.h"
24
25 namespace sync_pb {
26 class EntitySpecifics;
27 class SyncEntity;
28 } // namespace sync_pb
29
30 namespace syncer {
31
32 class AttachmentService;
33 class SyncDataLocal;
34 class SyncDataRemote;
35
36 // A light-weight container for immutable sync data. Pass-by-value and storage
37 // in STL containers are supported and encouraged if helpful.
38 class SYNC_EXPORT SyncData {
39 public:
40 // Creates an empty and invalid SyncData.
41 SyncData();
42 SyncData(const SyncData& other);
43 ~SyncData();
44
45 // Default copy and assign welcome.
46
47 // Helper methods for creating SyncData objects for local data.
48 //
49 // |sync_tag| Must be a string unique to this datatype and is used as a node
50 // identifier server-side.
51 //
52 // For deletes: |datatype| must specify the datatype who node is being
53 // deleted.
54 //
55 // For adds/updates: |specifics| must be valid and |non_unique_title| (can be
56 // the same as |sync_tag|) must be specfied. Note: |non_unique_title| is
57 // primarily for debug purposes, and will be overwritten if the datatype is
58 // encrypted.
59 //
60 // For data with attachments: |attachment_ids| must not contain duplicates.
61 static SyncData CreateLocalDelete(
62 const std::string& sync_tag,
63 ModelType datatype);
64 static SyncData CreateLocalData(
65 const std::string& sync_tag,
66 const std::string& non_unique_title,
67 const sync_pb::EntitySpecifics& specifics);
68 static SyncData CreateLocalDataWithAttachments(
69 const std::string& sync_tag,
70 const std::string& non_unique_title,
71 const sync_pb::EntitySpecifics& specifics,
72 const AttachmentIdList& attachment_ids);
73
74 // Helper method for creating SyncData objects originating from the syncer.
75 static SyncData CreateRemoteData(
76 int64_t id,
77 const sync_pb::EntitySpecifics& specifics,
78 const base::Time& last_modified_time,
79 const AttachmentIdList& attachment_ids,
80 const syncer::AttachmentServiceProxy& attachment_service,
81 const std::string& client_tag_hash = std::string());
82
83 // Whether this SyncData holds valid data. The only way to have a SyncData
84 // without valid data is to use the default constructor.
85 bool IsValid() const;
86
87 // Return the datatype we're holding information about. Derived from the sync
88 // datatype specifics.
89 ModelType GetDataType() const;
90
91 // Return the current sync datatype specifics.
92 const sync_pb::EntitySpecifics& GetSpecifics() const;
93
94 // Return the non unique title (for debugging). Currently only set for data
95 // going TO the syncer, not from.
96 const std::string& GetTitle() const;
97
98 // Whether this sync data is for local data or data coming from the syncer.
99 bool IsLocal() const;
100
101 std::string ToString() const;
102
103 // Return a list of this SyncData's attachment ids.
104 //
105 // The attachments may or may not be present on this device.
106 AttachmentIdList GetAttachmentIds() const;
107
108 // TODO(zea): Query methods for other sync properties: parent, successor, etc.
109
110 protected:
111 // These data members are protected so derived types like SyncDataLocal and
112 // SyncDataRemote can access them.
113
114 // Necessary since we forward-declare sync_pb::SyncEntity; see
115 // comments in immutable.h.
116 struct SYNC_EXPORT ImmutableSyncEntityTraits {
117 typedef sync_pb::SyncEntity* Wrapper;
118
119 static void InitializeWrapper(Wrapper* wrapper);
120
121 static void DestroyWrapper(Wrapper* wrapper);
122
123 static const sync_pb::SyncEntity& Unwrap(const Wrapper& wrapper);
124
125 static sync_pb::SyncEntity* UnwrapMutable(Wrapper* wrapper);
126
127 static void Swap(sync_pb::SyncEntity* t1, sync_pb::SyncEntity* t2);
128 };
129
130 typedef Immutable<sync_pb::SyncEntity, ImmutableSyncEntityTraits>
131 ImmutableSyncEntity;
132
133 // Equal to kInvalidId iff this is local.
134 int64_t id_;
135
136 // This may be null if the SyncData represents a deleted item.
137 base::Time remote_modification_time_;
138
139 // The actual shared sync entity being held.
140 ImmutableSyncEntity immutable_entity_;
141
142 AttachmentServiceProxy attachment_service_;
143
144 private:
145 // Whether this SyncData holds valid data.
146 bool is_valid_;
147
148 // Clears |entity| and |attachments|.
149 SyncData(int64_t id,
150 sync_pb::SyncEntity* entity,
151 const base::Time& remote_modification_time,
152 const syncer::AttachmentServiceProxy& attachment_service);
153 };
154
155 // A SyncData going to the syncer.
156 class SYNC_EXPORT SyncDataLocal : public SyncData {
157 public:
158 // Construct a SyncDataLocal from a SyncData.
159 //
160 // |sync_data|'s IsLocal() must be true.
161 explicit SyncDataLocal(const SyncData& sync_data);
162 ~SyncDataLocal();
163
164 // Return the value of the unique client tag. This is only set for data going
165 // TO the syncer, not coming from.
166 const std::string& GetTag() const;
167 };
168
169 // A SyncData that comes from the syncer.
170 class SYNC_EXPORT SyncDataRemote : public SyncData {
171 public:
172 // Construct a SyncDataRemote from a SyncData.
173 //
174 // |sync_data|'s IsLocal() must be false.
175 explicit SyncDataRemote(const SyncData& sync_data);
176 ~SyncDataRemote();
177
178 // Return the last motification time according to the server. This may be null
179 // if the SyncData represents a deleted item.
180 const base::Time& GetModifiedTime() const;
181
182 int64_t GetId() const;
183
184 // Returns the tag hash value. May not always be present, in which case an
185 // empty string will be returned.
186 const std::string& GetClientTagHash() const;
187
188 // Retrieve the attachments indentified by |attachment_ids|. Invoke
189 // |callback| with the requested attachments.
190 //
191 // |callback| will be invoked when the operation is complete (successfully
192 // or otherwise).
193 //
194 // Retrieving the requested attachments may require reading local storage or
195 // requesting the attachments from the network.
196 //
197 void GetOrDownloadAttachments(
198 const AttachmentIdList& attachment_ids,
199 const AttachmentService::GetOrDownloadCallback& callback);
200 };
201
202 // gmock printer helper.
203 void SYNC_EXPORT PrintTo(const SyncData& sync_data, std::ostream* os);
204
205 typedef std::vector<SyncData> SyncDataList;
206
207 } // namespace syncer
208
209 #endif // SYNC_API_SYNC_DATA_H_
OLDNEW
« no previous file with comments | « sync/api/sync_change_unittest.cc ('k') | sync/api/sync_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698