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

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

Issue 2360703002: [Sync] Implements the loopback sync server. (Closed)
Patch Set: Shuffle and rename stuff around. Created 4 years, 2 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/loopback_server_entity.cc
diff --git a/components/sync/test/fake_server/fake_server_entity.cc b/components/sync/engine_impl/loopback_server/loopback_server_entity.cc
similarity index 53%
copy from components/sync/test/fake_server/fake_server_entity.cc
copy to components/sync/engine_impl/loopback_server/loopback_server_entity.cc
index def68fccf4bf2513cd17632df83fe125310ead37..077aa81abdc044abded04d8190a81f2e911d7333 100644
--- a/components/sync/test/fake_server/fake_server_entity.cc
+++ b/components/sync/engine_impl/loopback_server/loopback_server_entity.cc
@@ -2,10 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/sync/test/fake_server/fake_server_entity.h"
+#include "components/sync/engine_impl/loopback_server/loopback_server_entity.h"
+
+#include <stdint.h>
#include <limits>
#include <memory>
+#include <string>
#include <vector>
#include "base/guid.h"
@@ -15,73 +18,90 @@
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
+#include "components/sync/base/model_type.h"
+#include "components/sync/protocol/sync.pb.h"
#include "net/base/net_errors.h"
#include "net/http/http_status_code.h"
using std::string;
using std::vector;
+
using syncer::ModelType;
+namespace {
// The separator used when formatting IDs.
//
// We chose the underscore character because it doesn't conflict with the
// special characters used by base/base64.h's encoding, which is also used in
// the construction of some IDs.
const char kIdSeparator[] = "_";
+} // namespace
-namespace fake_server {
+namespace syncer {
-FakeServerEntity::~FakeServerEntity() {}
+LoopbackServerEntity::~LoopbackServerEntity() {}
-int64_t FakeServerEntity::GetVersion() const {
+const std::string& LoopbackServerEntity::GetId() const {
+ return id_;
+}
+
+ModelType LoopbackServerEntity::GetModelType() const {
+ return model_type_;
+}
+
+int64_t LoopbackServerEntity::GetVersion() const {
return version_;
}
-void FakeServerEntity::SetVersion(int64_t version) {
+void LoopbackServerEntity::SetVersion(int64_t version) {
version_ = version;
}
-const std::string& FakeServerEntity::GetName() const {
+const std::string& LoopbackServerEntity::GetName() const {
return name_;
}
-void FakeServerEntity::SetName(const std::string& name) {
+void LoopbackServerEntity::SetName(const std::string& name) {
name_ = name;
}
-void FakeServerEntity::SetSpecifics(
+void LoopbackServerEntity::SetSpecifics(
const sync_pb::EntitySpecifics& updated_specifics) {
specifics_ = updated_specifics;
}
-bool FakeServerEntity::IsDeleted() const {
+sync_pb::EntitySpecifics LoopbackServerEntity::GetSpecifics() const {
+ return specifics_;
+}
+
+bool LoopbackServerEntity::IsDeleted() const {
return false;
}
-bool FakeServerEntity::IsFolder() const {
+bool LoopbackServerEntity::IsFolder() const {
return false;
}
-bool FakeServerEntity::IsPermanent() const {
+bool LoopbackServerEntity::IsPermanent() const {
return false;
}
// static
-string FakeServerEntity::CreateId(const ModelType& model_type,
- const string& inner_id) {
+string LoopbackServerEntity::CreateId(const ModelType& model_type,
+ const string& inner_id) {
int field_number = GetSpecificsFieldNumberFromModelType(model_type);
return base::StringPrintf("%d%s%s", field_number, kIdSeparator,
inner_id.c_str());
}
// static
-std::string FakeServerEntity::GetTopLevelId(const ModelType& model_type) {
- return FakeServerEntity::CreateId(model_type,
- syncer::ModelTypeToRootTag(model_type));
+std::string LoopbackServerEntity::GetTopLevelId(const ModelType& model_type) {
+ return LoopbackServerEntity::CreateId(model_type,
+ syncer::ModelTypeToRootTag(model_type));
}
// static
-ModelType FakeServerEntity::GetModelTypeFromId(const string& id) {
+ModelType LoopbackServerEntity::GetModelTypeFromId(const string& id) {
vector<base::StringPiece> tokens = base::SplitStringPiece(
id, kIdSeparator, base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
@@ -93,29 +113,19 @@ ModelType FakeServerEntity::GetModelTypeFromId(const string& id) {
return syncer::GetModelTypeFromSpecificsFieldNumber(field_number);
}
-FakeServerEntity::FakeServerEntity(const string& id,
- const string& client_defined_unique_tag,
- const ModelType& model_type,
- int64_t version,
- const string& name)
- : id_(id),
- client_defined_unique_tag_(client_defined_unique_tag),
- model_type_(model_type),
- version_(version),
- name_(name) {
- // There shouldn't be a unique_tag if the type is bookmarks.
- DCHECK(model_type != syncer::BOOKMARKS || client_defined_unique_tag.empty());
-}
+LoopbackServerEntity::LoopbackServerEntity(const string& id,
+ const ModelType& model_type,
+ int64_t version,
+ const string& name)
+ : id_(id), model_type_(model_type), version_(version), name_(name) {}
-void FakeServerEntity::SerializeBaseProtoFields(
+void LoopbackServerEntity::SerializeBaseProtoFields(
sync_pb::SyncEntity* sync_entity) const {
sync_pb::EntitySpecifics* specifics = sync_entity->mutable_specifics();
specifics->CopyFrom(specifics_);
- // FakeServerEntity fields
+ // LoopbackServerEntity fields
sync_entity->set_id_string(id_);
- if (!client_defined_unique_tag_.empty())
- sync_entity->set_client_defined_unique_tag(client_defined_unique_tag_);
sync_entity->set_version(version_);
sync_entity->set_name(name_);
@@ -127,4 +137,4 @@ void FakeServerEntity::SerializeBaseProtoFields(
sync_entity->set_parent_id_string(GetParentId());
}
-} // namespace fake_server
+} // namespace syncer

Powered by Google App Engine
This is Rietveld 408576698