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 SyncData::SharedSyncEntity::SharedSyncEntity( |
| 8 scoped_ptr<sync_pb::SyncEntity>* sync_entity) { |
| 9 sync_entity_.swap(*sync_entity); |
| 10 } |
| 11 |
| 12 const sync_pb::SyncEntity& SyncData::SharedSyncEntity::sync_entity() const { |
| 13 return *sync_entity_; |
| 14 } |
| 15 |
| 16 SyncData::SharedSyncEntity::~SharedSyncEntity() {} |
| 17 |
| 18 |
| 19 SyncData::SyncData() |
| 20 : is_local_(true) { |
| 21 } |
| 22 |
| 23 SyncData::~SyncData() { |
| 24 } |
| 25 |
| 26 // Static. |
| 27 SyncData SyncData::CreateLocalData(const std::string& sync_tag) { |
| 28 scoped_ptr<sync_pb::SyncEntity> entity(new sync_pb::SyncEntity); |
| 29 entity->set_client_defined_unique_tag(sync_tag); |
| 30 SyncData a; |
| 31 a.shared_entity_ = new SharedSyncEntity(&entity); |
| 32 a.is_local_ = true; |
| 33 return a; |
| 34 } |
| 35 |
| 36 // Static. |
| 37 SyncData SyncData::CreateLocalData( |
| 38 const std::string& sync_tag, |
| 39 const sync_pb::EntitySpecifics& specifics) { |
| 40 scoped_ptr<sync_pb::SyncEntity> entity(new sync_pb::SyncEntity); |
| 41 entity->set_client_defined_unique_tag(sync_tag); |
| 42 entity->mutable_specifics()->CopyFrom(specifics); |
| 43 SyncData a; |
| 44 a.shared_entity_ = new SharedSyncEntity(&entity); |
| 45 a.is_local_ = true; |
| 46 return a; |
| 47 } |
| 48 |
| 49 // Static. |
| 50 SyncData SyncData::CreateRemoteData(const sync_pb::SyncEntity& entity) { |
| 51 // TODO(zea): eventually use this for building changes from the original sync |
| 52 // entities if possible. |
| 53 NOTIMPLEMENTED(); |
| 54 return SyncData(); |
| 55 } |
| 56 |
| 57 // Static. |
| 58 SyncData SyncData::CreateRemoteData( |
| 59 const sync_pb::EntitySpecifics& specifics) { |
| 60 scoped_ptr<sync_pb::SyncEntity> entity(new sync_pb::SyncEntity); |
| 61 entity->mutable_specifics()->CopyFrom(specifics); |
| 62 SyncData a; |
| 63 a.shared_entity_ = new SharedSyncEntity(&entity); |
| 64 a.is_local_ = false; |
| 65 return a; |
| 66 } |
| 67 |
| 68 bool SyncData::IsValid() const { |
| 69 return (shared_entity_.get() != NULL); |
| 70 } |
| 71 |
| 72 const sync_pb::EntitySpecifics& SyncData::GetSpecifics() const { |
| 73 return shared_entity_->sync_entity().specifics(); |
| 74 } |
| 75 |
| 76 syncable::ModelType SyncData::GetDataType() const { |
| 77 return syncable::GetModelTypeFromSpecifics(GetSpecifics()); |
| 78 } |
| 79 |
| 80 const std::string& SyncData::GetTag() const { |
| 81 DCHECK(is_local_); |
| 82 return shared_entity_->sync_entity().client_defined_unique_tag(); |
| 83 } |
| 84 |
| 85 bool SyncData::IsLocal() const { |
| 86 return is_local_; |
| 87 } |
OLD | NEW |