Index: sync/api/sync_data.cc |
diff --git a/sync/api/sync_data.cc b/sync/api/sync_data.cc |
index d52e04ec21300951be156dcd2ae4ec0a29fdf7f2..e7478f56b249d436597a8874329c8306d957c596 100644 |
--- a/sync/api/sync_data.cc |
+++ b/sync/api/sync_data.cc |
@@ -17,42 +17,83 @@ |
namespace syncer { |
-void SyncData::ImmutableSyncEntityTraits::InitializeWrapper( |
+struct SyncDataCore { |
+ SyncDataCore(); |
+ SyncDataCore(ModelType datatype, |
+ int64 id, |
+ base::Time remote_modification_time, |
+ const std::string& context, |
+ const sync_pb::SyncEntity& entity); |
+ ~SyncDataCore(); |
+ |
+ // The datatype associated with this sync data. |
+ ModelType datatype; |
+ |
+ // Equal to kInvalidId iff this is local. |
+ int64 id; |
+ |
+ // This is only valid if IsLocal() is false, and may be null if the |
+ // SyncData represents a deleted item. |
+ base::Time remote_modification_time; |
+ |
+ // The sync context for this datatype. Only valid for non-entity based data. |
+ std::string context; |
+ |
+ // The sync entity associated with this data. Only valid for non-context |
+ // data. |
+ sync_pb::SyncEntity entity; |
+}; |
+ |
+SyncDataCore::SyncDataCore() |
+ : datatype(UNSPECIFIED), |
+ id(kInvalidId) {} |
+ |
+SyncDataCore::SyncDataCore(ModelType datatype, |
+ int64 id, |
+ base::Time remote_modification_time, |
+ const std::string& context, |
+ const sync_pb::SyncEntity& entity) |
+ : datatype(datatype), |
+ id(id), |
+ remote_modification_time(remote_modification_time), |
+ context(context), |
+ entity(entity) { |
+} |
+ |
+SyncDataCore::~SyncDataCore() {} |
+ |
+void SyncData::ImmutableSyncDataCoreTraits::InitializeWrapper( |
Wrapper* wrapper) { |
- *wrapper = new sync_pb::SyncEntity(); |
+ *wrapper = new SyncDataCore(); |
} |
-void SyncData::ImmutableSyncEntityTraits::DestroyWrapper( |
+void SyncData::ImmutableSyncDataCoreTraits::DestroyWrapper( |
Wrapper* wrapper) { |
delete *wrapper; |
} |
-const sync_pb::SyncEntity& SyncData::ImmutableSyncEntityTraits::Unwrap( |
+const SyncDataCore& SyncData::ImmutableSyncDataCoreTraits::Unwrap( |
const Wrapper& wrapper) { |
return *wrapper; |
} |
-sync_pb::SyncEntity* SyncData::ImmutableSyncEntityTraits::UnwrapMutable( |
+SyncDataCore* SyncData::ImmutableSyncDataCoreTraits::UnwrapMutable( |
Wrapper* wrapper) { |
return *wrapper; |
} |
-void SyncData::ImmutableSyncEntityTraits::Swap(sync_pb::SyncEntity* t1, |
- sync_pb::SyncEntity* t2) { |
- t1->Swap(t2); |
+void SyncData::ImmutableSyncDataCoreTraits::Swap(SyncDataCore* t1, |
+ SyncDataCore* t2) { |
+ SyncDataCore temp(*t1); |
+ *t1 = *t2; |
+ *t2 = *t1; |
} |
SyncData::SyncData() |
- : is_valid_(false), |
- id_(kInvalidId) {} |
+ : is_valid_(false) {} |
-SyncData::SyncData(int64 id, |
- sync_pb::SyncEntity* entity, |
- const base::Time& remote_modification_time) |
- : is_valid_(true), |
- id_(id), |
- remote_modification_time_(remote_modification_time), |
- immutable_entity_(entity) {} |
+SyncData::SyncData(SyncDataCore* core) |
+ : is_valid_(true), immutable_data_(core) {} |
SyncData::~SyncData() {} |
@@ -70,11 +111,15 @@ SyncData SyncData::CreateLocalData( |
const std::string& sync_tag, |
const std::string& non_unique_title, |
const sync_pb::EntitySpecifics& specifics) { |
- sync_pb::SyncEntity entity; |
- entity.set_client_defined_unique_tag(sync_tag); |
- entity.set_non_unique_name(non_unique_title); |
- entity.mutable_specifics()->CopyFrom(specifics); |
- return SyncData(kInvalidId, &entity, base::Time()); |
+ SyncDataCore core(GetModelTypeFromSpecifics(specifics), |
+ kInvalidId, |
+ base::Time(), |
+ "", |
+ sync_pb::SyncEntity()); |
+ core.entity.set_client_defined_unique_tag(sync_tag); |
+ core.entity.set_non_unique_name(non_unique_title); |
+ core.entity.mutable_specifics()->CopyFrom(specifics); |
+ return SyncData(&core); |
} |
// Static. |
@@ -82,9 +127,25 @@ SyncData SyncData::CreateRemoteData( |
int64 id, const sync_pb::EntitySpecifics& specifics, |
const base::Time& modification_time) { |
DCHECK_NE(id, kInvalidId); |
- sync_pb::SyncEntity entity; |
- entity.mutable_specifics()->CopyFrom(specifics); |
- return SyncData(id, &entity, modification_time); |
+ SyncDataCore core(GetModelTypeFromSpecifics(specifics), |
+ id, |
+ modification_time, |
+ "", |
+ sync_pb::SyncEntity()); |
+ core.entity.mutable_specifics()->CopyFrom(specifics); |
+ return SyncData(&core); |
+} |
+ |
+// Static. |
+SyncData SyncData::CreateContext( |
+ ModelType datatype, |
+ const std::string& context) { |
+ SyncDataCore core(datatype, |
+ kInvalidId, |
+ base::Time(), |
+ context, |
+ sync_pb::SyncEntity()); |
+ return SyncData(&core); |
} |
bool SyncData::IsValid() const { |
@@ -92,7 +153,7 @@ bool SyncData::IsValid() const { |
} |
const sync_pb::EntitySpecifics& SyncData::GetSpecifics() const { |
- return immutable_entity_.Get().specifics(); |
+ return immutable_data_.Get().entity.specifics(); |
} |
ModelType SyncData::GetDataType() const { |
@@ -101,27 +162,31 @@ ModelType SyncData::GetDataType() const { |
const std::string& SyncData::GetTag() const { |
DCHECK(IsLocal()); |
- return immutable_entity_.Get().client_defined_unique_tag(); |
+ return immutable_data_.Get().entity.client_defined_unique_tag(); |
} |
const std::string& SyncData::GetTitle() const { |
// TODO(zea): set this for data coming from the syncer too. |
- DCHECK(immutable_entity_.Get().has_non_unique_name()); |
- return immutable_entity_.Get().non_unique_name(); |
+ DCHECK(immutable_data_.Get().entity.has_non_unique_name()); |
+ return immutable_data_.Get().entity.non_unique_name(); |
+} |
+ |
+const std::string& SyncData::GetContext() const { |
+ return immutable_data_.Get().context; |
} |
const base::Time& SyncData::GetRemoteModifiedTime() const { |
DCHECK(!IsLocal()); |
- return remote_modification_time_; |
+ return immutable_data_.Get().remote_modification_time; |
} |
int64 SyncData::GetRemoteId() const { |
DCHECK(!IsLocal()); |
- return id_; |
+ return immutable_data_.Get().id; |
} |
bool SyncData::IsLocal() const { |
- return id_ == kInvalidId; |
+ return immutable_data_.Get().id == kInvalidId; |
} |
std::string SyncData::ToString() const { |
@@ -138,12 +203,13 @@ std::string SyncData::ToString() const { |
if (IsLocal()) { |
return "{ isLocal: true, type: " + type + ", tag: " + GetTag() + |
- ", title: " + GetTitle() + ", specifics: " + specifics + "}"; |
+ ", title: " + GetTitle() + ", context: " + GetContext() + |
+ "specifics: " + specifics + "}"; |
maniscalco
2014/03/31 23:59:16
Need a comma and space before specifics?
Nicolas Zea
2014/04/02 18:34:36
Done.
|
} |
std::string id = base::Int64ToString(GetRemoteId()); |
- return "{ isLocal: false, type: " + type + ", specifics: " + specifics + |
- ", id: " + id + "}"; |
+ return "{ isLocal: false, type: " + type + ", context: " + GetContext() + |
+ ", specifics: " + specifics + ", id: " + id + "}"; |
} |
void PrintTo(const SyncData& sync_data, std::ostream* os) { |