Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: components/sync/test/fake_server/permanent_entity.cc

Issue 2887343002: wip 3 (Closed)
Patch Set: cleanup Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "components/sync/test/fake_server/permanent_entity.h"
6
7 #include "base/logging.h"
8 #include "base/memory/ptr_util.h"
9
10 using std::string;
11 using syncer::ModelType;
12
13 // The parent tag for children of the root entity. Entities with this parent are
14 // referred to as top level enities.
15 static const char kRootParentTag[] = "0";
16
17 namespace fake_server {
18
19 PermanentEntity::~PermanentEntity() {}
20
21 // static
22 std::unique_ptr<FakeServerEntity> PermanentEntity::Create(
23 const ModelType& model_type,
24 const string& server_tag,
25 const string& name,
26 const string& parent_server_tag) {
27 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is "
28 << "invalid.";
29 CHECK(!server_tag.empty()) << "A PermanentEntity must have a server tag.";
30 CHECK(!name.empty()) << "The entity must have a non-empty name.";
31 CHECK(!parent_server_tag.empty()) << "A PermanentEntity must have a parent "
32 << "server tag.";
33 CHECK(parent_server_tag != kRootParentTag) << "Top-level entities should not "
34 << "be created with this factory.";
35
36 string id = FakeServerEntity::CreateId(model_type, server_tag);
37 string parent_id = FakeServerEntity::CreateId(model_type, parent_server_tag);
38 sync_pb::EntitySpecifics entity_specifics;
39 AddDefaultFieldValue(model_type, &entity_specifics);
40 return std::unique_ptr<FakeServerEntity>(new PermanentEntity(
41 id, model_type, name, parent_id, server_tag, entity_specifics));
42 }
43
44 // static
45 std::unique_ptr<FakeServerEntity> PermanentEntity::CreateTopLevel(
46 const ModelType& model_type) {
47 CHECK(model_type != syncer::UNSPECIFIED) << "The entity's ModelType is "
48 << "invalid.";
49 string server_tag = syncer::ModelTypeToRootTag(model_type);
50 string name = syncer::ModelTypeToString(model_type);
51 string id = FakeServerEntity::GetTopLevelId(model_type);
52 sync_pb::EntitySpecifics entity_specifics;
53 AddDefaultFieldValue(model_type, &entity_specifics);
54 return std::unique_ptr<FakeServerEntity>(new PermanentEntity(
55 id, model_type, name, kRootParentTag, server_tag, entity_specifics));
56 }
57
58 // static
59 std::unique_ptr<FakeServerEntity> PermanentEntity::CreateUpdatedNigoriEntity(
60 const sync_pb::SyncEntity& client_entity,
61 const FakeServerEntity& current_server_entity) {
62 ModelType model_type = current_server_entity.model_type();
63 CHECK(model_type == syncer::NIGORI) << "This factory only supports NIGORI "
64 << "entities.";
65
66 return base::WrapUnique<FakeServerEntity>(new PermanentEntity(
67 current_server_entity.id(), model_type, current_server_entity.GetName(),
68 current_server_entity.GetParentId(),
69 syncer::ModelTypeToRootTag(model_type), client_entity.specifics()));
70 }
71
72 PermanentEntity::PermanentEntity(const string& id,
73 const ModelType& model_type,
74 const string& name,
75 const string& parent_id,
76 const string& server_defined_unique_tag,
77 const sync_pb::EntitySpecifics& specifics)
78 : FakeServerEntity(id, string(), model_type, 0, name),
79 server_defined_unique_tag_(server_defined_unique_tag),
80 parent_id_(parent_id) {
81 SetSpecifics(specifics);
82 }
83
84 bool PermanentEntity::RequiresParentId() const {
85 return true;
86 }
87
88 string PermanentEntity::GetParentId() const {
89 return parent_id_;
90 }
91
92 void PermanentEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const {
93 FakeServerEntity::SerializeBaseProtoFields(proto);
94 proto->set_server_defined_unique_tag(server_defined_unique_tag_);
95 }
96
97 bool PermanentEntity::IsFolder() const {
98 return true;
99 }
100
101 bool PermanentEntity::IsPermanent() const {
102 return true;
103 }
104
105 } // namespace fake_server
OLDNEW
« no previous file with comments | « components/sync/test/fake_server/permanent_entity.h ('k') | components/sync/test/fake_server/tombstone_entity.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698