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

Unified Diff: components/sync/engine_impl/loopback_server/persistent_unique_client_entity.cc

Issue 2969643002: Reland - Replace FakeServer's implementation with LoopbackServer invocations. (Closed)
Patch Set: Rebased on master. Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: components/sync/engine_impl/loopback_server/persistent_unique_client_entity.cc
diff --git a/components/sync/engine_impl/loopback_server/persistent_unique_client_entity.cc b/components/sync/engine_impl/loopback_server/persistent_unique_client_entity.cc
index 9a2b8725b17d1d4c877cc6e15c0a33f6ad4df74e..c2bdcf730d09ab3ec9ed6623ef29f6c77211185b 100644
--- a/components/sync/engine_impl/loopback_server/persistent_unique_client_entity.cc
+++ b/components/sync/engine_impl/loopback_server/persistent_unique_client_entity.cc
@@ -5,6 +5,9 @@
#include "components/sync/engine_impl/loopback_server/persistent_unique_client_entity.h"
#include "base/guid.h"
+#include "base/rand_util.h"
+#include "base/strings/string_number_conversions.h"
+#include "components/sync/base/hash_util.h"
#include "components/sync/engine_impl/loopback_server/persistent_permanent_entity.h"
#include "components/sync/protocol/sync.pb.h"
@@ -31,13 +34,21 @@ PersistentUniqueClientEntity::PersistentUniqueClientEntity(
PersistentUniqueClientEntity::~PersistentUniqueClientEntity() {}
// static
-std::unique_ptr<LoopbackServerEntity> PersistentUniqueClientEntity::Create(
+std::unique_ptr<LoopbackServerEntity>
+PersistentUniqueClientEntity::CreateFromEntity(
const sync_pb::SyncEntity& client_entity) {
- CHECK(client_entity.has_client_defined_unique_tag())
- << "A PersistentUniqueClientEntity must have a client-defined unique "
- "tag.";
ModelType model_type = GetModelTypeFromSpecifics(client_entity.specifics());
- string id = EffectiveIdForClientTaggedEntity(client_entity);
+ CHECK_NE(client_entity.has_client_defined_unique_tag(),
+ syncer::CommitOnlyTypes().Has(model_type))
+ << "A UniqueClientEntity should have a client-defined unique tag iff it "
+ "is not a CommitOnly type.";
+ // Without model type specific logic for each CommitOnly type, we cannot infer
+ // a reasonable tag from the specifics. We need uniqueness for how the server
+ // holds onto all objects, so simply make a new tag from a random number.
+ string effective_tag = client_entity.has_client_defined_unique_tag()
+ ? client_entity.client_defined_unique_tag()
+ : base::Uint64ToString(base::RandUint64());
+ string id = LoopbackServerEntity::CreateId(model_type, effective_tag);
return std::unique_ptr<LoopbackServerEntity>(new PersistentUniqueClientEntity(
id, model_type, client_entity.version(), client_entity.name(),
client_entity.client_defined_unique_tag(), client_entity.specifics(),
@@ -45,11 +56,17 @@ std::unique_ptr<LoopbackServerEntity> PersistentUniqueClientEntity::Create(
}
// static
-std::string PersistentUniqueClientEntity::EffectiveIdForClientTaggedEntity(
- const sync_pb::SyncEntity& entity) {
- return LoopbackServerEntity::CreateId(
- GetModelTypeFromSpecifics(entity.specifics()),
- entity.client_defined_unique_tag());
+std::unique_ptr<LoopbackServerEntity>
+PersistentUniqueClientEntity::CreateFromEntitySpecifics(
+ const string& name,
+ const sync_pb::EntitySpecifics& entity_specifics) {
+ ModelType model_type = GetModelTypeFromSpecifics(entity_specifics);
+ string client_defined_unique_tag = GenerateSyncableHash(model_type, name);
+ string id =
+ LoopbackServerEntity::CreateId(model_type, client_defined_unique_tag);
+ return std::unique_ptr<LoopbackServerEntity>(new PersistentUniqueClientEntity(
+ id, model_type, 0, name, client_defined_unique_tag, entity_specifics,
+ 1337, 1337));
}
bool PersistentUniqueClientEntity::RequiresParentId() const {

Powered by Google App Engine
This is Rietveld 408576698