OLD | NEW |
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> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "sync/api/attachments/attachment.h" | 17 #include "sync/api/attachments/attachment_id.h" |
18 #include "sync/base/sync_export.h" | 18 #include "sync/base/sync_export.h" |
19 #include "sync/internal_api/public/attachments/attachment_service_proxy.h" | 19 #include "sync/internal_api/public/attachments/attachment_service_proxy.h" |
20 #include "sync/internal_api/public/base/model_type.h" | 20 #include "sync/internal_api/public/base/model_type.h" |
21 #include "sync/internal_api/public/util/immutable.h" | 21 #include "sync/internal_api/public/util/immutable.h" |
22 #include "sync/internal_api/public/util/weak_handle.h" | 22 #include "sync/internal_api/public/util/weak_handle.h" |
23 | 23 |
24 namespace sync_pb { | 24 namespace sync_pb { |
25 class EntitySpecifics; | 25 class EntitySpecifics; |
26 class SyncEntity; | 26 class SyncEntity; |
27 } // namespace sync_pb | 27 } // namespace sync_pb |
(...skipping 20 matching lines...) Expand all Loading... |
48 // identifier server-side. | 48 // identifier server-side. |
49 // | 49 // |
50 // For deletes: |datatype| must specify the datatype who node is being | 50 // For deletes: |datatype| must specify the datatype who node is being |
51 // deleted. | 51 // deleted. |
52 // | 52 // |
53 // For adds/updates: |specifics| must be valid and |non_unique_title| (can be | 53 // For adds/updates: |specifics| must be valid and |non_unique_title| (can be |
54 // the same as |sync_tag|) must be specfied. Note: |non_unique_title| is | 54 // the same as |sync_tag|) must be specfied. Note: |non_unique_title| is |
55 // primarily for debug purposes, and will be overwritten if the datatype is | 55 // primarily for debug purposes, and will be overwritten if the datatype is |
56 // encrypted. | 56 // encrypted. |
57 // | 57 // |
58 // For data with attachments: |attachments| must not contain duplicates. | 58 // For data with attachments: |attachment_ids| must not contain duplicates. |
59 static SyncData CreateLocalDelete( | 59 static SyncData CreateLocalDelete( |
60 const std::string& sync_tag, | 60 const std::string& sync_tag, |
61 ModelType datatype); | 61 ModelType datatype); |
62 static SyncData CreateLocalData( | 62 static SyncData CreateLocalData( |
63 const std::string& sync_tag, | 63 const std::string& sync_tag, |
64 const std::string& non_unique_title, | 64 const std::string& non_unique_title, |
65 const sync_pb::EntitySpecifics& specifics); | 65 const sync_pb::EntitySpecifics& specifics); |
66 static SyncData CreateLocalDataWithAttachments( | 66 static SyncData CreateLocalDataWithAttachments( |
67 const std::string& sync_tag, | 67 const std::string& sync_tag, |
68 const std::string& non_unique_title, | 68 const std::string& non_unique_title, |
69 const sync_pb::EntitySpecifics& specifics, | 69 const sync_pb::EntitySpecifics& specifics, |
70 const AttachmentList& attachments); | 70 const AttachmentIdList& attachment_ids); |
71 | 71 |
72 // Helper method for creating SyncData objects originating from the syncer. | 72 // Helper method for creating SyncData objects originating from the syncer. |
73 static SyncData CreateRemoteData( | 73 static SyncData CreateRemoteData( |
74 int64 id, | 74 int64 id, |
75 const sync_pb::EntitySpecifics& specifics, | 75 const sync_pb::EntitySpecifics& specifics, |
76 const base::Time& last_modified_time, | 76 const base::Time& last_modified_time, |
77 const AttachmentIdList& attachment_ids, | 77 const AttachmentIdList& attachment_ids, |
78 const syncer::AttachmentServiceProxy& attachment_service); | 78 const syncer::AttachmentServiceProxy& attachment_service); |
79 | 79 |
80 // Whether this SyncData holds valid data. The only way to have a SyncData | 80 // Whether this SyncData holds valid data. The only way to have a SyncData |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 // Equal to kInvalidId iff this is local. | 130 // Equal to kInvalidId iff this is local. |
131 int64 id_; | 131 int64 id_; |
132 | 132 |
133 // This may be null if the SyncData represents a deleted item. | 133 // This may be null if the SyncData represents a deleted item. |
134 base::Time remote_modification_time_; | 134 base::Time remote_modification_time_; |
135 | 135 |
136 // The actual shared sync entity being held. | 136 // The actual shared sync entity being held. |
137 ImmutableSyncEntity immutable_entity_; | 137 ImmutableSyncEntity immutable_entity_; |
138 | 138 |
139 Immutable<AttachmentList> attachments_; | |
140 | |
141 AttachmentServiceProxy attachment_service_; | 139 AttachmentServiceProxy attachment_service_; |
142 | 140 |
143 private: | 141 private: |
144 // Whether this SyncData holds valid data. | 142 // Whether this SyncData holds valid data. |
145 bool is_valid_; | 143 bool is_valid_; |
146 | 144 |
147 // Clears |entity| and |attachments|. | 145 // Clears |entity| and |attachments|. |
148 SyncData(int64 id, | 146 SyncData(int64 id, |
149 sync_pb::SyncEntity* entity, | 147 sync_pb::SyncEntity* entity, |
150 AttachmentList* attachments, | |
151 const base::Time& remote_modification_time, | 148 const base::Time& remote_modification_time, |
152 const syncer::AttachmentServiceProxy& attachment_service); | 149 const syncer::AttachmentServiceProxy& attachment_service); |
153 }; | 150 }; |
154 | 151 |
155 // A SyncData going to the syncer. | 152 // A SyncData going to the syncer. |
156 class SYNC_EXPORT SyncDataLocal : public SyncData { | 153 class SYNC_EXPORT SyncDataLocal : public SyncData { |
157 public: | 154 public: |
158 // Construct a SyncDataLocal from a SyncData. | 155 // Construct a SyncDataLocal from a SyncData. |
159 // | 156 // |
160 // |sync_data|'s IsLocal() must be true. | 157 // |sync_data|'s IsLocal() must be true. |
161 explicit SyncDataLocal(const SyncData& sync_data); | 158 explicit SyncDataLocal(const SyncData& sync_data); |
162 ~SyncDataLocal(); | 159 ~SyncDataLocal(); |
163 | 160 |
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 | 161 // Return the value of the unique client tag. This is only set for data going |
168 // TO the syncer, not coming from. | 162 // TO the syncer, not coming from. |
169 const std::string& GetTag() const; | 163 const std::string& GetTag() const; |
170 }; | 164 }; |
171 | 165 |
172 // A SyncData that comes from the syncer. | 166 // A SyncData that comes from the syncer. |
173 class SYNC_EXPORT SyncDataRemote : public SyncData { | 167 class SYNC_EXPORT SyncDataRemote : public SyncData { |
174 public: | 168 public: |
175 // Construct a SyncDataRemote from a SyncData. | 169 // Construct a SyncDataRemote from a SyncData. |
176 // | 170 // |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 }; | 202 }; |
209 | 203 |
210 // gmock printer helper. | 204 // gmock printer helper. |
211 void PrintTo(const SyncData& sync_data, std::ostream* os); | 205 void PrintTo(const SyncData& sync_data, std::ostream* os); |
212 | 206 |
213 typedef std::vector<SyncData> SyncDataList; | 207 typedef std::vector<SyncData> SyncDataList; |
214 | 208 |
215 } // namespace syncer | 209 } // namespace syncer |
216 | 210 |
217 #endif // SYNC_API_SYNC_DATA_H_ | 211 #endif // SYNC_API_SYNC_DATA_H_ |
OLD | NEW |