Chromium Code Reviews| 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> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 // without valid data is to use the default constructor. | 79 // without valid data is to use the default constructor. |
| 80 bool IsValid() const; | 80 bool IsValid() const; |
| 81 | 81 |
| 82 // Return the datatype we're holding information about. Derived from the sync | 82 // Return the datatype we're holding information about. Derived from the sync |
| 83 // datatype specifics. | 83 // datatype specifics. |
| 84 ModelType GetDataType() const; | 84 ModelType GetDataType() const; |
| 85 | 85 |
| 86 // Return the current sync datatype specifics. | 86 // Return the current sync datatype specifics. |
| 87 const sync_pb::EntitySpecifics& GetSpecifics() const; | 87 const sync_pb::EntitySpecifics& GetSpecifics() const; |
| 88 | 88 |
| 89 // Returns the value of the unique client tag. This is only set for data going | |
| 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 | 89 // Returns the non unique title (for debugging). Currently only set for data |
| 94 // going TO the syncer, not from. | 90 // going TO the syncer, not from. |
| 95 const std::string& GetTitle() const; | 91 const std::string& GetTitle() const; |
| 96 | 92 |
| 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. | 93 // Whether this sync data is for local data or data coming from the syncer. |
| 106 bool IsLocal() const; | 94 bool IsLocal() const; |
| 107 | 95 |
| 108 // TODO(maniscalco): Reduce the dependence on knowing whether a SyncData is | 96 // 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 | 97 // 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 | 98 // of SyncData to accidentally call local-only methods on a remote SyncData |
| 111 // (bug 357305). | 99 // (bug 357305). |
| 112 | 100 |
| 113 std::string ToString() const; | 101 std::string ToString() const; |
| 114 | 102 |
| 115 // Return a list of this SyncData's attachment ids. | 103 // Return a list of this SyncData's attachment ids. |
| 116 // | 104 // |
| 117 // The attachments may or may not be present on this device. | 105 // The attachments may or may not be present on this device. |
| 118 AttachmentIdList GetAttachmentIds() const; | 106 AttachmentIdList GetAttachmentIds() const; |
| 119 | 107 |
| 120 // Return a list of this SyncData's attachments. | 108 // TODO(zea): Query methods for other sync properties: parent, successor, etc. |
| 109 | |
| 110 // This class is comprised of methods that operate on "local" SyncData. That | |
| 111 // is, SyncData where IsLocal() == true. See also local(). | |
| 112 class Local { | |
|
tim (not reviewing)
2014/03/28 21:16:02
I guess I was imagining we would organize the data
maniscalco
2014/03/28 21:45:13
Re organizing the data at construction time... I e
| |
| 113 public: | |
| 114 // Return a list of this SyncData's attachments. | |
| 115 // | |
| 116 // May only be called when IsLocal() is true. | |
| 117 const AttachmentList& GetLocalAttachmentsForUpload() const; | |
| 118 | |
| 119 // Returns the value of the unique client tag. This is only set for data | |
| 120 // going TO the syncer, not coming from. | |
| 121 const std::string& GetTag() const; | |
| 122 | |
| 123 private: | |
| 124 friend SyncData; | |
|
tim (not reviewing)
2014/03/28 21:16:02
Do you actually need the friend?
maniscalco
2014/03/28 21:45:13
Yeah, I was using it along with the private Local
| |
| 125 Local(SyncData* sync_data) : sync_data_(sync_data) {} | |
| 126 | |
| 127 SyncData* sync_data_; | |
| 128 }; | |
| 129 | |
| 130 // Used to access Local methods. | |
| 121 // | 131 // |
| 122 // May only be called when IsLocal() is true. | 132 // May only be called when IsLocal() is true. |
| 123 const AttachmentList& GetLocalAttachmentsForUpload() const; | 133 const Local& local() const; |
| 124 | 134 |
| 125 // Retrieve the attachments indentified by |attachment_ids|. Invoke |callback| | 135 // This class is comprised of methods that operate on "remote" SyncData. That |
| 126 // with the requested attachments. | 136 // is, SyncData where IsLocal() == false. See also remote(). |
| 137 class Remote { | |
| 138 public: | |
| 139 // Returns the last motification time according to the server. This is | |
| 140 // only valid if IsLocal() is false, and may be null if the SyncData | |
| 141 // represents a deleted item. | |
| 142 const base::Time& GetRemoteModifiedTime() const; | |
| 143 | |
| 144 // Should only be called by sync code when IsLocal() is false. | |
| 145 int64 GetRemoteId() const; | |
|
tim (not reviewing)
2014/03/28 21:16:02
I think 'Remote' in names of methods is redundant
maniscalco
2014/03/28 21:45:13
Agreed. Removed.
| |
| 146 | |
| 147 // Retrieve the attachments indentified by |attachment_ids|. Invoke | |
| 148 // |callback| with the requested attachments. | |
| 149 // | |
| 150 // May only be called when IsLocal() is false. | |
| 151 // | |
| 152 // |callback| will be invoked when the operation is complete (successfully | |
| 153 // or otherwise). | |
| 154 // | |
| 155 // Retrieving the requested attachments may require reading local storage or | |
| 156 // requesting the attachments from the network. | |
| 157 // | |
| 158 void GetOrDownloadAttachments( | |
| 159 const AttachmentIdList& attachment_ids, | |
| 160 const AttachmentService::GetOrDownloadCallback& callback); | |
| 161 | |
| 162 // Drop (delete from local storage) the attachments associated with this | |
| 163 // SyncData specified in |attachment_ids|. This method will not delete | |
| 164 // attachments from the server. | |
| 165 // | |
| 166 // May only be called when IsLocal() is false. | |
| 167 // | |
| 168 // |callback| will be invoked when the operation is complete (successfully | |
| 169 // or otherwise). | |
| 170 void DropAttachments(const AttachmentIdList& attachment_ids, | |
| 171 const AttachmentService::DropCallback& callback); | |
| 172 | |
| 173 private: | |
| 174 friend SyncData; | |
| 175 Remote(SyncData* sync_data) : sync_data_(sync_data) {} | |
| 176 | |
| 177 SyncData* sync_data_; | |
| 178 }; | |
| 179 | |
| 180 // Used to access Remote methods. | |
| 127 // | 181 // |
| 128 // May only be called when IsLocal() is false. | 182 // May only be called when IsLocal() is false. |
| 129 // | 183 Remote& remote(); |
| 130 // |callback| will be invoked when the operation is complete (successfully or | 184 const Remote& remote() const; |
| 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. | |
| 152 | 185 |
| 153 private: | 186 private: |
| 187 friend Local; | |
| 188 friend Remote; | |
| 189 | |
| 154 // Necessary since we forward-declare sync_pb::SyncEntity; see | 190 // Necessary since we forward-declare sync_pb::SyncEntity; see |
| 155 // comments in immutable.h. | 191 // comments in immutable.h. |
| 156 struct ImmutableSyncEntityTraits { | 192 struct ImmutableSyncEntityTraits { |
| 157 typedef sync_pb::SyncEntity* Wrapper; | 193 typedef sync_pb::SyncEntity* Wrapper; |
| 158 | 194 |
| 159 static void InitializeWrapper(Wrapper* wrapper); | 195 static void InitializeWrapper(Wrapper* wrapper); |
| 160 | 196 |
| 161 static void DestroyWrapper(Wrapper* wrapper); | 197 static void DestroyWrapper(Wrapper* wrapper); |
| 162 | 198 |
| 163 static const sync_pb::SyncEntity& Unwrap(const Wrapper& wrapper); | 199 static const sync_pb::SyncEntity& Unwrap(const Wrapper& wrapper); |
| 164 | 200 |
| 165 static sync_pb::SyncEntity* UnwrapMutable(Wrapper* wrapper); | 201 static sync_pb::SyncEntity* UnwrapMutable(Wrapper* wrapper); |
| 166 | 202 |
| 167 static void Swap(sync_pb::SyncEntity* t1, sync_pb::SyncEntity* t2); | 203 static void Swap(sync_pb::SyncEntity* t1, sync_pb::SyncEntity* t2); |
| 168 }; | 204 }; |
| 169 | 205 |
| 170 typedef Immutable<sync_pb::SyncEntity, ImmutableSyncEntityTraits> | 206 typedef Immutable<sync_pb::SyncEntity, ImmutableSyncEntityTraits> |
| 171 ImmutableSyncEntity; | 207 ImmutableSyncEntity; |
| 172 | 208 |
| 173 // Clears |entity| and |attachments|. | 209 // Clears |entity| and |attachments|. |
| 174 SyncData( | 210 SyncData( |
| 175 int64 id, | 211 int64 id, |
| 176 sync_pb::SyncEntity* entity, | 212 sync_pb::SyncEntity* entity, |
| 177 AttachmentList* attachments, | 213 AttachmentList* attachments, |
| 178 const base::Time& remote_modification_time, | 214 const base::Time& remote_modification_time, |
| 179 const syncer::AttachmentServiceProxy& attachment_service); | 215 const syncer::AttachmentServiceProxy& attachment_service); |
| 180 | 216 |
| 217 Local local_; | |
| 218 Remote remote_; | |
| 219 | |
| 181 // Whether this SyncData holds valid data. | 220 // Whether this SyncData holds valid data. |
| 182 bool is_valid_; | 221 bool is_valid_; |
| 183 | 222 |
| 184 // Equal to kInvalidId iff this is local. | 223 // Equal to kInvalidId iff this is local. |
| 185 int64 id_; | 224 int64 id_; |
| 186 | 225 |
| 187 // This is only valid if IsLocal() is false, and may be null if the | 226 // This is only valid if IsLocal() is false, and may be null if the |
| 188 // SyncData represents a deleted item. | 227 // SyncData represents a deleted item. |
| 189 base::Time remote_modification_time_; | 228 base::Time remote_modification_time_; |
| 190 | 229 |
| 191 // The actual shared sync entity being held. | 230 // The actual shared sync entity being held. |
| 192 ImmutableSyncEntity immutable_entity_; | 231 ImmutableSyncEntity immutable_entity_; |
| 193 | 232 |
| 194 Immutable<AttachmentList> attachments_; | 233 Immutable<AttachmentList> attachments_; |
| 195 | 234 |
| 196 AttachmentServiceProxy attachment_service_; | 235 AttachmentServiceProxy attachment_service_; |
| 197 }; | 236 }; |
| 198 | 237 |
| 199 // gmock printer helper. | 238 // gmock printer helper. |
| 200 void PrintTo(const SyncData& sync_data, std::ostream* os); | 239 void PrintTo(const SyncData& sync_data, std::ostream* os); |
| 201 | 240 |
| 202 typedef std::vector<SyncData> SyncDataList; | 241 typedef std::vector<SyncData> SyncDataList; |
| 203 | 242 |
| 204 } // namespace syncer | 243 } // namespace syncer |
| 205 | 244 |
| 206 #endif // SYNC_API_SYNC_DATA_H_ | 245 #endif // SYNC_API_SYNC_DATA_H_ |
| OLD | NEW |