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

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

Issue 2360703002: [Sync] Implements the loopback sync server. (Closed)
Patch Set: Address comment. 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/persistent_bookmark_entity.cc
diff --git a/components/sync/engine_impl/loopback_server/persistent_bookmark_entity.cc b/components/sync/engine_impl/loopback_server/persistent_bookmark_entity.cc
new file mode 100644
index 0000000000000000000000000000000000000000..16728a982e583de692cb9484ca1c423c50bc4246
--- /dev/null
+++ b/components/sync/engine_impl/loopback_server/persistent_bookmark_entity.cc
@@ -0,0 +1,149 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/sync/engine_impl/loopback_server/persistent_bookmark_entity.h"
+
+#include <stdint.h>
+
+#include <memory>
+#include <string>
+
+#include "base/guid.h"
+#include "components/sync/base/model_type.h"
+#include "components/sync/engine_impl/loopback_server/loopback_server_entity.h"
+#include "components/sync/protocol/sync.pb.h"
+
+using std::string;
+
+namespace syncer {
+
+namespace {
+
+// Returns true if and only if |client_entity| is a bookmark.
+bool IsBookmark(const sync_pb::SyncEntity& client_entity) {
+ return syncer::GetModelType(client_entity) == syncer::BOOKMARKS;
+}
+
+} // namespace
+
+PersistentBookmarkEntity::~PersistentBookmarkEntity() {}
+
+// static
+std::unique_ptr<LoopbackServerEntity> PersistentBookmarkEntity::CreateNew(
+ const sync_pb::SyncEntity& client_entity,
+ const string& parent_id,
+ const string& client_guid) {
+ CHECK(client_entity.version() == 0) << "New entities must have version = 0.";
+ CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark.";
+
+ const string id =
+ LoopbackServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID());
+ const string originator_cache_guid = client_guid;
+ const string originator_client_item_id = client_entity.id_string();
+
+ return std::unique_ptr<LoopbackServerEntity>(new PersistentBookmarkEntity(
+ id, 0, client_entity.name(), originator_cache_guid,
+ originator_client_item_id, client_entity.unique_position(),
+ client_entity.specifics(), client_entity.folder(), parent_id,
+ client_entity.ctime(), client_entity.mtime()));
+}
+
+// static
+std::unique_ptr<LoopbackServerEntity>
+PersistentBookmarkEntity::CreateUpdatedVersion(
+ const sync_pb::SyncEntity& client_entity,
+ const LoopbackServerEntity& current_server_entity,
+ const string& parent_id) {
+ CHECK(client_entity.version() != 0) << "Existing entities must not have a "
+ << "version = 0.";
+ CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark.";
+
+ const PersistentBookmarkEntity& current_bookmark_entity =
+ static_cast<const PersistentBookmarkEntity&>(current_server_entity);
+ const string originator_cache_guid =
+ current_bookmark_entity.originator_cache_guid_;
+ const string originator_client_item_id =
+ current_bookmark_entity.originator_client_item_id_;
+
+ return std::unique_ptr<LoopbackServerEntity>(new PersistentBookmarkEntity(
+ client_entity.id_string(), 0, client_entity.name(), originator_cache_guid,
+ originator_client_item_id, client_entity.unique_position(),
+ client_entity.specifics(), client_entity.folder(), parent_id,
+ client_entity.ctime(), client_entity.mtime()));
+}
+
+// static
+std::unique_ptr<LoopbackServerEntity>
+PersistentBookmarkEntity::CreateFromEntity(
+ const sync_pb::SyncEntity& client_entity) {
+ CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark.";
+
+ return std::unique_ptr<LoopbackServerEntity>(new PersistentBookmarkEntity(
+ client_entity.id_string(), client_entity.version(), client_entity.name(),
+ client_entity.originator_cache_guid(),
+ client_entity.originator_client_item_id(),
+ client_entity.unique_position(), client_entity.specifics(),
+ client_entity.folder(), client_entity.parent_id_string(),
+ client_entity.ctime(), client_entity.mtime()));
+}
+PersistentBookmarkEntity::PersistentBookmarkEntity(
+ const string& id,
+ int64_t version,
+ const string& name,
+ const string& originator_cache_guid,
+ const string& originator_client_item_id,
+ const sync_pb::UniquePosition& unique_position,
+ const sync_pb::EntitySpecifics& specifics,
+ bool is_folder,
+ const string& parent_id,
+ int64_t creation_time,
+ int64_t last_modified_time)
+ : LoopbackServerEntity(id, syncer::BOOKMARKS, version, name),
+ originator_cache_guid_(originator_cache_guid),
+ originator_client_item_id_(originator_client_item_id),
+ unique_position_(unique_position),
+ is_folder_(is_folder),
+ parent_id_(parent_id),
+ creation_time_(creation_time),
+ last_modified_time_(last_modified_time) {
+ SetSpecifics(specifics);
+}
+
+void PersistentBookmarkEntity::SetParentId(const string& parent_id) {
+ parent_id_ = parent_id;
+}
+
+bool PersistentBookmarkEntity::RequiresParentId() const {
+ // Bookmarks are stored as a hierarchy. All bookmarks must have a parent ID.
+ return true;
+}
+
+string PersistentBookmarkEntity::GetParentId() const {
+ return parent_id_;
+}
+
+sync_pb::LoopbackServerEntity_Type
+PersistentBookmarkEntity::GetLoopbackServerEntityType() const {
+ return sync_pb::LoopbackServerEntity_Type_BOOKMARK;
+}
+
+void PersistentBookmarkEntity::SerializeAsProto(
+ sync_pb::SyncEntity* proto) const {
+ LoopbackServerEntity::SerializeBaseProtoFields(proto);
+
+ proto->set_originator_cache_guid(originator_cache_guid_);
+ proto->set_originator_client_item_id(originator_client_item_id_);
+
+ proto->set_ctime(creation_time_);
+ proto->set_mtime(last_modified_time_);
+
+ sync_pb::UniquePosition* unique_position = proto->mutable_unique_position();
+ unique_position->CopyFrom(unique_position_);
+}
+
+bool PersistentBookmarkEntity::IsFolder() const {
+ return is_folder_;
+}
+
+} // namespace syncer

Powered by Google App Engine
This is Rietveld 408576698