Convert most two client sync_integration_tests to use FakeServer
[chromium-blink-merge.git] / sync / test / fake_server / unique_client_entity.cc
blob693b24a2c89b143f48a6db298b350e61614c1bf2
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"
7 #include <string>
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"
15 using std::string;
17 using syncer::ModelType;
19 namespace fake_server {
21 UniqueClientEntity::~UniqueClientEntity() { }
23 // static
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,
35 model_type,
36 client_entity.version(),
37 client_entity.name(),
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());
45 // static
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(),
52 client_entity.name(),
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(
61 const string& id,
62 const ModelType& model_type,
63 int64 version,
64 const string& name,
65 const string& parent_id,
66 const string& client_defined_unique_tag,
67 const sync_pb::EntitySpecifics& specifics,
68 int64 creation_time,
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
79 // root node.
80 return parent_id_;
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_);
95 return sync_entity;
98 bool UniqueClientEntity::IsDeleted() const {
99 return false;
102 bool UniqueClientEntity::IsFolder() const {
103 return false;
106 } // namespace fake_server