OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/sync/api/sync_data.h" |
| 6 |
| 7 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 8 |
| 9 SyncData::SharedSyncEntity::SharedSyncEntity( |
| 10 sync_pb::SyncEntity* sync_entity) |
| 11 : sync_entity_(new sync_pb::SyncEntity()){ |
| 12 sync_entity_->Swap(sync_entity); |
| 13 } |
| 14 |
| 15 const sync_pb::SyncEntity& SyncData::SharedSyncEntity::sync_entity() const { |
| 16 return *sync_entity_; |
| 17 } |
| 18 |
| 19 SyncData::SharedSyncEntity::~SharedSyncEntity() {} |
| 20 |
| 21 |
| 22 SyncData::SyncData() |
| 23 : is_local_(true) { |
| 24 } |
| 25 |
| 26 SyncData::~SyncData() { |
| 27 } |
| 28 |
| 29 // Static. |
| 30 SyncData SyncData::CreateLocalData(const std::string& sync_tag) { |
| 31 sync_pb::SyncEntity entity; |
| 32 entity.set_client_defined_unique_tag(sync_tag); |
| 33 SyncData a; |
| 34 a.shared_entity_ = new SharedSyncEntity(&entity); |
| 35 a.is_local_ = true; |
| 36 return a; |
| 37 } |
| 38 |
| 39 // Static. |
| 40 SyncData SyncData::CreateLocalData( |
| 41 const std::string& sync_tag, |
| 42 const sync_pb::EntitySpecifics& specifics) { |
| 43 sync_pb::SyncEntity entity; |
| 44 entity.set_client_defined_unique_tag(sync_tag); |
| 45 entity.mutable_specifics()->CopyFrom(specifics); |
| 46 SyncData a; |
| 47 a.shared_entity_ = new SharedSyncEntity(&entity); |
| 48 a.is_local_ = true; |
| 49 return a; |
| 50 } |
| 51 |
| 52 // Static. |
| 53 SyncData SyncData::CreateRemoteData(const sync_pb::SyncEntity& entity) { |
| 54 // TODO(zea): eventually use this for building changes from the original sync |
| 55 // entities if possible. |
| 56 NOTIMPLEMENTED(); |
| 57 return SyncData(); |
| 58 } |
| 59 |
| 60 // Static. |
| 61 SyncData SyncData::CreateRemoteData( |
| 62 const sync_pb::EntitySpecifics& specifics) { |
| 63 sync_pb::SyncEntity entity; |
| 64 entity.mutable_specifics()->CopyFrom(specifics); |
| 65 SyncData a; |
| 66 a.shared_entity_ = new SharedSyncEntity(&entity); |
| 67 a.is_local_ = false; |
| 68 return a; |
| 69 } |
| 70 |
| 71 bool SyncData::IsValid() const { |
| 72 return (shared_entity_.get() != NULL); |
| 73 } |
| 74 |
| 75 const sync_pb::EntitySpecifics& SyncData::GetSpecifics() const { |
| 76 return shared_entity_->sync_entity().specifics(); |
| 77 } |
| 78 |
| 79 syncable::ModelType SyncData::GetDataType() const { |
| 80 return syncable::GetModelTypeFromSpecifics(GetSpecifics()); |
| 81 } |
| 82 |
| 83 const std::string& SyncData::GetTag() const { |
| 84 DCHECK(is_local_); |
| 85 return shared_entity_->sync_entity().client_defined_unique_tag(); |
| 86 } |
| 87 |
| 88 bool SyncData::IsLocal() const { |
| 89 return is_local_; |
| 90 } |
OLD | NEW |