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