1 // Copyright 2014 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.
5 #include "sync/test/fake_server/unique_client_entity.h"
9 #include "base/basictypes.h"
10 #include "base/guid.h"
11 #include "sync/internal_api/public/base/model_type.h"
12 #include "sync/protocol/sync.pb.h"
13 #include "sync/test/fake_server/fake_server_entity.h"
14 #include "sync/test/fake_server/permanent_entity.h"
18 using syncer::ModelType
;
20 namespace fake_server
{
22 UniqueClientEntity::~UniqueClientEntity() { }
25 FakeServerEntity
* UniqueClientEntity::Create(
26 const sync_pb::SyncEntity
& client_entity
) {
27 CHECK(client_entity
.has_client_defined_unique_tag())
28 << "A UniqueClientEntity must have a client-defined unique tag.";
29 ModelType model_type
=
30 syncer::GetModelTypeFromSpecifics(client_entity
.specifics());
31 string id
= EffectiveIdForClientTaggedEntity(client_entity
);
32 return new UniqueClientEntity(id
,
34 client_entity
.version(),
36 client_entity
.client_defined_unique_tag(),
37 client_entity
.specifics(),
38 client_entity
.ctime(),
39 client_entity
.mtime());
43 std::string
UniqueClientEntity::EffectiveIdForClientTaggedEntity(
44 const sync_pb::SyncEntity
& entity
) {
45 return FakeServerEntity::CreateId(
46 syncer::GetModelTypeFromSpecifics(entity
.specifics()),
47 entity
.client_defined_unique_tag());
50 UniqueClientEntity::UniqueClientEntity(
52 const ModelType
& model_type
,
55 const string
& client_defined_unique_tag
,
56 const sync_pb::EntitySpecifics
& specifics
,
58 int64 last_modified_time
)
59 : FakeServerEntity(id
, model_type
, version
, name
),
60 client_defined_unique_tag_(client_defined_unique_tag
),
61 specifics_(specifics
),
62 creation_time_(creation_time
),
63 last_modified_time_(last_modified_time
) { }
65 string
UniqueClientEntity::GetParentId() const {
66 // The parent ID for this type of entity should always be its ModelType's
68 return FakeServerEntity::GetTopLevelId(model_type_
);
71 void UniqueClientEntity::SerializeAsProto(sync_pb::SyncEntity
* proto
) {
72 FakeServerEntity::SerializeBaseProtoFields(proto
);
74 sync_pb::EntitySpecifics
* specifics
= proto
->mutable_specifics();
75 specifics
->CopyFrom(specifics_
);
77 proto
->set_parent_id_string(GetParentId());
78 proto
->set_client_defined_unique_tag(client_defined_unique_tag_
);
79 proto
->set_ctime(creation_time_
);
80 proto
->set_mtime(last_modified_time_
);
83 bool UniqueClientEntity::IsDeleted() const {
87 bool UniqueClientEntity::IsFolder() const {
91 } // namespace fake_server