Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / sync / test / fake_server / unique_client_entity.cc
blob11b37d585b657f46bd41e5ad3934e9bae19eae29
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"
14 #include "sync/test/fake_server/permanent_entity.h"
16 using std::string;
18 using syncer::ModelType;
20 namespace fake_server {
22 UniqueClientEntity::~UniqueClientEntity() { }
24 // static
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,
33 model_type,
34 client_entity.version(),
35 client_entity.name(),
36 client_entity.client_defined_unique_tag(),
37 client_entity.specifics(),
38 client_entity.ctime(),
39 client_entity.mtime());
42 // static
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(
51 const string& id,
52 const ModelType& model_type,
53 int64 version,
54 const string& name,
55 const string& client_defined_unique_tag,
56 const sync_pb::EntitySpecifics& specifics,
57 int64 creation_time,
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
67 // root node.
68 return FakeServerEntity::GetTopLevelId(model_type_);
71 sync_pb::SyncEntity* UniqueClientEntity::SerializeAsProto() {
72 sync_pb::SyncEntity* sync_entity = new sync_pb::SyncEntity();
73 FakeServerEntity::SerializeBaseProtoFields(sync_entity);
75 sync_pb::EntitySpecifics* specifics = sync_entity->mutable_specifics();
76 specifics->CopyFrom(specifics_);
78 sync_entity->set_parent_id_string(GetParentId());
79 sync_entity->set_client_defined_unique_tag(client_defined_unique_tag_);
80 sync_entity->set_ctime(creation_time_);
81 sync_entity->set_mtime(last_modified_time_);
83 return sync_entity;
86 bool UniqueClientEntity::IsDeleted() const {
87 return false;
90 bool UniqueClientEntity::IsFolder() const {
91 return false;
94 } // namespace fake_server