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

Side by Side Diff: components/sync/test/fake_server/unique_client_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/unique_client_entity.h"
6
7 #include "base/guid.h"
8 #include "components/sync/base/hash_util.h"
9 #include "components/sync/protocol/sync.pb.h"
10 #include "components/sync/test/fake_server/permanent_entity.h"
11
12 using std::string;
13 using syncer::GenerateSyncableHash;
14 using syncer::GetModelTypeFromSpecifics;
15 using syncer::ModelType;
16
17 namespace fake_server {
18
19 namespace {
20
21 // A version must be passed when creating a FakeServerEntity, but this value
22 // is overrideen immediately when saving the entity in FakeServer.
23 const int64_t kUnusedVersion = 0L;
24
25 // Default time (creation and last modified) used when creating entities.
26 const int64_t kDefaultTime = 1234L;
27
28 } // namespace
29
30 UniqueClientEntity::UniqueClientEntity(
31 const string& id,
32 const string& client_defined_unique_tag,
33 ModelType model_type,
34 int64_t version,
35 const string& name,
36 const sync_pb::EntitySpecifics& specifics,
37 int64_t creation_time,
38 int64_t last_modified_time)
39 : FakeServerEntity(id,
40 client_defined_unique_tag,
41 model_type,
42 version,
43 name),
44 creation_time_(creation_time),
45 last_modified_time_(last_modified_time) {
46 SetSpecifics(specifics);
47 }
48
49 UniqueClientEntity::~UniqueClientEntity() {}
50
51 // static
52 std::unique_ptr<FakeServerEntity> UniqueClientEntity::Create(
53 const sync_pb::SyncEntity& client_entity) {
54 CHECK(client_entity.has_client_defined_unique_tag())
55 << "A UniqueClientEntity must have a client-defined unique tag.";
56 ModelType model_type =
57 syncer::GetModelTypeFromSpecifics(client_entity.specifics());
58 string id = EffectiveIdForClientTaggedEntity(client_entity);
59 return std::unique_ptr<FakeServerEntity>(new UniqueClientEntity(
60 id, client_entity.client_defined_unique_tag(), model_type,
61 client_entity.version(), client_entity.name(), client_entity.specifics(),
62 client_entity.ctime(), client_entity.mtime()));
63 }
64
65 // static
66 std::unique_ptr<FakeServerEntity> UniqueClientEntity::CreateForInjection(
67 const string& name,
68 const sync_pb::EntitySpecifics& entity_specifics) {
69 ModelType model_type = GetModelTypeFromSpecifics(entity_specifics);
70 string client_defined_unique_tag = GenerateSyncableHash(model_type, name);
71 string id = FakeServerEntity::CreateId(model_type, client_defined_unique_tag);
72 return std::unique_ptr<FakeServerEntity>(new UniqueClientEntity(
73 id, client_defined_unique_tag, model_type, kUnusedVersion, name,
74 entity_specifics, kDefaultTime, kDefaultTime));
75 }
76
77 // static
78 std::string UniqueClientEntity::EffectiveIdForClientTaggedEntity(
79 const sync_pb::SyncEntity& entity) {
80 return FakeServerEntity::CreateId(
81 syncer::GetModelTypeFromSpecifics(entity.specifics()),
82 entity.client_defined_unique_tag());
83 }
84
85 bool UniqueClientEntity::RequiresParentId() const {
86 return false;
87 }
88
89 string UniqueClientEntity::GetParentId() const {
90 // The parent ID for this type of entity should always be its ModelType's
91 // root node.
92 return FakeServerEntity::GetTopLevelId(model_type());
93 }
94
95 void UniqueClientEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const {
96 FakeServerEntity::SerializeBaseProtoFields(proto);
97
98 proto->set_ctime(creation_time_);
99 proto->set_mtime(last_modified_time_);
100 }
101
102 } // namespace fake_server
OLDNEW
« no previous file with comments | « components/sync/test/fake_server/unique_client_entity.h ('k') | ios/chrome/test/app/sync_test_util.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698