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 10 matching lines...) Expand all Loading... | |
| 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 Loading... | |
| 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 | 98 // Construct a SyncDataLocal from this SyncData. |
| 109 // local (in the IsLocal() == true sense) or remote. Make it harder for users | 99 // |
| 110 // of SyncData to accidentally call local-only methods on a remote SyncData | 100 // Can only be called when IsLocal() is true. |
| 111 // (bug 357305). | 101 SyncDataLocal AsLocal() const; |
|
tim (not reviewing)
2014/03/31 22:38:12
Hmm. Given that there's no way (that doesn't invol
maniscalco
2014/03/31 23:11:07
Done. I've removed AsLocal/AsRemote and added DCH
| |
| 102 | |
| 103 // Construct a SyncDataRemote from this SyncData. | |
| 104 // | |
| 105 // Can only be called when IsLocal() is false. | |
| 106 SyncDataRemote AsRemote() const; | |
| 112 | 107 |
| 113 std::string ToString() const; | 108 std::string ToString() const; |
| 114 | 109 |
| 115 // Return a list of this SyncData's attachment ids. | 110 // Return a list of this SyncData's attachment ids. |
| 116 // | 111 // |
| 117 // The attachments may or may not be present on this device. | 112 // The attachments may or may not be present on this device. |
| 118 AttachmentIdList GetAttachmentIds() const; | 113 AttachmentIdList GetAttachmentIds() const; |
| 119 | 114 |
| 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. | 115 // TODO(zea): Query methods for other sync properties: parent, successor, etc. |
| 152 | 116 |
| 153 private: | 117 protected: |
| 118 // These data members are protected so derived types like SyncDataLocal and | |
| 119 // SyncDataRemote can access them. | |
| 120 | |
| 154 // Necessary since we forward-declare sync_pb::SyncEntity; see | 121 // Necessary since we forward-declare sync_pb::SyncEntity; see |
| 155 // comments in immutable.h. | 122 // comments in immutable.h. |
| 156 struct ImmutableSyncEntityTraits { | 123 struct ImmutableSyncEntityTraits { |
| 157 typedef sync_pb::SyncEntity* Wrapper; | 124 typedef sync_pb::SyncEntity* Wrapper; |
| 158 | 125 |
| 159 static void InitializeWrapper(Wrapper* wrapper); | 126 static void InitializeWrapper(Wrapper* wrapper); |
| 160 | 127 |
| 161 static void DestroyWrapper(Wrapper* wrapper); | 128 static void DestroyWrapper(Wrapper* wrapper); |
| 162 | 129 |
| 163 static const sync_pb::SyncEntity& Unwrap(const Wrapper& wrapper); | 130 static const sync_pb::SyncEntity& Unwrap(const Wrapper& wrapper); |
| 164 | 131 |
| 165 static sync_pb::SyncEntity* UnwrapMutable(Wrapper* wrapper); | 132 static sync_pb::SyncEntity* UnwrapMutable(Wrapper* wrapper); |
| 166 | 133 |
| 167 static void Swap(sync_pb::SyncEntity* t1, sync_pb::SyncEntity* t2); | 134 static void Swap(sync_pb::SyncEntity* t1, sync_pb::SyncEntity* t2); |
| 168 }; | 135 }; |
| 169 | 136 |
| 170 typedef Immutable<sync_pb::SyncEntity, ImmutableSyncEntityTraits> | 137 typedef Immutable<sync_pb::SyncEntity, ImmutableSyncEntityTraits> |
| 171 ImmutableSyncEntity; | 138 ImmutableSyncEntity; |
| 172 | 139 |
| 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. | 140 // Equal to kInvalidId iff this is local. |
| 185 int64 id_; | 141 int64 id_; |
| 186 | 142 |
| 187 // This is only valid if IsLocal() is false, and may be null if the | 143 // This may be null if the SyncData represents a deleted item. |
| 188 // SyncData represents a deleted item. | |
| 189 base::Time remote_modification_time_; | 144 base::Time remote_modification_time_; |
| 190 | 145 |
| 191 // The actual shared sync entity being held. | 146 // The actual shared sync entity being held. |
| 192 ImmutableSyncEntity immutable_entity_; | 147 ImmutableSyncEntity immutable_entity_; |
| 193 | 148 |
| 194 Immutable<AttachmentList> attachments_; | 149 Immutable<AttachmentList> attachments_; |
| 195 | 150 |
| 196 AttachmentServiceProxy attachment_service_; | 151 AttachmentServiceProxy attachment_service_; |
| 152 | |
| 153 private: | |
| 154 // Whether this SyncData holds valid data. | |
| 155 bool is_valid_; | |
| 156 | |
| 157 // Clears |entity| and |attachments|. | |
| 158 SyncData(int64 id, | |
| 159 sync_pb::SyncEntity* entity, | |
| 160 AttachmentList* attachments, | |
| 161 const base::Time& remote_modification_time, | |
| 162 const syncer::AttachmentServiceProxy& attachment_service); | |
| 163 }; | |
| 164 | |
| 165 // As SyncData going to the syncer. | |
|
tim (not reviewing)
2014/03/31 22:38:12
nit - A SyncData
maniscalco
2014/03/31 23:11:07
Done.
| |
| 166 class SYNC_EXPORT SyncDataLocal : public SyncData { | |
| 167 public: | |
| 168 explicit SyncDataLocal(const SyncData& sync_data); | |
| 169 ~SyncDataLocal(); | |
| 170 | |
| 171 // Return a list of this SyncData's attachments. | |
| 172 const AttachmentList& GetLocalAttachmentsForUpload() const; | |
| 173 | |
| 174 // Return the value of the unique client tag. This is only set for data going | |
| 175 // TO the syncer, not coming from. | |
| 176 const std::string& GetTag() const; | |
| 177 }; | |
| 178 | |
| 179 // A SyncData that comes from the syncer. | |
| 180 class SYNC_EXPORT SyncDataRemote : public SyncData { | |
| 181 public: | |
| 182 explicit SyncDataRemote(const SyncData& sync_data); | |
| 183 ~SyncDataRemote(); | |
| 184 | |
| 185 // Return the last motification time according to the server. This may be null | |
| 186 // if the SyncData represents a deleted item. | |
| 187 const base::Time& GetModifiedTime() const; | |
| 188 | |
| 189 int64 GetId() const; | |
| 190 | |
| 191 // Retrieve the attachments indentified by |attachment_ids|. Invoke | |
| 192 // |callback| with the requested attachments. | |
| 193 // | |
| 194 // |callback| will be invoked when the operation is complete (successfully | |
| 195 // or otherwise). | |
| 196 // | |
| 197 // Retrieving the requested attachments may require reading local storage or | |
| 198 // requesting the attachments from the network. | |
| 199 // | |
| 200 void GetOrDownloadAttachments( | |
| 201 const AttachmentIdList& attachment_ids, | |
| 202 const AttachmentService::GetOrDownloadCallback& callback); | |
| 203 | |
| 204 // Drop (delete from local storage) the attachments associated with this | |
| 205 // SyncData specified in |attachment_ids|. This method will not delete | |
| 206 // attachments from the server. | |
| 207 // | |
| 208 // |callback| will be invoked when the operation is complete (successfully | |
| 209 // or otherwise). | |
| 210 void DropAttachments(const AttachmentIdList& attachment_ids, | |
| 211 const AttachmentService::DropCallback& callback); | |
| 197 }; | 212 }; |
| 198 | 213 |
| 199 // gmock printer helper. | 214 // gmock printer helper. |
| 200 void PrintTo(const SyncData& sync_data, std::ostream* os); | 215 void PrintTo(const SyncData& sync_data, std::ostream* os); |
| 201 | 216 |
| 202 typedef std::vector<SyncData> SyncDataList; | 217 typedef std::vector<SyncData> SyncDataList; |
| 203 | 218 |
| 204 } // namespace syncer | 219 } // namespace syncer |
| 205 | 220 |
| 206 #endif // SYNC_API_SYNC_DATA_H_ | 221 #endif // SYNC_API_SYNC_DATA_H_ |
| OLD | NEW |