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