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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "sync/base/sync_export.h" | 14 #include "sync/base/sync_export.h" |
| 15 #include "sync/internal_api/public/base/model_type.h" | 15 #include "sync/internal_api/public/base/model_type.h" |
| 16 #include "sync/internal_api/public/util/immutable.h" | 16 #include "sync/internal_api/public/util/immutable.h" |
| 17 | 17 |
| 18 namespace sync_pb { | 18 namespace sync_pb { |
| 19 class EntitySpecifics; | 19 class EntitySpecifics; |
| 20 class SyncEntity; | |
| 21 } // namespace sync_pb | 20 } // namespace sync_pb |
| 22 | 21 |
| 23 namespace syncer { | 22 namespace syncer { |
| 24 | 23 |
| 24 struct SyncDataCore; | |
| 25 | |
| 25 // A light-weight container for immutable sync data. Pass-by-value and storage | 26 // A light-weight container for immutable sync data. Pass-by-value and storage |
| 26 // in STL containers are supported and encouraged if helpful. | 27 // in STL containers are supported and encouraged if helpful. |
| 27 class SYNC_EXPORT SyncData { | 28 class SYNC_EXPORT SyncData { |
| 28 public: | 29 public: |
| 29 // Creates an empty and invalid SyncData. | 30 // Creates an empty and invalid SyncData. |
| 30 SyncData(); | 31 SyncData(); |
| 31 ~SyncData(); | 32 ~SyncData(); |
| 32 | 33 |
| 33 // Default copy and assign welcome. | 34 // Default copy and assign welcome. |
| 34 | 35 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 48 const std::string& sync_tag, | 49 const std::string& sync_tag, |
| 49 const std::string& non_unique_title, | 50 const std::string& non_unique_title, |
| 50 const sync_pb::EntitySpecifics& specifics); | 51 const sync_pb::EntitySpecifics& specifics); |
| 51 | 52 |
| 52 // Helper method for creating SyncData objects originating from the syncer. | 53 // Helper method for creating SyncData objects originating from the syncer. |
| 53 static SyncData CreateRemoteData( | 54 static SyncData CreateRemoteData( |
| 54 int64 id, | 55 int64 id, |
| 55 const sync_pb::EntitySpecifics& specifics, | 56 const sync_pb::EntitySpecifics& specifics, |
| 56 const base::Time& last_modified_time); | 57 const base::Time& last_modified_time); |
| 57 | 58 |
| 59 // For datatype context changes: |datatype| specifies the type whose context | |
| 60 // is being updated. | |
| 61 static SyncData CreateContext(ModelType datatype, const std::string& context); | |
|
maniscalco
2014/03/31 23:59:16
Any reason not to pass datatype by const ref? The
maniscalco
2014/03/31 23:59:16
Are SyncData created by this method "local" or "re
Nicolas Zea
2014/04/02 18:34:36
ModelType is just an enum, so passing by ref is ac
Nicolas Zea
2014/04/02 18:34:36
Neither. I was actually planning to get rid of the
maniscalco
2014/04/02 21:13:09
Pass by value SGTM.
| |
| 62 | |
| 58 // Whether this SyncData holds valid data. The only way to have a SyncData | 63 // Whether this SyncData holds valid data. The only way to have a SyncData |
| 59 // without valid data is to use the default constructor. | 64 // without valid data is to use the default constructor. |
| 60 bool IsValid() const; | 65 bool IsValid() const; |
| 61 | 66 |
| 62 // Return the datatype we're holding information about. Derived from the sync | 67 // Return the datatype we're holding information about. Derived from the sync |
| 63 // datatype specifics. | 68 // datatype specifics. |
| 64 ModelType GetDataType() const; | 69 ModelType GetDataType() const; |
| 65 | 70 |
| 66 // Return the current sync datatype specifics. | 71 // Return the current sync datatype specifics. |
| 67 const sync_pb::EntitySpecifics& GetSpecifics() const; | 72 const sync_pb::EntitySpecifics& GetSpecifics() const; |
| 68 | 73 |
| 69 // Returns the value of the unique client tag. This is only set for data going | 74 // Returns the value of the unique client tag. This is only set for data going |
| 70 // TO the syncer, not coming from. | 75 // TO the syncer, not coming from. |
| 71 const std::string& GetTag() const; | 76 const std::string& GetTag() const; |
| 72 | 77 |
| 73 // Returns the non unique title (for debugging). Currently only set for data | 78 // Returns the non unique title (for debugging). Currently only set for data |
| 74 // going TO the syncer, not from. | 79 // going TO the syncer, not from. |
| 75 const std::string& GetTitle() const; | 80 const std::string& GetTitle() const; |
| 76 | 81 |
| 82 // Returns the datatype context, if one exists. Returns empty string | |
| 83 // otherwise. | |
| 84 const std::string& GetContext() const; | |
| 85 | |
| 77 // Returns the last motification time according to the server. This is | 86 // Returns the last motification time according to the server. This is |
| 78 // only valid if IsLocal() is false, and may be null if the SyncData | 87 // only valid if IsLocal() is false, and may be null if the SyncData |
| 79 // represents a deleted item. | 88 // represents a deleted item. |
| 80 const base::Time& GetRemoteModifiedTime() const; | 89 const base::Time& GetRemoteModifiedTime() const; |
| 81 | 90 |
| 82 // Should only be called by sync code when IsLocal() is false. | 91 // Should only be called by sync code when IsLocal() is false. |
| 83 int64 GetRemoteId() const; | 92 int64 GetRemoteId() const; |
| 84 | 93 |
| 85 // Whether this sync data is for local data or data coming from the syncer. | 94 // Whether this sync data is for local data or data coming from the syncer. |
| 95 // TODO(zea): remove this. | |
| 86 bool IsLocal() const; | 96 bool IsLocal() const; |
| 87 | 97 |
| 88 std::string ToString() const; | 98 std::string ToString() const; |
| 89 | 99 |
| 90 // TODO(zea): Query methods for other sync properties: parent, successor, etc. | 100 // TODO(zea): Query methods for other sync properties: parent, successor, etc. |
| 91 | 101 |
| 92 private: | 102 private: |
| 93 // Necessary since we forward-declare sync_pb::SyncEntity; see | 103 // Necessary since we forward-declare SyncDataCore; see |
| 94 // comments in immutable.h. | 104 // comments in immutable.h. |
| 95 struct ImmutableSyncEntityTraits { | 105 struct ImmutableSyncDataCoreTraits { |
| 96 typedef sync_pb::SyncEntity* Wrapper; | 106 typedef SyncDataCore* Wrapper; |
| 97 | 107 |
| 98 static void InitializeWrapper(Wrapper* wrapper); | 108 static void InitializeWrapper(Wrapper* wrapper); |
| 99 | 109 |
| 100 static void DestroyWrapper(Wrapper* wrapper); | 110 static void DestroyWrapper(Wrapper* wrapper); |
| 101 | 111 |
| 102 static const sync_pb::SyncEntity& Unwrap(const Wrapper& wrapper); | 112 static const SyncDataCore& Unwrap(const Wrapper& wrapper); |
| 103 | 113 |
| 104 static sync_pb::SyncEntity* UnwrapMutable(Wrapper* wrapper); | 114 static SyncDataCore* UnwrapMutable(Wrapper* wrapper); |
| 105 | 115 |
| 106 static void Swap(sync_pb::SyncEntity* t1, sync_pb::SyncEntity* t2); | 116 static void Swap(SyncDataCore* t1, SyncDataCore* t2); |
| 107 }; | 117 }; |
| 108 | 118 |
| 109 typedef Immutable<sync_pb::SyncEntity, ImmutableSyncEntityTraits> | 119 typedef Immutable<SyncDataCore, ImmutableSyncDataCoreTraits> |
| 110 ImmutableSyncEntity; | 120 ImmutableSyncDataCore; |
| 111 | 121 |
| 112 // Clears |entity|. | 122 // Clears |data|. |
| 113 SyncData(int64 id, | 123 SyncData(SyncDataCore* data); |
| 114 sync_pb::SyncEntity* entity, | |
| 115 const base::Time& remote_modification_time); | |
| 116 | 124 |
| 117 // Whether this SyncData holds valid data. | 125 // Whether this SyncData holds valid data. |
| 118 bool is_valid_; | 126 bool is_valid_; |
| 119 | 127 |
| 120 // Equal to kInvalidId iff this is local. | 128 // The actual sync data being held. |
| 121 int64 id_; | 129 ImmutableSyncDataCore immutable_data_; |
| 122 | |
| 123 // This is only valid if IsLocal() is false, and may be null if the | |
| 124 // SyncData represents a deleted item. | |
| 125 base::Time remote_modification_time_; | |
| 126 | |
| 127 // The actual shared sync entity being held. | |
| 128 ImmutableSyncEntity immutable_entity_; | |
| 129 }; | 130 }; |
| 130 | 131 |
| 131 // gmock printer helper. | 132 // gmock printer helper. |
| 132 void PrintTo(const SyncData& sync_data, std::ostream* os); | 133 void PrintTo(const SyncData& sync_data, std::ostream* os); |
| 133 | 134 |
| 134 typedef std::vector<SyncData> SyncDataList; | 135 typedef std::vector<SyncData> SyncDataList; |
| 135 | 136 |
| 136 } // namespace syncer | 137 } // namespace syncer |
| 137 | 138 |
| 138 #endif // SYNC_API_SYNC_DATA_H_ | 139 #endif // SYNC_API_SYNC_DATA_H_ |
| OLD | NEW |