Index: chrome/browser/sync/api/sync_data.cc |
diff --git a/chrome/browser/sync/api/sync_data.cc b/chrome/browser/sync/api/sync_data.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..88a590b01a9c3472eacddf97d61d26fcbbcfcce9 |
--- /dev/null |
+++ b/chrome/browser/sync/api/sync_data.cc |
@@ -0,0 +1,86 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/sync/api/sync_data.h" |
+ |
+RefCountedSyncEntity::RefCountedSyncEntity(sync_pb::SyncEntity* sync_entity) { |
+ sync_entity_.reset(sync_entity); |
akalin
2011/05/19 00:58:45
Is there a swap method we could use instead?
Nicolas Zea
2011/05/19 21:17:45
Done.
akalin
2011/05/20 00:19:39
I meant a swap for the protocol buffer itself. So
|
+} |
+ |
+const sync_pb::SyncEntity& RefCountedSyncEntity::sync_entity() { |
+ return *sync_entity_; |
+} |
+ |
+RefCountedSyncEntity::~RefCountedSyncEntity() {} |
+ |
+ |
+SyncData::SyncData() |
+ : is_local_(true) { |
+} |
+ |
+SyncData::~SyncData() { |
+} |
+ |
+// Static. |
+SyncData SyncData::CreateLocalData(const std::string& sync_tag) { |
+ scoped_ptr<sync_pb::SyncEntity> entity(new sync_pb::SyncEntity); |
+ entity->set_client_defined_unique_tag(sync_tag); |
+ SyncData a; |
+ a.shared_entity_ = new RefCountedSyncEntity(entity.release()); |
+ a.is_local_ = true; |
+ return a; |
+} |
+ |
+// Static. |
+SyncData SyncData::CreateLocalData( |
+ const std::string& sync_tag, |
+ const sync_pb::EntitySpecifics& specifics) { |
+ scoped_ptr<sync_pb::SyncEntity> entity(new sync_pb::SyncEntity); |
+ entity->set_client_defined_unique_tag(sync_tag); |
+ entity->mutable_specifics()->CopyFrom(specifics); |
+ SyncData a; |
+ a.shared_entity_ = new RefCountedSyncEntity(entity.release()); |
+ a.is_local_ = true; |
+ return a; |
+} |
+ |
+// Static. |
+SyncData SyncData::CreateRemoteData(const sync_pb::SyncEntity& entity) { |
+ // TODO(zea): eventually use this for building events from the original sync |
+ // entities if possible. |
+ NOTIMPLEMENTED(); |
+ return SyncData(); |
+} |
+ |
+// Static. |
+SyncData SyncData::CreateRemoteData( |
+ const sync_pb::EntitySpecifics& specifics) { |
+ scoped_ptr<sync_pb::SyncEntity> entity(new sync_pb::SyncEntity); |
+ entity->mutable_specifics()->CopyFrom(specifics); |
+ SyncData a; |
+ a.shared_entity_ = new RefCountedSyncEntity(entity.release()); |
+ a.is_local_ = false; |
+ return a; |
+} |
+ |
+bool SyncData::IsValid() const { |
+ return (shared_entity_.get() != NULL); |
+} |
+ |
+const sync_pb::EntitySpecifics& SyncData::GetSpecifics() const { |
+ return shared_entity_->sync_entity().specifics(); |
+} |
+ |
+syncable::ModelType SyncData::GetDataType() const { |
+ return syncable::GetModelTypeFromSpecifics(GetSpecifics()); |
+} |
+ |
+const std::string& SyncData::GetTag() const { |
+ DCHECK(is_local_); |
+ return shared_entity_->sync_entity().client_defined_unique_tag(); |
+} |
+ |
+bool SyncData::IsLocal() const { |
+ return is_local_; |
+} |