| 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 "sync/test/fake_server/bookmark_entity.h" | 5 #include "sync/test/fake_server/bookmark_entity.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // Returns true if and only if |client_entity| is a bookmark. | 22 // Returns true if and only if |client_entity| is a bookmark. |
| 23 bool IsBookmark(const sync_pb::SyncEntity& client_entity) { | 23 bool IsBookmark(const sync_pb::SyncEntity& client_entity) { |
| 24 return syncer::GetModelType(client_entity) == syncer::BOOKMARKS; | 24 return syncer::GetModelType(client_entity) == syncer::BOOKMARKS; |
| 25 } | 25 } |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 BookmarkEntity::~BookmarkEntity() { } | 29 BookmarkEntity::~BookmarkEntity() { } |
| 30 | 30 |
| 31 // static | 31 // static |
| 32 scoped_ptr<FakeServerEntity> BookmarkEntity::CreateNew( | 32 std::unique_ptr<FakeServerEntity> BookmarkEntity::CreateNew( |
| 33 const sync_pb::SyncEntity& client_entity, | 33 const sync_pb::SyncEntity& client_entity, |
| 34 const string& parent_id, | 34 const string& parent_id, |
| 35 const string& client_guid) { | 35 const string& client_guid) { |
| 36 CHECK(client_entity.version() == 0) << "New entities must have version = 0."; | 36 CHECK(client_entity.version() == 0) << "New entities must have version = 0."; |
| 37 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; | 37 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; |
| 38 | 38 |
| 39 const string id = | 39 const string id = |
| 40 FakeServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID()); | 40 FakeServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID()); |
| 41 const string originator_cache_guid = client_guid; | 41 const string originator_cache_guid = client_guid; |
| 42 const string originator_client_item_id = client_entity.id_string(); | 42 const string originator_client_item_id = client_entity.id_string(); |
| 43 | 43 |
| 44 return scoped_ptr<FakeServerEntity>(new BookmarkEntity( | 44 return std::unique_ptr<FakeServerEntity>(new BookmarkEntity( |
| 45 id, client_entity.version(), client_entity.name(), originator_cache_guid, | 45 id, client_entity.version(), client_entity.name(), originator_cache_guid, |
| 46 originator_client_item_id, client_entity.unique_position(), | 46 originator_client_item_id, client_entity.unique_position(), |
| 47 client_entity.specifics(), client_entity.folder(), parent_id, | 47 client_entity.specifics(), client_entity.folder(), parent_id, |
| 48 client_entity.ctime(), client_entity.mtime())); | 48 client_entity.ctime(), client_entity.mtime())); |
| 49 } | 49 } |
| 50 | 50 |
| 51 // static | 51 // static |
| 52 scoped_ptr<FakeServerEntity> BookmarkEntity::CreateUpdatedVersion( | 52 std::unique_ptr<FakeServerEntity> BookmarkEntity::CreateUpdatedVersion( |
| 53 const sync_pb::SyncEntity& client_entity, | 53 const sync_pb::SyncEntity& client_entity, |
| 54 const FakeServerEntity& current_server_entity, | 54 const FakeServerEntity& current_server_entity, |
| 55 const string& parent_id) { | 55 const string& parent_id) { |
| 56 CHECK(client_entity.version() != 0) << "Existing entities must not have a " | 56 CHECK(client_entity.version() != 0) << "Existing entities must not have a " |
| 57 << "version = 0."; | 57 << "version = 0."; |
| 58 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; | 58 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; |
| 59 | 59 |
| 60 const BookmarkEntity& current_bookmark_entity = | 60 const BookmarkEntity& current_bookmark_entity = |
| 61 static_cast<const BookmarkEntity&>(current_server_entity); | 61 static_cast<const BookmarkEntity&>(current_server_entity); |
| 62 const string originator_cache_guid = | 62 const string originator_cache_guid = |
| 63 current_bookmark_entity.originator_cache_guid_; | 63 current_bookmark_entity.originator_cache_guid_; |
| 64 const string originator_client_item_id = | 64 const string originator_client_item_id = |
| 65 current_bookmark_entity.originator_client_item_id_; | 65 current_bookmark_entity.originator_client_item_id_; |
| 66 | 66 |
| 67 return scoped_ptr<FakeServerEntity>(new BookmarkEntity( | 67 return std::unique_ptr<FakeServerEntity>(new BookmarkEntity( |
| 68 client_entity.id_string(), client_entity.version(), client_entity.name(), | 68 client_entity.id_string(), client_entity.version(), client_entity.name(), |
| 69 originator_cache_guid, originator_client_item_id, | 69 originator_cache_guid, originator_client_item_id, |
| 70 client_entity.unique_position(), client_entity.specifics(), | 70 client_entity.unique_position(), client_entity.specifics(), |
| 71 client_entity.folder(), parent_id, client_entity.ctime(), | 71 client_entity.folder(), parent_id, client_entity.ctime(), |
| 72 client_entity.mtime())); | 72 client_entity.mtime())); |
| 73 } | 73 } |
| 74 | 74 |
| 75 BookmarkEntity::BookmarkEntity(const string& id, | 75 BookmarkEntity::BookmarkEntity(const string& id, |
| 76 int64_t version, | 76 int64_t version, |
| 77 const string& name, | 77 const string& name, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 118 |
| 119 sync_pb::UniquePosition* unique_position = proto->mutable_unique_position(); | 119 sync_pb::UniquePosition* unique_position = proto->mutable_unique_position(); |
| 120 unique_position->CopyFrom(unique_position_); | 120 unique_position->CopyFrom(unique_position_); |
| 121 } | 121 } |
| 122 | 122 |
| 123 bool BookmarkEntity::IsFolder() const { | 123 bool BookmarkEntity::IsFolder() const { |
| 124 return is_folder_; | 124 return is_folder_; |
| 125 } | 125 } |
| 126 | 126 |
| 127 } // namespace fake_server | 127 } // namespace fake_server |
| OLD | NEW |