Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Unified Diff: sync/api/sync_data.cc

Issue 217063005: Separate SyncData methods into three groups, local, remote, and common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@syncapi
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sync/api/sync_data.cc
diff --git a/sync/api/sync_data.cc b/sync/api/sync_data.cc
index 0324fc1a228f3f4e7cd7a1c850440c36557d3796..4a2e3719818e33fc3a9c998f08e4a0174daaae38 100644
--- a/sync/api/sync_data.cc
+++ b/sync/api/sync_data.cc
@@ -63,20 +63,28 @@ void SyncData::ImmutableSyncEntityTraits::Swap(sync_pb::SyncEntity* t1,
t1->Swap(t2);
}
-SyncData::SyncData() : is_valid_(false), id_(kInvalidId) {}
-
-SyncData::SyncData(
- int64 id,
- sync_pb::SyncEntity* entity,
- AttachmentList* attachments,
- const base::Time& remote_modification_time,
- const syncer::AttachmentServiceProxy& attachment_service)
- : is_valid_(true),
+SyncData::SyncData()
+ : local_(NULL), remote_(NULL), is_valid_(false), id_(kInvalidId) {}
+
+SyncData::SyncData(int64 id,
+ sync_pb::SyncEntity* entity,
+ AttachmentList* attachments,
+ const base::Time& remote_modification_time,
+ const syncer::AttachmentServiceProxy& attachment_service)
+ : local_(this),
+ remote_(this),
+ is_valid_(true),
id_(id),
remote_modification_time_(remote_modification_time),
immutable_entity_(entity),
attachments_(attachments),
- attachment_service_(attachment_service) {}
+ attachment_service_(attachment_service) {
+ if (IsLocal()) {
+ remote_ = Remote(NULL);
+ } else {
+ local_ = Local(NULL);
+ }
+}
SyncData::~SyncData() {}
@@ -165,27 +173,12 @@ ModelType SyncData::GetDataType() const {
return GetModelTypeFromSpecifics(GetSpecifics());
}
-const std::string& SyncData::GetTag() const {
- DCHECK(IsLocal());
- return immutable_entity_.Get().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();
}
-const base::Time& SyncData::GetRemoteModifiedTime() const {
- DCHECK(!IsLocal());
- return remote_modification_time_;
-}
-
-int64 SyncData::GetRemoteId() const {
- DCHECK(!IsLocal());
- return id_;
-}
-
bool SyncData::IsLocal() const { return id_ == kInvalidId; }
std::string SyncData::ToString() const {
@@ -200,11 +193,11 @@ std::string SyncData::ToString() const {
value.get(), base::JSONWriter::OPTIONS_PRETTY_PRINT, &specifics);
if (IsLocal()) {
- return "{ isLocal: true, type: " + type + ", tag: " + GetTag() +
+ return "{ isLocal: true, type: " + type + ", tag: " + local().GetTag() +
", title: " + GetTitle() + ", specifics: " + specifics + "}";
}
- std::string id = base::Int64ToString(GetRemoteId());
+ std::string id = base::Int64ToString(remote().GetRemoteId());
return "{ isLocal: false, type: " + type + ", specifics: " + specifics +
", id: " + id + "}";
}
@@ -223,23 +216,48 @@ AttachmentIdList SyncData::GetAttachmentIds() const {
return result;
}
-const AttachmentList& SyncData::GetLocalAttachmentsForUpload() const {
+const AttachmentList& SyncData::Local::GetLocalAttachmentsForUpload() const {
+ return sync_data_->attachments_.Get();
+}
+
+const std::string& SyncData::Local::GetTag() const {
+ return sync_data_->immutable_entity_.Get().client_defined_unique_tag();
+}
+
+const SyncData::Local& SyncData::local() const {
DCHECK(IsLocal());
- return attachments_.Get();
+ return local_;
+}
+
+const base::Time& SyncData::Remote::GetRemoteModifiedTime() const {
+ return sync_data_->remote_modification_time_;
+}
+
+int64 SyncData::Remote::GetRemoteId() const {
+ return sync_data_->id_;
}
-void SyncData::GetOrDownloadAttachments(
+void SyncData::Remote::GetOrDownloadAttachments(
const AttachmentIdList& attachment_ids,
const AttachmentService::GetOrDownloadCallback& callback) {
- DCHECK(!IsLocal());
- attachment_service_.GetOrDownloadAttachments(attachment_ids, callback);
+ sync_data_->attachment_service_.GetOrDownloadAttachments(attachment_ids,
+ callback);
}
-void SyncData::DropAttachments(
+void SyncData::Remote::DropAttachments(
const AttachmentIdList& attachment_ids,
const AttachmentService::DropCallback& callback) {
+ sync_data_->attachment_service_.DropAttachments(attachment_ids, callback);
+}
+
+SyncData::Remote& SyncData::remote() {
+ DCHECK(!IsLocal());
+ return remote_;
+}
+
+const SyncData::Remote& SyncData::remote() const {
DCHECK(!IsLocal());
- attachment_service_.DropAttachments(attachment_ids, callback);
+ return remote_;
}
} // namespace syncer
« sync/api/sync_data.h ('K') | « sync/api/sync_data.h ('k') | sync/api/sync_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698