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

Side by Side Diff: components/sync/engine_impl/loopback_server/persistent_unique_client_entity.cc

Issue 2938553003: Revert of [sync] Replace FakeServer's implementation with LoopbackServer invocations. (Closed)
Patch Set: 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/sync/engine_impl/loopback_server/persistent_unique_client_e ntity.h" 5 #include "components/sync/engine_impl/loopback_server/persistent_unique_client_e ntity.h"
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "components/sync/base/hash_util.h"
9 #include "components/sync/engine_impl/loopback_server/persistent_permanent_entit y.h" 8 #include "components/sync/engine_impl/loopback_server/persistent_permanent_entit y.h"
10 #include "components/sync/protocol/sync.pb.h" 9 #include "components/sync/protocol/sync.pb.h"
11 10
12 using std::string; 11 using std::string;
13 12
14 namespace syncer { 13 namespace syncer {
15 14
16 PersistentUniqueClientEntity::PersistentUniqueClientEntity( 15 PersistentUniqueClientEntity::PersistentUniqueClientEntity(
17 const string& id, 16 const string& id,
18 ModelType model_type, 17 ModelType model_type,
19 int64_t version, 18 int64_t version,
20 const string& name, 19 const string& name,
21 const string& client_defined_unique_tag, 20 const string& client_defined_unique_tag,
22 const sync_pb::EntitySpecifics& specifics, 21 const sync_pb::EntitySpecifics& specifics,
23 int64_t creation_time, 22 int64_t creation_time,
24 int64_t last_modified_time) 23 int64_t last_modified_time)
25 : LoopbackServerEntity(id, model_type, version, name), 24 : LoopbackServerEntity(id, model_type, version, name),
26 client_defined_unique_tag_(client_defined_unique_tag), 25 client_defined_unique_tag_(client_defined_unique_tag),
27 creation_time_(creation_time), 26 creation_time_(creation_time),
28 last_modified_time_(last_modified_time) { 27 last_modified_time_(last_modified_time) {
29 SetSpecifics(specifics); 28 SetSpecifics(specifics);
30 } 29 }
31 30
32 PersistentUniqueClientEntity::~PersistentUniqueClientEntity() {} 31 PersistentUniqueClientEntity::~PersistentUniqueClientEntity() {}
33 32
34 // static 33 // static
35 std::unique_ptr<LoopbackServerEntity> 34 std::unique_ptr<LoopbackServerEntity> PersistentUniqueClientEntity::Create(
36 PersistentUniqueClientEntity::CreateFromEntity(
37 const sync_pb::SyncEntity& client_entity) { 35 const sync_pb::SyncEntity& client_entity) {
38 CHECK(client_entity.has_client_defined_unique_tag()) 36 CHECK(client_entity.has_client_defined_unique_tag())
39 << "A PersistentUniqueClientEntity must have a client-defined unique " 37 << "A PersistentUniqueClientEntity must have a client-defined unique "
40 "tag."; 38 "tag.";
41 ModelType model_type = GetModelTypeFromSpecifics(client_entity.specifics()); 39 ModelType model_type = GetModelTypeFromSpecifics(client_entity.specifics());
42 string id = EffectiveIdForClientTaggedEntity(client_entity); 40 string id = EffectiveIdForClientTaggedEntity(client_entity);
43 return std::unique_ptr<LoopbackServerEntity>(new PersistentUniqueClientEntity( 41 return std::unique_ptr<LoopbackServerEntity>(new PersistentUniqueClientEntity(
44 id, model_type, client_entity.version(), client_entity.name(), 42 id, model_type, client_entity.version(), client_entity.name(),
45 client_entity.client_defined_unique_tag(), client_entity.specifics(), 43 client_entity.client_defined_unique_tag(), client_entity.specifics(),
46 client_entity.ctime(), client_entity.mtime())); 44 client_entity.ctime(), client_entity.mtime()));
47 } 45 }
48 46
49 // static 47 // static
50 std::unique_ptr<LoopbackServerEntity>
51 PersistentUniqueClientEntity::CreateFromEntitySpecifics(
52 const string& name,
53 const sync_pb::EntitySpecifics& entity_specifics) {
54 ModelType model_type = GetModelTypeFromSpecifics(entity_specifics);
55 string client_defined_unique_tag = GenerateSyncableHash(model_type, name);
56 string id =
57 LoopbackServerEntity::CreateId(model_type, client_defined_unique_tag);
58 return std::unique_ptr<LoopbackServerEntity>(new PersistentUniqueClientEntity(
59 id, model_type, 0, name, client_defined_unique_tag, entity_specifics,
60 1337, 1337));
61 }
62
63 // static
64 std::string PersistentUniqueClientEntity::EffectiveIdForClientTaggedEntity( 48 std::string PersistentUniqueClientEntity::EffectiveIdForClientTaggedEntity(
65 const sync_pb::SyncEntity& entity) { 49 const sync_pb::SyncEntity& entity) {
66 return LoopbackServerEntity::CreateId( 50 return LoopbackServerEntity::CreateId(
67 GetModelTypeFromSpecifics(entity.specifics()), 51 GetModelTypeFromSpecifics(entity.specifics()),
68 entity.client_defined_unique_tag()); 52 entity.client_defined_unique_tag());
69 } 53 }
70 54
71 bool PersistentUniqueClientEntity::RequiresParentId() const { 55 bool PersistentUniqueClientEntity::RequiresParentId() const {
72 return false; 56 return false;
73 } 57 }
(...skipping 12 matching lines...) Expand all
86 void PersistentUniqueClientEntity::SerializeAsProto( 70 void PersistentUniqueClientEntity::SerializeAsProto(
87 sync_pb::SyncEntity* proto) const { 71 sync_pb::SyncEntity* proto) const {
88 LoopbackServerEntity::SerializeBaseProtoFields(proto); 72 LoopbackServerEntity::SerializeBaseProtoFields(proto);
89 73
90 proto->set_client_defined_unique_tag(client_defined_unique_tag_); 74 proto->set_client_defined_unique_tag(client_defined_unique_tag_);
91 proto->set_ctime(creation_time_); 75 proto->set_ctime(creation_time_);
92 proto->set_mtime(last_modified_time_); 76 proto->set_mtime(last_modified_time_);
93 } 77 }
94 78
95 } // namespace syncer 79 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698