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_builder.h" | 5 #include "sync/test/fake_server/bookmark_entity_builder.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
| 9 #include <memory> |
9 #include <string> | 10 #include <string> |
10 | 11 |
11 #include "base/guid.h" | 12 #include "base/guid.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/ptr_util.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "sync/internal_api/public/base/model_type.h" | 15 #include "sync/internal_api/public/base/model_type.h" |
15 #include "sync/internal_api/public/base/unique_position.h" | 16 #include "sync/internal_api/public/base/unique_position.h" |
16 #include "sync/protocol/sync.pb.h" | 17 #include "sync/protocol/sync.pb.h" |
17 #include "sync/syncable/syncable_util.h" | 18 #include "sync/syncable/syncable_util.h" |
18 #include "sync/test/fake_server/bookmark_entity.h" | 19 #include "sync/test/fake_server/bookmark_entity.h" |
19 #include "sync/test/fake_server/fake_server_entity.h" | 20 #include "sync/test/fake_server/fake_server_entity.h" |
20 #include "sync/util/time.h" | 21 #include "sync/util/time.h" |
21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
22 | 23 |
(...skipping 22 matching lines...) Expand all Loading... |
45 BookmarkEntityBuilder::BookmarkEntityBuilder( | 46 BookmarkEntityBuilder::BookmarkEntityBuilder( |
46 const BookmarkEntityBuilder& other) = default; | 47 const BookmarkEntityBuilder& other) = default; |
47 | 48 |
48 BookmarkEntityBuilder::~BookmarkEntityBuilder() { | 49 BookmarkEntityBuilder::~BookmarkEntityBuilder() { |
49 } | 50 } |
50 | 51 |
51 void BookmarkEntityBuilder::SetParentId(const std::string& parent_id) { | 52 void BookmarkEntityBuilder::SetParentId(const std::string& parent_id) { |
52 parent_id_ = parent_id; | 53 parent_id_ = parent_id; |
53 } | 54 } |
54 | 55 |
55 scoped_ptr<FakeServerEntity> BookmarkEntityBuilder::BuildBookmark( | 56 std::unique_ptr<FakeServerEntity> BookmarkEntityBuilder::BuildBookmark( |
56 const GURL& url) { | 57 const GURL& url) { |
57 if (!url.is_valid()) { | 58 if (!url.is_valid()) { |
58 return make_scoped_ptr<FakeServerEntity>(NULL); | 59 return base::WrapUnique<FakeServerEntity>(NULL); |
59 } | 60 } |
60 | 61 |
61 sync_pb::EntitySpecifics entity_specifics = CreateBaseEntitySpecifics(); | 62 sync_pb::EntitySpecifics entity_specifics = CreateBaseEntitySpecifics(); |
62 entity_specifics.mutable_bookmark()->set_url(url.spec()); | 63 entity_specifics.mutable_bookmark()->set_url(url.spec()); |
63 const bool kIsNotFolder = false; | 64 const bool kIsNotFolder = false; |
64 return Build(entity_specifics, kIsNotFolder); | 65 return Build(entity_specifics, kIsNotFolder); |
65 } | 66 } |
66 | 67 |
67 scoped_ptr<FakeServerEntity> BookmarkEntityBuilder::BuildFolder() { | 68 std::unique_ptr<FakeServerEntity> BookmarkEntityBuilder::BuildFolder() { |
68 const bool kIsFolder = true; | 69 const bool kIsFolder = true; |
69 return Build(CreateBaseEntitySpecifics(), kIsFolder); | 70 return Build(CreateBaseEntitySpecifics(), kIsFolder); |
70 } | 71 } |
71 | 72 |
72 sync_pb::EntitySpecifics BookmarkEntityBuilder::CreateBaseEntitySpecifics() | 73 sync_pb::EntitySpecifics BookmarkEntityBuilder::CreateBaseEntitySpecifics() |
73 const { | 74 const { |
74 sync_pb::EntitySpecifics entity_specifics; | 75 sync_pb::EntitySpecifics entity_specifics; |
75 sync_pb::BookmarkSpecifics* bookmark_specifics = | 76 sync_pb::BookmarkSpecifics* bookmark_specifics = |
76 entity_specifics.mutable_bookmark(); | 77 entity_specifics.mutable_bookmark(); |
77 bookmark_specifics->set_title(title_); | 78 bookmark_specifics->set_title(title_); |
78 | 79 |
79 return entity_specifics; | 80 return entity_specifics; |
80 } | 81 } |
81 | 82 |
82 scoped_ptr<FakeServerEntity> BookmarkEntityBuilder::Build( | 83 std::unique_ptr<FakeServerEntity> BookmarkEntityBuilder::Build( |
83 const sync_pb::EntitySpecifics& entity_specifics, | 84 const sync_pb::EntitySpecifics& entity_specifics, |
84 bool is_folder) { | 85 bool is_folder) { |
85 sync_pb::UniquePosition unique_position; | 86 sync_pb::UniquePosition unique_position; |
86 // TODO(pvalenzuela): Allow caller customization of the position integer. | 87 // TODO(pvalenzuela): Allow caller customization of the position integer. |
87 const string suffix = GenerateSyncableBookmarkHash( | 88 const string suffix = GenerateSyncableBookmarkHash( |
88 originator_cache_guid_, | 89 originator_cache_guid_, |
89 originator_client_item_id_); | 90 originator_client_item_id_); |
90 syncer::UniquePosition::FromInt64(0, suffix).ToProto(&unique_position); | 91 syncer::UniquePosition::FromInt64(0, suffix).ToProto(&unique_position); |
91 | 92 |
92 if (parent_id_.empty()) { | 93 if (parent_id_.empty()) { |
93 parent_id_ = FakeServerEntity::CreateId(syncer::BOOKMARKS, "bookmark_bar"); | 94 parent_id_ = FakeServerEntity::CreateId(syncer::BOOKMARKS, "bookmark_bar"); |
94 } | 95 } |
95 | 96 |
96 const string id = FakeServerEntity::CreateId(syncer::BOOKMARKS, | 97 const string id = FakeServerEntity::CreateId(syncer::BOOKMARKS, |
97 base::GenerateGUID()); | 98 base::GenerateGUID()); |
98 | 99 |
99 return make_scoped_ptr<FakeServerEntity>( | 100 return base::WrapUnique<FakeServerEntity>(new BookmarkEntity( |
100 new BookmarkEntity(id, | 101 id, kUnusedVersion, title_, originator_cache_guid_, |
101 kUnusedVersion, | 102 originator_client_item_id_, unique_position, entity_specifics, is_folder, |
102 title_, | 103 parent_id_, kDefaultTime, kDefaultTime)); |
103 originator_cache_guid_, | |
104 originator_client_item_id_, | |
105 unique_position, | |
106 entity_specifics, | |
107 is_folder, | |
108 parent_id_, | |
109 kDefaultTime, | |
110 kDefaultTime)); | |
111 } | 104 } |
112 | 105 |
113 } // namespace fake_server | 106 } // namespace fake_server |
OLD | NEW |