| 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/test/fake_server/bookmark_entity_builder.h" | 5 #include "components/sync/test/fake_server/bookmark_entity_builder.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "components/sync/base/hash_util.h" | 12 #include "components/sync/base/hash_util.h" |
| 13 #include "components/sync/base/time.h" | 13 #include "components/sync/base/time.h" |
| 14 #include "components/sync/base/unique_position.h" | 14 #include "components/sync/base/unique_position.h" |
| 15 #include "components/sync/engine_impl/loopback_server/persistent_bookmark_entity
.h" | |
| 16 #include "components/sync/protocol/sync.pb.h" | 15 #include "components/sync/protocol/sync.pb.h" |
| 16 #include "components/sync/test/fake_server/bookmark_entity.h" |
| 17 | 17 |
| 18 using std::string; | 18 using std::string; |
| 19 using syncer::GenerateSyncableBookmarkHash; | 19 using syncer::GenerateSyncableBookmarkHash; |
| 20 using syncer::LoopbackServerEntity; | |
| 21 | 20 |
| 22 // A version must be passed when creating a LoopbackServerEntity, but this value | 21 // A version must be passed when creating a FakeServerEntity, but this value |
| 23 // is overrideen immediately when saving the entity in FakeServer. | 22 // is overrideen immediately when saving the entity in FakeServer. |
| 24 const int64_t kUnusedVersion = 0L; | 23 const int64_t kUnusedVersion = 0L; |
| 25 | 24 |
| 26 // Default time (creation and last modified) used when creating entities. | 25 // Default time (creation and last modified) used when creating entities. |
| 27 const int64_t kDefaultTime = 1234L; | 26 const int64_t kDefaultTime = 1234L; |
| 28 | 27 |
| 29 namespace fake_server { | 28 namespace fake_server { |
| 30 | 29 |
| 31 BookmarkEntityBuilder::BookmarkEntityBuilder( | 30 BookmarkEntityBuilder::BookmarkEntityBuilder( |
| 32 const string& title, | 31 const string& title, |
| 33 const string& originator_cache_guid, | 32 const string& originator_cache_guid, |
| 34 const string& originator_client_item_id) | 33 const string& originator_client_item_id) |
| 35 : title_(title), | 34 : title_(title), |
| 36 originator_cache_guid_(originator_cache_guid), | 35 originator_cache_guid_(originator_cache_guid), |
| 37 originator_client_item_id_(originator_client_item_id) {} | 36 originator_client_item_id_(originator_client_item_id) {} |
| 38 | 37 |
| 39 BookmarkEntityBuilder::BookmarkEntityBuilder( | 38 BookmarkEntityBuilder::BookmarkEntityBuilder( |
| 40 const BookmarkEntityBuilder& other) = default; | 39 const BookmarkEntityBuilder& other) = default; |
| 41 | 40 |
| 42 BookmarkEntityBuilder::~BookmarkEntityBuilder() {} | 41 BookmarkEntityBuilder::~BookmarkEntityBuilder() {} |
| 43 | 42 |
| 44 void BookmarkEntityBuilder::SetParentId(const std::string& parent_id) { | 43 void BookmarkEntityBuilder::SetParentId(const std::string& parent_id) { |
| 45 parent_id_ = parent_id; | 44 parent_id_ = parent_id; |
| 46 } | 45 } |
| 47 | 46 |
| 48 std::unique_ptr<LoopbackServerEntity> BookmarkEntityBuilder::BuildBookmark( | 47 std::unique_ptr<FakeServerEntity> BookmarkEntityBuilder::BuildBookmark( |
| 49 const GURL& url) { | 48 const GURL& url) { |
| 50 if (!url.is_valid()) { | 49 if (!url.is_valid()) { |
| 51 return base::WrapUnique<LoopbackServerEntity>(nullptr); | 50 return base::WrapUnique<FakeServerEntity>(nullptr); |
| 52 } | 51 } |
| 53 | 52 |
| 54 sync_pb::EntitySpecifics entity_specifics = CreateBaseEntitySpecifics(); | 53 sync_pb::EntitySpecifics entity_specifics = CreateBaseEntitySpecifics(); |
| 55 entity_specifics.mutable_bookmark()->set_url(url.spec()); | 54 entity_specifics.mutable_bookmark()->set_url(url.spec()); |
| 56 const bool kIsNotFolder = false; | 55 const bool kIsNotFolder = false; |
| 57 return Build(entity_specifics, kIsNotFolder); | 56 return Build(entity_specifics, kIsNotFolder); |
| 58 } | 57 } |
| 59 | 58 |
| 60 std::unique_ptr<LoopbackServerEntity> BookmarkEntityBuilder::BuildFolder() { | 59 std::unique_ptr<FakeServerEntity> BookmarkEntityBuilder::BuildFolder() { |
| 61 const bool kIsFolder = true; | 60 const bool kIsFolder = true; |
| 62 return Build(CreateBaseEntitySpecifics(), kIsFolder); | 61 return Build(CreateBaseEntitySpecifics(), kIsFolder); |
| 63 } | 62 } |
| 64 | 63 |
| 65 sync_pb::EntitySpecifics BookmarkEntityBuilder::CreateBaseEntitySpecifics() | 64 sync_pb::EntitySpecifics BookmarkEntityBuilder::CreateBaseEntitySpecifics() |
| 66 const { | 65 const { |
| 67 sync_pb::EntitySpecifics entity_specifics; | 66 sync_pb::EntitySpecifics entity_specifics; |
| 68 sync_pb::BookmarkSpecifics* bookmark_specifics = | 67 sync_pb::BookmarkSpecifics* bookmark_specifics = |
| 69 entity_specifics.mutable_bookmark(); | 68 entity_specifics.mutable_bookmark(); |
| 70 bookmark_specifics->set_title(title_); | 69 bookmark_specifics->set_title(title_); |
| 71 | 70 |
| 72 return entity_specifics; | 71 return entity_specifics; |
| 73 } | 72 } |
| 74 | 73 |
| 75 std::unique_ptr<LoopbackServerEntity> BookmarkEntityBuilder::Build( | 74 std::unique_ptr<FakeServerEntity> BookmarkEntityBuilder::Build( |
| 76 const sync_pb::EntitySpecifics& entity_specifics, | 75 const sync_pb::EntitySpecifics& entity_specifics, |
| 77 bool is_folder) { | 76 bool is_folder) { |
| 78 sync_pb::UniquePosition unique_position; | 77 sync_pb::UniquePosition unique_position; |
| 79 // TODO(pvalenzuela): Allow caller customization of the position integer. | 78 // TODO(pvalenzuela): Allow caller customization of the position integer. |
| 80 const string suffix = GenerateSyncableBookmarkHash( | 79 const string suffix = GenerateSyncableBookmarkHash( |
| 81 originator_cache_guid_, originator_client_item_id_); | 80 originator_cache_guid_, originator_client_item_id_); |
| 82 syncer::UniquePosition::FromInt64(0, suffix).ToProto(&unique_position); | 81 syncer::UniquePosition::FromInt64(0, suffix).ToProto(&unique_position); |
| 83 | 82 |
| 84 if (parent_id_.empty()) { | 83 if (parent_id_.empty()) { |
| 85 parent_id_ = | 84 parent_id_ = FakeServerEntity::CreateId(syncer::BOOKMARKS, "bookmark_bar"); |
| 86 LoopbackServerEntity::CreateId(syncer::BOOKMARKS, "bookmark_bar"); | |
| 87 } | 85 } |
| 88 | 86 |
| 89 const string id = | 87 const string id = |
| 90 LoopbackServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID()); | 88 FakeServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID()); |
| 91 | 89 |
| 92 return base::WrapUnique<LoopbackServerEntity>( | 90 return base::WrapUnique<FakeServerEntity>(new BookmarkEntity( |
| 93 new syncer::PersistentBookmarkEntity( | 91 id, kUnusedVersion, title_, originator_cache_guid_, |
| 94 id, kUnusedVersion, title_, originator_cache_guid_, | 92 originator_client_item_id_, unique_position, entity_specifics, is_folder, |
| 95 originator_client_item_id_, unique_position, entity_specifics, | 93 parent_id_, kDefaultTime, kDefaultTime)); |
| 96 is_folder, parent_id_, kDefaultTime, kDefaultTime)); | |
| 97 } | 94 } |
| 98 | 95 |
| 99 } // namespace fake_server | 96 } // namespace fake_server |
| OLD | NEW |