| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/sync/test/fake_server/bookmark_entity.h" |
| 6 |
| 7 #include "base/guid.h" |
| 8 |
| 9 using std::string; |
| 10 |
| 11 namespace fake_server { |
| 12 namespace { |
| 13 |
| 14 // Returns true if and only if |client_entity| is a bookmark. |
| 15 bool IsBookmark(const sync_pb::SyncEntity& client_entity) { |
| 16 return syncer::GetModelType(client_entity) == syncer::BOOKMARKS; |
| 17 } |
| 18 |
| 19 } // namespace |
| 20 |
| 21 BookmarkEntity::~BookmarkEntity() {} |
| 22 |
| 23 // static |
| 24 std::unique_ptr<FakeServerEntity> BookmarkEntity::CreateNew( |
| 25 const sync_pb::SyncEntity& client_entity, |
| 26 const string& parent_id, |
| 27 const string& client_guid) { |
| 28 CHECK_EQ(0, client_entity.version()) << "New entities must have version = 0."; |
| 29 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; |
| 30 |
| 31 const string id = |
| 32 FakeServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID()); |
| 33 const string originator_cache_guid = client_guid; |
| 34 const string originator_client_item_id = client_entity.id_string(); |
| 35 |
| 36 return std::unique_ptr<FakeServerEntity>(new BookmarkEntity( |
| 37 id, client_entity.version(), client_entity.name(), originator_cache_guid, |
| 38 originator_client_item_id, client_entity.unique_position(), |
| 39 client_entity.specifics(), client_entity.folder(), parent_id, |
| 40 client_entity.ctime(), client_entity.mtime())); |
| 41 } |
| 42 |
| 43 // static |
| 44 std::unique_ptr<FakeServerEntity> BookmarkEntity::CreateUpdatedVersion( |
| 45 const sync_pb::SyncEntity& client_entity, |
| 46 const FakeServerEntity& current_server_entity, |
| 47 const string& parent_id) { |
| 48 CHECK_NE(0, client_entity.version()) << "Existing entities must not have a " |
| 49 << "version = 0."; |
| 50 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; |
| 51 |
| 52 const BookmarkEntity& current_bookmark_entity = |
| 53 static_cast<const BookmarkEntity&>(current_server_entity); |
| 54 const string originator_cache_guid = |
| 55 current_bookmark_entity.originator_cache_guid_; |
| 56 const string originator_client_item_id = |
| 57 current_bookmark_entity.originator_client_item_id_; |
| 58 |
| 59 return std::unique_ptr<FakeServerEntity>(new BookmarkEntity( |
| 60 client_entity.id_string(), client_entity.version(), client_entity.name(), |
| 61 originator_cache_guid, originator_client_item_id, |
| 62 client_entity.unique_position(), client_entity.specifics(), |
| 63 client_entity.folder(), parent_id, client_entity.ctime(), |
| 64 client_entity.mtime())); |
| 65 } |
| 66 |
| 67 BookmarkEntity::BookmarkEntity(const string& id, |
| 68 int64_t version, |
| 69 const string& name, |
| 70 const string& originator_cache_guid, |
| 71 const string& originator_client_item_id, |
| 72 const sync_pb::UniquePosition& unique_position, |
| 73 const sync_pb::EntitySpecifics& specifics, |
| 74 bool is_folder, |
| 75 const string& parent_id, |
| 76 int64_t creation_time, |
| 77 int64_t last_modified_time) |
| 78 : FakeServerEntity(id, string(), syncer::BOOKMARKS, version, name), |
| 79 originator_cache_guid_(originator_cache_guid), |
| 80 originator_client_item_id_(originator_client_item_id), |
| 81 unique_position_(unique_position), |
| 82 is_folder_(is_folder), |
| 83 parent_id_(parent_id), |
| 84 creation_time_(creation_time), |
| 85 last_modified_time_(last_modified_time) { |
| 86 SetSpecifics(specifics); |
| 87 } |
| 88 |
| 89 void BookmarkEntity::SetParentId(const string& parent_id) { |
| 90 parent_id_ = parent_id; |
| 91 } |
| 92 |
| 93 bool BookmarkEntity::RequiresParentId() const { |
| 94 // Bookmarks are stored as a hierarchy. All bookmarks must have a parent ID. |
| 95 return true; |
| 96 } |
| 97 |
| 98 string BookmarkEntity::GetParentId() const { |
| 99 return parent_id_; |
| 100 } |
| 101 |
| 102 void BookmarkEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const { |
| 103 FakeServerEntity::SerializeBaseProtoFields(proto); |
| 104 |
| 105 proto->set_originator_cache_guid(originator_cache_guid_); |
| 106 proto->set_originator_client_item_id(originator_client_item_id_); |
| 107 |
| 108 proto->set_ctime(creation_time_); |
| 109 proto->set_mtime(last_modified_time_); |
| 110 |
| 111 sync_pb::UniquePosition* unique_position = proto->mutable_unique_position(); |
| 112 unique_position->CopyFrom(unique_position_); |
| 113 } |
| 114 |
| 115 bool BookmarkEntity::IsFolder() const { |
| 116 return is_folder_; |
| 117 } |
| 118 |
| 119 } // namespace fake_server |
| OLD | NEW |