Chromium Code Reviews| 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..3e95c3695a9e06776f4e90e55d7c36aacd3ecc4c |
| --- /dev/null |
| +++ b/chrome/browser/sync/api/sync_data.cc |
| @@ -0,0 +1,89 @@ |
| +// 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" |
| + |
| +#include "chrome/browser/sync/protocol/sync.pb.h" |
| + |
| +SyncData::SharedSyncEntity::SharedSyncEntity( |
| + scoped_ptr<sync_pb::SyncEntity>* sync_entity) { |
|
akalin
2011/05/21 00:57:58
Change to:
SyncData::SharedSyncEntity::SharedSync
Nicolas Zea
2011/05/23 18:13:27
Done.
|
| + sync_entity_.swap(*sync_entity); |
| +} |
| + |
| +const sync_pb::SyncEntity& SyncData::SharedSyncEntity::sync_entity() const { |
| + return *sync_entity_; |
| +} |
| + |
| +SyncData::SharedSyncEntity::~SharedSyncEntity() {} |
| + |
| + |
| +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 SharedSyncEntity(&entity); |
| + a.is_local_ = true; |
| + return a; |
| +} |
| + |
| +// Static. |
| +SyncData SyncData::CreateLocalData( |
| + const std::string& sync_tag, |
| + const sync_pb::EntitySpecifics& specifics) { |
|
akalin
2011/05/21 00:57:58
Change to:
SyncData SyncData::CreateLocalData(
Nicolas Zea
2011/05/23 18:13:27
Done.
|
| + 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 SharedSyncEntity(&entity); |
| + a.is_local_ = true; |
| + return a; |
| +} |
| + |
| +// Static. |
| +SyncData SyncData::CreateRemoteData(const sync_pb::SyncEntity& entity) { |
| + // TODO(zea): eventually use this for building changes from the original sync |
| + // entities if possible. |
| + NOTIMPLEMENTED(); |
| + return SyncData(); |
| +} |
| + |
| +// Static. |
| +SyncData SyncData::CreateRemoteData( |
| + const sync_pb::EntitySpecifics& specifics) { |
|
akalin
2011/05/21 00:57:58
change similar to CreateLocalData
Nicolas Zea
2011/05/23 18:13:27
Done.
|
| + scoped_ptr<sync_pb::SyncEntity> entity(new sync_pb::SyncEntity); |
| + entity->mutable_specifics()->CopyFrom(specifics); |
| + SyncData a; |
| + a.shared_entity_ = new SharedSyncEntity(&entity); |
| + 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_; |
| +} |