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

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

Issue 2502253003: [Sync] Move GenerateSyncableHash to base. (Closed)
Patch Set: Keep full syncable/ DEP. Created 4 years, 1 month 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/guid.h" 12 #include "base/guid.h"
13 #include "components/sync/base/model_type.h" 13 #include "components/sync/base/model_type.h"
14 #include "components/sync/engine_impl/loopback_server/loopback_server_entity.h" 14 #include "components/sync/engine_impl/loopback_server/loopback_server_entity.h"
15 #include "components/sync/engine_impl/loopback_server/persistent_permanent_entit y.h" 15 #include "components/sync/engine_impl/loopback_server/persistent_permanent_entit y.h"
16 #include "components/sync/protocol/sync.pb.h" 16 #include "components/sync/protocol/sync.pb.h"
17 #include "components/sync/syncable/syncable_util.h"
18 17
19 using std::string; 18 using std::string;
20 19
21 using syncer::GetModelTypeFromSpecifics;
22 using syncer::ModelType;
23 using syncer::syncable::GenerateSyncableHash;
24
25 namespace syncer { 20 namespace syncer {
26 21
27 PersistentUniqueClientEntity::PersistentUniqueClientEntity( 22 PersistentUniqueClientEntity::PersistentUniqueClientEntity(
28 const string& id, 23 const string& id,
29 ModelType model_type, 24 ModelType model_type,
30 int64_t version, 25 int64_t version,
31 const string& name, 26 const string& name,
32 const string& client_defined_unique_tag, 27 const string& client_defined_unique_tag,
33 const sync_pb::EntitySpecifics& specifics, 28 const sync_pb::EntitySpecifics& specifics,
34 int64_t creation_time, 29 int64_t creation_time,
35 int64_t last_modified_time) 30 int64_t last_modified_time)
36 : LoopbackServerEntity(id, model_type, version, name), 31 : LoopbackServerEntity(id, model_type, version, name),
37 client_defined_unique_tag_(client_defined_unique_tag), 32 client_defined_unique_tag_(client_defined_unique_tag),
38 creation_time_(creation_time), 33 creation_time_(creation_time),
39 last_modified_time_(last_modified_time) { 34 last_modified_time_(last_modified_time) {
40 SetSpecifics(specifics); 35 SetSpecifics(specifics);
41 } 36 }
42 37
43 PersistentUniqueClientEntity::~PersistentUniqueClientEntity() {} 38 PersistentUniqueClientEntity::~PersistentUniqueClientEntity() {}
44 39
45 // static 40 // static
46 std::unique_ptr<LoopbackServerEntity> PersistentUniqueClientEntity::Create( 41 std::unique_ptr<LoopbackServerEntity> PersistentUniqueClientEntity::Create(
47 const sync_pb::SyncEntity& client_entity) { 42 const sync_pb::SyncEntity& client_entity) {
48 CHECK(client_entity.has_client_defined_unique_tag()) 43 CHECK(client_entity.has_client_defined_unique_tag())
49 << "A PersistentUniqueClientEntity must have a client-defined unique " 44 << "A PersistentUniqueClientEntity must have a client-defined unique "
50 "tag."; 45 "tag.";
51 ModelType model_type = 46 ModelType model_type = GetModelTypeFromSpecifics(client_entity.specifics());
52 syncer::GetModelTypeFromSpecifics(client_entity.specifics());
53 string id = EffectiveIdForClientTaggedEntity(client_entity); 47 string id = EffectiveIdForClientTaggedEntity(client_entity);
54 return std::unique_ptr<LoopbackServerEntity>(new PersistentUniqueClientEntity( 48 return std::unique_ptr<LoopbackServerEntity>(new PersistentUniqueClientEntity(
55 id, model_type, client_entity.version(), client_entity.name(), 49 id, model_type, client_entity.version(), client_entity.name(),
56 client_entity.client_defined_unique_tag(), client_entity.specifics(), 50 client_entity.client_defined_unique_tag(), client_entity.specifics(),
57 client_entity.ctime(), client_entity.mtime())); 51 client_entity.ctime(), client_entity.mtime()));
58 } 52 }
59 53
60 // static 54 // static
61 std::string PersistentUniqueClientEntity::EffectiveIdForClientTaggedEntity( 55 std::string PersistentUniqueClientEntity::EffectiveIdForClientTaggedEntity(
62 const sync_pb::SyncEntity& entity) { 56 const sync_pb::SyncEntity& entity) {
63 return LoopbackServerEntity::CreateId( 57 return LoopbackServerEntity::CreateId(
64 syncer::GetModelTypeFromSpecifics(entity.specifics()), 58 GetModelTypeFromSpecifics(entity.specifics()),
65 entity.client_defined_unique_tag()); 59 entity.client_defined_unique_tag());
66 } 60 }
67 61
68 bool PersistentUniqueClientEntity::RequiresParentId() const { 62 bool PersistentUniqueClientEntity::RequiresParentId() const {
69 return false; 63 return false;
70 } 64 }
71 65
72 string PersistentUniqueClientEntity::GetParentId() const { 66 string PersistentUniqueClientEntity::GetParentId() const {
73 // The parent ID for this type of entity should always be its ModelType's 67 // The parent ID for this type of entity should always be its ModelType's
74 // root node. 68 // root node.
75 return LoopbackServerEntity::GetTopLevelId(GetModelType()); 69 return LoopbackServerEntity::GetTopLevelId(GetModelType());
76 } 70 }
77 71
78 sync_pb::LoopbackServerEntity_Type 72 sync_pb::LoopbackServerEntity_Type
79 PersistentUniqueClientEntity::GetLoopbackServerEntityType() const { 73 PersistentUniqueClientEntity::GetLoopbackServerEntityType() const {
80 return sync_pb::LoopbackServerEntity_Type_UNIQUE; 74 return sync_pb::LoopbackServerEntity_Type_UNIQUE;
81 } 75 }
82 76
83 void PersistentUniqueClientEntity::SerializeAsProto( 77 void PersistentUniqueClientEntity::SerializeAsProto(
84 sync_pb::SyncEntity* proto) const { 78 sync_pb::SyncEntity* proto) const {
85 LoopbackServerEntity::SerializeBaseProtoFields(proto); 79 LoopbackServerEntity::SerializeBaseProtoFields(proto);
86 80
87 proto->set_client_defined_unique_tag(client_defined_unique_tag_); 81 proto->set_client_defined_unique_tag(client_defined_unique_tag_);
88 proto->set_ctime(creation_time_); 82 proto->set_ctime(creation_time_);
89 proto->set_mtime(last_modified_time_); 83 proto->set_mtime(last_modified_time_);
90 } 84 }
91 85
92 } // namespace syncer 86 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/base/hash_util_unittest.cc ('k') | components/sync/engine_impl/model_type_worker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698