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

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

Issue 217063005: Separate SyncData methods into three groups, local, remote, and common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@syncapi
Patch Set: Remove AsLocal and AsRemote methods from SyncData. Created 6 years, 8 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
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef SYNC_API_SYNC_DATA_H_ 5 #ifndef SYNC_API_SYNC_DATA_H_
6 #define SYNC_API_SYNC_DATA_H_ 6 #define SYNC_API_SYNC_DATA_H_
7 7
8 #include <iosfwd> 8 #include <iosfwd>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 10 matching lines...) Expand all
21 #include "sync/internal_api/public/util/weak_handle.h" 21 #include "sync/internal_api/public/util/weak_handle.h"
22 22
23 namespace sync_pb { 23 namespace sync_pb {
24 class EntitySpecifics; 24 class EntitySpecifics;
25 class SyncEntity; 25 class SyncEntity;
26 } // namespace sync_pb 26 } // namespace sync_pb
27 27
28 namespace syncer { 28 namespace syncer {
29 29
30 class AttachmentService; 30 class AttachmentService;
31 class SyncDataLocal;
32 class SyncDataRemote;
31 33
32 // A light-weight container for immutable sync data. Pass-by-value and storage 34 // A light-weight container for immutable sync data. Pass-by-value and storage
33 // in STL containers are supported and encouraged if helpful. 35 // in STL containers are supported and encouraged if helpful.
34 class SYNC_EXPORT SyncData { 36 class SYNC_EXPORT SyncData {
35 public: 37 public:
36 // Creates an empty and invalid SyncData. 38 // Creates an empty and invalid SyncData.
37 SyncData(); 39 SyncData();
38 ~SyncData(); 40 ~SyncData();
39 41
40 // Default copy and assign welcome. 42 // Default copy and assign welcome.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // without valid data is to use the default constructor. 81 // without valid data is to use the default constructor.
80 bool IsValid() const; 82 bool IsValid() const;
81 83
82 // Return the datatype we're holding information about. Derived from the sync 84 // Return the datatype we're holding information about. Derived from the sync
83 // datatype specifics. 85 // datatype specifics.
84 ModelType GetDataType() const; 86 ModelType GetDataType() const;
85 87
86 // Return the current sync datatype specifics. 88 // Return the current sync datatype specifics.
87 const sync_pb::EntitySpecifics& GetSpecifics() const; 89 const sync_pb::EntitySpecifics& GetSpecifics() const;
88 90
89 // Returns the value of the unique client tag. This is only set for data going 91 // Return the non unique title (for debugging). Currently only set for data
90 // TO the syncer, not coming from.
91 const std::string& GetTag() const;
92
93 // Returns the non unique title (for debugging). Currently only set for data
94 // going TO the syncer, not from. 92 // going TO the syncer, not from.
95 const std::string& GetTitle() const; 93 const std::string& GetTitle() const;
96 94
97 // Returns the last motification time according to the server. This is
98 // only valid if IsLocal() is false, and may be null if the SyncData
99 // represents a deleted item.
100 const base::Time& GetRemoteModifiedTime() const;
101
102 // Should only be called by sync code when IsLocal() is false.
103 int64 GetRemoteId() const;
104
105 // Whether this sync data is for local data or data coming from the syncer. 95 // Whether this sync data is for local data or data coming from the syncer.
106 bool IsLocal() const; 96 bool IsLocal() const;
107 97
108 // TODO(maniscalco): Reduce the dependence on knowing whether a SyncData is
109 // local (in the IsLocal() == true sense) or remote. Make it harder for users
110 // of SyncData to accidentally call local-only methods on a remote SyncData
111 // (bug 357305).
112
113 std::string ToString() const; 98 std::string ToString() const;
114 99
115 // Return a list of this SyncData's attachment ids. 100 // Return a list of this SyncData's attachment ids.
116 // 101 //
117 // The attachments may or may not be present on this device. 102 // The attachments may or may not be present on this device.
118 AttachmentIdList GetAttachmentIds() const; 103 AttachmentIdList GetAttachmentIds() const;
119 104
120 // Return a list of this SyncData's attachments.
121 //
122 // May only be called when IsLocal() is true.
123 const AttachmentList& GetLocalAttachmentsForUpload() const;
124
125 // Retrieve the attachments indentified by |attachment_ids|. Invoke |callback|
126 // with the requested attachments.
127 //
128 // May only be called when IsLocal() is false.
129 //
130 // |callback| will be invoked when the operation is complete (successfully or
131 // otherwise).
132 //
133 // Retrieving the requested attachments may require reading local storage or
134 // requesting the attachments from the network.
135 //
136 void GetOrDownloadAttachments(
137 const AttachmentIdList& attachment_ids,
138 const AttachmentService::GetOrDownloadCallback& callback);
139
140 // Drop (delete from local storage) the attachments associated with this
141 // SyncData specified in |attachment_ids|. This method will not delete
142 // attachments from the server.
143 //
144 // May only be called when IsLocal() is false.
145 //
146 // |callback| will be invoked when the operation is complete (successfully or
147 // otherwise).
148 void DropAttachments(const AttachmentIdList& attachment_ids,
149 const AttachmentService::DropCallback& callback);
150
151 // TODO(zea): Query methods for other sync properties: parent, successor, etc. 105 // TODO(zea): Query methods for other sync properties: parent, successor, etc.
152 106
153 private: 107 protected:
108 // These data members are protected so derived types like SyncDataLocal and
109 // SyncDataRemote can access them.
110
154 // Necessary since we forward-declare sync_pb::SyncEntity; see 111 // Necessary since we forward-declare sync_pb::SyncEntity; see
155 // comments in immutable.h. 112 // comments in immutable.h.
156 struct ImmutableSyncEntityTraits { 113 struct ImmutableSyncEntityTraits {
157 typedef sync_pb::SyncEntity* Wrapper; 114 typedef sync_pb::SyncEntity* Wrapper;
158 115
159 static void InitializeWrapper(Wrapper* wrapper); 116 static void InitializeWrapper(Wrapper* wrapper);
160 117
161 static void DestroyWrapper(Wrapper* wrapper); 118 static void DestroyWrapper(Wrapper* wrapper);
162 119
163 static const sync_pb::SyncEntity& Unwrap(const Wrapper& wrapper); 120 static const sync_pb::SyncEntity& Unwrap(const Wrapper& wrapper);
164 121
165 static sync_pb::SyncEntity* UnwrapMutable(Wrapper* wrapper); 122 static sync_pb::SyncEntity* UnwrapMutable(Wrapper* wrapper);
166 123
167 static void Swap(sync_pb::SyncEntity* t1, sync_pb::SyncEntity* t2); 124 static void Swap(sync_pb::SyncEntity* t1, sync_pb::SyncEntity* t2);
168 }; 125 };
169 126
170 typedef Immutable<sync_pb::SyncEntity, ImmutableSyncEntityTraits> 127 typedef Immutable<sync_pb::SyncEntity, ImmutableSyncEntityTraits>
171 ImmutableSyncEntity; 128 ImmutableSyncEntity;
172 129
173 // Clears |entity| and |attachments|.
174 SyncData(
175 int64 id,
176 sync_pb::SyncEntity* entity,
177 AttachmentList* attachments,
178 const base::Time& remote_modification_time,
179 const syncer::AttachmentServiceProxy& attachment_service);
180
181 // Whether this SyncData holds valid data.
182 bool is_valid_;
183
184 // Equal to kInvalidId iff this is local. 130 // Equal to kInvalidId iff this is local.
185 int64 id_; 131 int64 id_;
186 132
187 // This is only valid if IsLocal() is false, and may be null if the 133 // This may be null if the SyncData represents a deleted item.
188 // SyncData represents a deleted item.
189 base::Time remote_modification_time_; 134 base::Time remote_modification_time_;
190 135
191 // The actual shared sync entity being held. 136 // The actual shared sync entity being held.
192 ImmutableSyncEntity immutable_entity_; 137 ImmutableSyncEntity immutable_entity_;
193 138
194 Immutable<AttachmentList> attachments_; 139 Immutable<AttachmentList> attachments_;
195 140
196 AttachmentServiceProxy attachment_service_; 141 AttachmentServiceProxy attachment_service_;
142
143 private:
144 // Whether this SyncData holds valid data.
145 bool is_valid_;
146
147 // Clears |entity| and |attachments|.
148 SyncData(int64 id,
149 sync_pb::SyncEntity* entity,
150 AttachmentList* attachments,
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 a list of this SyncData's attachments.
165 const AttachmentList& GetLocalAttachmentsForUpload() const;
166
167 // Return the value of the unique client tag. This is only set for data going
168 // TO the syncer, not coming from.
169 const std::string& GetTag() const;
170 };
171
172 // A SyncData that comes from the syncer.
173 class SYNC_EXPORT SyncDataRemote : public SyncData {
174 public:
175 // Construct a SyncDataRemote from a SyncData.
176 //
177 // |sync_data|'s IsLocal() must be false.
178 explicit SyncDataRemote(const SyncData& sync_data);
179 ~SyncDataRemote();
180
181 // Return the last motification time according to the server. This may be null
182 // if the SyncData represents a deleted item.
183 const base::Time& GetModifiedTime() const;
184
185 int64 GetId() const;
186
187 // Retrieve the attachments indentified by |attachment_ids|. Invoke
188 // |callback| with the requested attachments.
189 //
190 // |callback| will be invoked when the operation is complete (successfully
191 // or otherwise).
192 //
193 // Retrieving the requested attachments may require reading local storage or
194 // requesting the attachments from the network.
195 //
196 void GetOrDownloadAttachments(
197 const AttachmentIdList& attachment_ids,
198 const AttachmentService::GetOrDownloadCallback& callback);
199
200 // Drop (delete from local storage) the attachments associated with this
201 // SyncData specified in |attachment_ids|. This method will not delete
202 // attachments from the server.
203 //
204 // |callback| will be invoked when the operation is complete (successfully
205 // or otherwise).
206 void DropAttachments(const AttachmentIdList& attachment_ids,
207 const AttachmentService::DropCallback& callback);
197 }; 208 };
198 209
199 // gmock printer helper. 210 // gmock printer helper.
200 void PrintTo(const SyncData& sync_data, std::ostream* os); 211 void PrintTo(const SyncData& sync_data, std::ostream* os);
201 212
202 typedef std::vector<SyncData> SyncDataList; 213 typedef std::vector<SyncData> SyncDataList;
203 214
204 } // namespace syncer 215 } // namespace syncer
205 216
206 #endif // SYNC_API_SYNC_DATA_H_ 217 #endif // SYNC_API_SYNC_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698