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"
17 using syncer::ModelType
;
19 namespace fake_server
{
21 UniqueClientEntity::~UniqueClientEntity() { }
24 FakeServerEntity
* UniqueClientEntity::CreateNew(
25 const sync_pb::SyncEntity
& client_entity
) {
26 DCHECK(client_entity
.has_client_defined_unique_tag());
27 DCHECK(!client_entity
.folder());
28 DCHECK(!client_entity
.deleted());
29 ModelType model_type
=
30 syncer::GetModelTypeFromSpecifics(client_entity
.specifics());
31 string id
= client_entity
.version() == 0 ?
32 FakeServerEntity::CreateId(model_type
, base::GenerateGUID()) :
33 client_entity
.id_string();
34 return new UniqueClientEntity(id
,
36 client_entity
.version(),
38 client_entity
.parent_id_string(),
39 client_entity
.client_defined_unique_tag(),
40 client_entity
.specifics(),
41 client_entity
.ctime(),
42 client_entity
.mtime());
46 FakeServerEntity
* UniqueClientEntity::CreateUpdatedVersion(
47 const sync_pb::SyncEntity
& client_entity
,
48 FakeServerEntity
* current_server_entity
) {
49 return new UniqueClientEntity(client_entity
.id_string(),
50 current_server_entity
->GetModelType(),
51 client_entity
.version(),
53 client_entity
.parent_id_string(),
54 client_entity
.client_defined_unique_tag(),
55 client_entity
.specifics(),
56 client_entity
.ctime(),
57 client_entity
.mtime());
60 UniqueClientEntity::UniqueClientEntity(
62 const ModelType
& model_type
,
65 const string
& parent_id
,
66 const string
& client_defined_unique_tag
,
67 const sync_pb::EntitySpecifics
& specifics
,
69 int64 last_modified_time
)
70 : FakeServerEntity(id
, model_type
, version
, name
),
71 parent_id_(parent_id
),
72 client_defined_unique_tag_(client_defined_unique_tag
),
73 specifics_(specifics
),
74 creation_time_(creation_time
),
75 last_modified_time_(last_modified_time
) { }
77 string
UniqueClientEntity::GetParentId() const {
78 // The parent ID for this type of entity should always be its ModelType's
83 sync_pb::SyncEntity
* UniqueClientEntity::SerializeAsProto() {
84 sync_pb::SyncEntity
* sync_entity
= new sync_pb::SyncEntity();
85 FakeServerEntity::SerializeBaseProtoFields(sync_entity
);
87 sync_pb::EntitySpecifics
* specifics
= sync_entity
->mutable_specifics();
88 specifics
->CopyFrom(specifics_
);
90 sync_entity
->set_parent_id_string(parent_id_
);
91 sync_entity
->set_client_defined_unique_tag(client_defined_unique_tag_
);
92 sync_entity
->set_ctime(creation_time_
);
93 sync_entity
->set_mtime(last_modified_time_
);
98 bool UniqueClientEntity::IsDeleted() const {
102 bool UniqueClientEntity::IsFolder() const {
106 } // namespace fake_server