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" | |
14 #include "base/stl_util.h" | |
13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "sync/api/attachments/attachment.h" | |
17 #include "sync/api/attachments/attachment_service.h" | |
14 #include "sync/base/sync_export.h" | 18 #include "sync/base/sync_export.h" |
15 #include "sync/internal_api/public/base/model_type.h" | 19 #include "sync/internal_api/public/base/model_type.h" |
16 #include "sync/internal_api/public/util/immutable.h" | 20 #include "sync/internal_api/public/util/immutable.h" |
21 #include "sync/internal_api/public/util/weak_handle.h" | |
17 | 22 |
18 namespace sync_pb { | 23 namespace sync_pb { |
19 class EntitySpecifics; | 24 class EntitySpecifics; |
20 class SyncEntity; | 25 class SyncEntity; |
21 } // namespace sync_pb | 26 } // namespace sync_pb |
22 | 27 |
23 namespace syncer { | 28 namespace syncer { |
24 | 29 |
30 class AttachmentService; | |
31 | |
25 // A light-weight container for immutable sync data. Pass-by-value and storage | 32 // A light-weight container for immutable sync data. Pass-by-value and storage |
26 // in STL containers are supported and encouraged if helpful. | 33 // in STL containers are supported and encouraged if helpful. |
27 class SYNC_EXPORT SyncData { | 34 class SYNC_EXPORT SyncData { |
28 public: | 35 public: |
29 // Creates an empty and invalid SyncData. | 36 // Creates an empty and invalid SyncData. |
30 SyncData(); | 37 SyncData(); |
31 ~SyncData(); | 38 ~SyncData(); |
32 | 39 |
33 // Default copy and assign welcome. | 40 // Default copy and assign welcome. |
34 | 41 |
35 // Helper methods for creating SyncData objects for local data. | 42 // Helper methods for creating SyncData objects for local data. |
36 // The sync tag must be a string unique to this datatype and is used as a node | 43 // The sync tag must be a string unique to this datatype and is used as a node |
37 // identifier server-side. | 44 // identifier server-side. |
38 // For deletes: |datatype| must specify the datatype who node is being | 45 // For deletes: |datatype| must specify the datatype who node is being |
39 // deleted. | 46 // deleted. |
40 // For adds/updates: the specifics must be valid and the non-unique title (can | 47 // For adds/updates: the specifics must be valid and the non-unique title (can |
41 // be the same as sync tag) must be specfied. | 48 // be the same as sync tag) must be specfied. |
42 // Note: the non_unique_title is primarily for debug purposes, and will be | 49 // Note: the non_unique_title is primarily for debug purposes, and will be |
43 // overwritten if the datatype is encrypted. | 50 // overwritten if the datatype is encrypted. |
44 static SyncData CreateLocalDelete( | 51 static SyncData CreateLocalDelete( |
45 const std::string& sync_tag, | 52 const std::string& sync_tag, |
46 ModelType datatype); | 53 ModelType datatype); |
47 static SyncData CreateLocalData( | 54 static SyncData CreateLocalData( |
48 const std::string& sync_tag, | 55 const std::string& sync_tag, |
49 const std::string& non_unique_title, | 56 const std::string& non_unique_title, |
50 const sync_pb::EntitySpecifics& specifics); | 57 const sync_pb::EntitySpecifics& specifics); |
58 static SyncData CreateLocalDataWithAttachments( | |
59 const std::string& sync_tag, | |
60 const std::string& non_unique_title, | |
61 const sync_pb::EntitySpecifics& specifics, | |
62 const AttachmentList& attachments); | |
51 | 63 |
52 // Helper method for creating SyncData objects originating from the syncer. | 64 // Helper method for creating SyncData objects originating from the syncer. |
65 // | |
66 // TODO(maniscalco): Replace all calls to 3-arg CreateRemoteData with calls to | |
67 // the 4-arg version. | |
tim (not reviewing)
2014/03/10 22:55:58
For stuff like this, a recommended chromium conven
maniscalco
2014/03/18 20:49:18
Thanks for the reminder. Done.
| |
68 // | |
tim (not reviewing)
2014/03/10 22:55:58
Remove the trailing // line.
maniscalco
2014/03/18 20:49:18
Done.
| |
53 static SyncData CreateRemoteData( | 69 static SyncData CreateRemoteData( |
54 int64 id, | 70 int64 id, |
55 const sync_pb::EntitySpecifics& specifics, | 71 const sync_pb::EntitySpecifics& specifics, |
56 const base::Time& last_modified_time); | 72 const base::Time& last_modified_time, |
73 const WeakHandle<syncer::AttachmentService>& attachment_service, | |
74 const AttachmentIdList& attachment_ids); | |
75 static SyncData CreateRemoteData(int64 id, | |
76 const sync_pb::EntitySpecifics& specifics, | |
77 const base::Time& last_modified_time); | |
57 | 78 |
58 // Whether this SyncData holds valid data. The only way to have a SyncData | 79 // Whether this SyncData holds valid data. The only way to have a SyncData |
59 // without valid data is to use the default constructor. | 80 // without valid data is to use the default constructor. |
60 bool IsValid() const; | 81 bool IsValid() const; |
61 | 82 |
62 // Return the datatype we're holding information about. Derived from the sync | 83 // Return the datatype we're holding information about. Derived from the sync |
63 // datatype specifics. | 84 // datatype specifics. |
64 ModelType GetDataType() const; | 85 ModelType GetDataType() const; |
65 | 86 |
66 // Return the current sync datatype specifics. | 87 // Return the current sync datatype specifics. |
(...skipping 13 matching lines...) Expand all Loading... | |
80 const base::Time& GetRemoteModifiedTime() const; | 101 const base::Time& GetRemoteModifiedTime() const; |
81 | 102 |
82 // Should only be called by sync code when IsLocal() is false. | 103 // Should only be called by sync code when IsLocal() is false. |
83 int64 GetRemoteId() const; | 104 int64 GetRemoteId() const; |
84 | 105 |
85 // Whether this sync data is for local data or data coming from the syncer. | 106 // Whether this sync data is for local data or data coming from the syncer. |
86 bool IsLocal() const; | 107 bool IsLocal() const; |
87 | 108 |
88 std::string ToString() const; | 109 std::string ToString() const; |
89 | 110 |
111 // Return a list of this SyncData's attachment ids. | |
112 // | |
113 // The attachments may or may not be present on this host. | |
114 AttachmentIdList GetAttachmentIds() const; | |
115 | |
116 // Retrieve the attachments indentified by |attachment_ids|. Invoke |callback| | |
117 // with the requested attachments. | |
118 // | |
119 // May only be called when IsLocal() is false. | |
120 // | |
121 // |callback| will be invoked when the operation is complete (successfully or | |
122 // otherwise). | |
123 // | |
124 // Retrieving the requested attachments may require reading local storage or | |
125 // requesting the attachments from the network. | |
126 // | |
127 void GetAttachments(const AttachmentIdList& attachment_ids, | |
tim (not reviewing)
2014/03/10 22:55:58
As in the other file, I'm wondering if we should e
maniscalco
2014/03/18 20:49:18
Good point. I agree. I would like the verb to mo
tim (not reviewing)
2014/03/19 22:32:48
How about 'Get' as you say and 'GetOrDownload', th
maniscalco
2014/03/25 21:40:30
Done.
| |
128 const AttachmentService::GetCallback& callback); | |
129 | |
130 // Drop (delete locally) the attachments associated with this SyncData | |
131 // specified in |attachment_ids|. This method will not delete attachments | |
132 // from the server. | |
133 // | |
134 // May only be called when IsLocal() is false. | |
135 // | |
136 // |callback| will be invoked when the operation is complete (successfully or | |
137 // otherwise). | |
138 void DropAttachments(const AttachmentIdList& attachment_ids, | |
tim (not reviewing)
2014/03/10 22:55:58
We talked about this but pointing out for posterit
maniscalco
2014/03/18 20:49:18
Agreed.
| |
139 const AttachmentService::DropCallback& callback); | |
140 | |
90 // TODO(zea): Query methods for other sync properties: parent, successor, etc. | 141 // TODO(zea): Query methods for other sync properties: parent, successor, etc. |
91 | 142 |
92 private: | 143 private: |
93 // Necessary since we forward-declare sync_pb::SyncEntity; see | 144 // Necessary since we forward-declare sync_pb::SyncEntity; see |
94 // comments in immutable.h. | 145 // comments in immutable.h. |
95 struct ImmutableSyncEntityTraits { | 146 struct ImmutableSyncEntityTraits { |
96 typedef sync_pb::SyncEntity* Wrapper; | 147 typedef sync_pb::SyncEntity* Wrapper; |
97 | 148 |
98 static void InitializeWrapper(Wrapper* wrapper); | 149 static void InitializeWrapper(Wrapper* wrapper); |
99 | 150 |
100 static void DestroyWrapper(Wrapper* wrapper); | 151 static void DestroyWrapper(Wrapper* wrapper); |
101 | 152 |
102 static const sync_pb::SyncEntity& Unwrap(const Wrapper& wrapper); | 153 static const sync_pb::SyncEntity& Unwrap(const Wrapper& wrapper); |
103 | 154 |
104 static sync_pb::SyncEntity* UnwrapMutable(Wrapper* wrapper); | 155 static sync_pb::SyncEntity* UnwrapMutable(Wrapper* wrapper); |
105 | 156 |
106 static void Swap(sync_pb::SyncEntity* t1, sync_pb::SyncEntity* t2); | 157 static void Swap(sync_pb::SyncEntity* t1, sync_pb::SyncEntity* t2); |
107 }; | 158 }; |
108 | 159 |
109 typedef Immutable<sync_pb::SyncEntity, ImmutableSyncEntityTraits> | 160 typedef Immutable<sync_pb::SyncEntity, ImmutableSyncEntityTraits> |
110 ImmutableSyncEntity; | 161 ImmutableSyncEntity; |
111 | 162 |
112 // Clears |entity|. | 163 // Clears |entity|. |
113 SyncData(int64 id, | 164 SyncData(int64 id, |
114 sync_pb::SyncEntity* entity, | 165 sync_pb::SyncEntity* entity, |
115 const base::Time& remote_modification_time); | 166 const base::Time& remote_modification_time, |
167 const WeakHandle<syncer::AttachmentService>& attachment_service); | |
116 | 168 |
117 // Whether this SyncData holds valid data. | 169 // Whether this SyncData holds valid data. |
118 bool is_valid_; | 170 bool is_valid_; |
119 | 171 |
120 // Equal to kInvalidId iff this is local. | 172 // Equal to kInvalidId iff this is local. |
121 int64 id_; | 173 int64 id_; |
122 | 174 |
123 // This is only valid if IsLocal() is false, and may be null if the | 175 // This is only valid if IsLocal() is false, and may be null if the |
124 // SyncData represents a deleted item. | 176 // SyncData represents a deleted item. |
125 base::Time remote_modification_time_; | 177 base::Time remote_modification_time_; |
126 | 178 |
127 // The actual shared sync entity being held. | 179 // The actual shared sync entity being held. |
128 ImmutableSyncEntity immutable_entity_; | 180 ImmutableSyncEntity immutable_entity_; |
181 | |
182 WeakHandle<AttachmentService> attachment_service_; | |
129 }; | 183 }; |
130 | 184 |
131 // gmock printer helper. | 185 // gmock printer helper. |
132 void PrintTo(const SyncData& sync_data, std::ostream* os); | 186 void PrintTo(const SyncData& sync_data, std::ostream* os); |
133 | 187 |
134 typedef std::vector<SyncData> SyncDataList; | 188 typedef std::vector<SyncData> SyncDataList; |
135 | 189 |
136 } // namespace syncer | 190 } // namespace syncer |
137 | 191 |
138 #endif // SYNC_API_SYNC_DATA_H_ | 192 #endif // SYNC_API_SYNC_DATA_H_ |
OLD | NEW |