| OLD | NEW |
| 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_bookmark_entity
.h" | 5 #include "components/sync/engine_impl/loopback_server/persistent_bookmark_entity
.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> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 PersistentBookmarkEntity::~PersistentBookmarkEntity() {} | 30 PersistentBookmarkEntity::~PersistentBookmarkEntity() {} |
| 31 | 31 |
| 32 // static | 32 // static |
| 33 std::unique_ptr<LoopbackServerEntity> PersistentBookmarkEntity::CreateNew( | 33 std::unique_ptr<LoopbackServerEntity> PersistentBookmarkEntity::CreateNew( |
| 34 const sync_pb::SyncEntity& client_entity, | 34 const sync_pb::SyncEntity& client_entity, |
| 35 const string& parent_id, | 35 const string& parent_id, |
| 36 const string& client_guid) { | 36 const string& client_guid) { |
| 37 CHECK(client_entity.version() == 0) << "New entities must have version = 0."; | 37 // New entities must have version = 0. |
| 38 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; | 38 CHECK_EQ(client_entity.version(), 0); |
| 39 // The given entity must be a bookmark. |
| 40 CHECK(IsBookmark(client_entity)); |
| 39 | 41 |
| 40 const string id = | 42 const string id = |
| 41 LoopbackServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID()); | 43 LoopbackServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID()); |
| 42 const string originator_cache_guid = client_guid; | 44 const string originator_cache_guid = client_guid; |
| 43 const string originator_client_item_id = client_entity.id_string(); | 45 const string originator_client_item_id = client_entity.id_string(); |
| 44 | 46 |
| 45 return std::unique_ptr<LoopbackServerEntity>(new PersistentBookmarkEntity( | 47 return std::unique_ptr<LoopbackServerEntity>(new PersistentBookmarkEntity( |
| 46 id, 0, client_entity.name(), originator_cache_guid, | 48 id, 0, client_entity.name(), originator_cache_guid, |
| 47 originator_client_item_id, client_entity.unique_position(), | 49 originator_client_item_id, client_entity.unique_position(), |
| 48 client_entity.specifics(), client_entity.folder(), parent_id, | 50 client_entity.specifics(), client_entity.folder(), parent_id, |
| 49 client_entity.ctime(), client_entity.mtime())); | 51 client_entity.ctime(), client_entity.mtime())); |
| 50 } | 52 } |
| 51 | 53 |
| 52 // static | 54 // static |
| 53 std::unique_ptr<LoopbackServerEntity> | 55 std::unique_ptr<LoopbackServerEntity> |
| 54 PersistentBookmarkEntity::CreateUpdatedVersion( | 56 PersistentBookmarkEntity::CreateUpdatedVersion( |
| 55 const sync_pb::SyncEntity& client_entity, | 57 const sync_pb::SyncEntity& client_entity, |
| 56 const LoopbackServerEntity& current_server_entity, | 58 const LoopbackServerEntity& current_server_entity, |
| 57 const string& parent_id) { | 59 const string& parent_id) { |
| 58 CHECK(client_entity.version() != 0) << "Existing entities must not have a " | 60 // Existing entities must not have a version = 0. |
| 59 << "version = 0."; | 61 CHECK_NE(client_entity.version(), 0); |
| 60 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; | 62 // The given entity must be a bookmark. |
| 63 CHECK(IsBookmark(client_entity)); |
| 61 | 64 |
| 62 const PersistentBookmarkEntity& current_bookmark_entity = | 65 const PersistentBookmarkEntity& current_bookmark_entity = |
| 63 static_cast<const PersistentBookmarkEntity&>(current_server_entity); | 66 static_cast<const PersistentBookmarkEntity&>(current_server_entity); |
| 64 const string originator_cache_guid = | 67 const string originator_cache_guid = |
| 65 current_bookmark_entity.originator_cache_guid_; | 68 current_bookmark_entity.originator_cache_guid_; |
| 66 const string originator_client_item_id = | 69 const string originator_client_item_id = |
| 67 current_bookmark_entity.originator_client_item_id_; | 70 current_bookmark_entity.originator_client_item_id_; |
| 68 | 71 |
| 69 return std::unique_ptr<LoopbackServerEntity>(new PersistentBookmarkEntity( | 72 return std::unique_ptr<LoopbackServerEntity>(new PersistentBookmarkEntity( |
| 70 client_entity.id_string(), 0, client_entity.name(), originator_cache_guid, | 73 client_entity.id_string(), 0, client_entity.name(), originator_cache_guid, |
| 71 originator_client_item_id, client_entity.unique_position(), | 74 originator_client_item_id, client_entity.unique_position(), |
| 72 client_entity.specifics(), client_entity.folder(), parent_id, | 75 client_entity.specifics(), client_entity.folder(), parent_id, |
| 73 client_entity.ctime(), client_entity.mtime())); | 76 client_entity.ctime(), client_entity.mtime())); |
| 74 } | 77 } |
| 75 | 78 |
| 76 // static | 79 // static |
| 77 std::unique_ptr<LoopbackServerEntity> | 80 std::unique_ptr<LoopbackServerEntity> |
| 78 PersistentBookmarkEntity::CreateFromEntity( | 81 PersistentBookmarkEntity::CreateFromEntity( |
| 79 const sync_pb::SyncEntity& client_entity) { | 82 const sync_pb::SyncEntity& client_entity) { |
| 80 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; | 83 // The given entity must be a bookmark. |
| 84 CHECK(IsBookmark(client_entity)); |
| 81 | 85 |
| 82 return std::unique_ptr<LoopbackServerEntity>(new PersistentBookmarkEntity( | 86 return std::unique_ptr<LoopbackServerEntity>(new PersistentBookmarkEntity( |
| 83 client_entity.id_string(), client_entity.version(), client_entity.name(), | 87 client_entity.id_string(), client_entity.version(), client_entity.name(), |
| 84 client_entity.originator_cache_guid(), | 88 client_entity.originator_cache_guid(), |
| 85 client_entity.originator_client_item_id(), | 89 client_entity.originator_client_item_id(), |
| 86 client_entity.unique_position(), client_entity.specifics(), | 90 client_entity.unique_position(), client_entity.specifics(), |
| 87 client_entity.folder(), client_entity.parent_id_string(), | 91 client_entity.folder(), client_entity.parent_id_string(), |
| 88 client_entity.ctime(), client_entity.mtime())); | 92 client_entity.ctime(), client_entity.mtime())); |
| 89 } | 93 } |
| 90 PersistentBookmarkEntity::PersistentBookmarkEntity( | 94 PersistentBookmarkEntity::PersistentBookmarkEntity( |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 144 |
| 141 sync_pb::UniquePosition* unique_position = proto->mutable_unique_position(); | 145 sync_pb::UniquePosition* unique_position = proto->mutable_unique_position(); |
| 142 unique_position->CopyFrom(unique_position_); | 146 unique_position->CopyFrom(unique_position_); |
| 143 } | 147 } |
| 144 | 148 |
| 145 bool PersistentBookmarkEntity::IsFolder() const { | 149 bool PersistentBookmarkEntity::IsFolder() const { |
| 146 return is_folder_; | 150 return is_folder_; |
| 147 } | 151 } |
| 148 | 152 |
| 149 } // namespace syncer | 153 } // namespace syncer |
| OLD | NEW |