Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: components/sync/test/fake_server/bookmark_entity_builder.cc

Issue 2969643002: Reland - Replace FakeServer's implementation with LoopbackServer invocations. (Closed)
Patch Set: Rebased on master. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
15 #include "components/sync/protocol/sync.pb.h" 16 #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;
20 21
21 // A version must be passed when creating a FakeServerEntity, but this value 22 // A version must be passed when creating a LoopbackServerEntity, but this value
22 // is overrideen immediately when saving the entity in FakeServer. 23 // is overrideen immediately when saving the entity in FakeServer.
23 const int64_t kUnusedVersion = 0L; 24 const int64_t kUnusedVersion = 0L;
24 25
25 // Default time (creation and last modified) used when creating entities. 26 // Default time (creation and last modified) used when creating entities.
26 const int64_t kDefaultTime = 1234L; 27 const int64_t kDefaultTime = 1234L;
27 28
28 namespace fake_server { 29 namespace fake_server {
29 30
30 BookmarkEntityBuilder::BookmarkEntityBuilder( 31 BookmarkEntityBuilder::BookmarkEntityBuilder(
31 const string& title, 32 const string& title,
32 const string& originator_cache_guid, 33 const string& originator_cache_guid,
33 const string& originator_client_item_id) 34 const string& originator_client_item_id)
34 : title_(title), 35 : title_(title),
35 originator_cache_guid_(originator_cache_guid), 36 originator_cache_guid_(originator_cache_guid),
36 originator_client_item_id_(originator_client_item_id) {} 37 originator_client_item_id_(originator_client_item_id) {}
37 38
38 BookmarkEntityBuilder::BookmarkEntityBuilder( 39 BookmarkEntityBuilder::BookmarkEntityBuilder(
39 const BookmarkEntityBuilder& other) = default; 40 const BookmarkEntityBuilder& other) = default;
40 41
41 BookmarkEntityBuilder::~BookmarkEntityBuilder() {} 42 BookmarkEntityBuilder::~BookmarkEntityBuilder() {}
42 43
43 void BookmarkEntityBuilder::SetParentId(const std::string& parent_id) { 44 void BookmarkEntityBuilder::SetParentId(const std::string& parent_id) {
44 parent_id_ = parent_id; 45 parent_id_ = parent_id;
45 } 46 }
46 47
47 std::unique_ptr<FakeServerEntity> BookmarkEntityBuilder::BuildBookmark( 48 std::unique_ptr<LoopbackServerEntity> BookmarkEntityBuilder::BuildBookmark(
48 const GURL& url) { 49 const GURL& url) {
49 if (!url.is_valid()) { 50 if (!url.is_valid()) {
50 return base::WrapUnique<FakeServerEntity>(nullptr); 51 return base::WrapUnique<LoopbackServerEntity>(nullptr);
51 } 52 }
52 53
53 sync_pb::EntitySpecifics entity_specifics = CreateBaseEntitySpecifics(); 54 sync_pb::EntitySpecifics entity_specifics = CreateBaseEntitySpecifics();
54 entity_specifics.mutable_bookmark()->set_url(url.spec()); 55 entity_specifics.mutable_bookmark()->set_url(url.spec());
55 const bool kIsNotFolder = false; 56 const bool kIsNotFolder = false;
56 return Build(entity_specifics, kIsNotFolder); 57 return Build(entity_specifics, kIsNotFolder);
57 } 58 }
58 59
59 std::unique_ptr<FakeServerEntity> BookmarkEntityBuilder::BuildFolder() { 60 std::unique_ptr<LoopbackServerEntity> BookmarkEntityBuilder::BuildFolder() {
60 const bool kIsFolder = true; 61 const bool kIsFolder = true;
61 return Build(CreateBaseEntitySpecifics(), kIsFolder); 62 return Build(CreateBaseEntitySpecifics(), kIsFolder);
62 } 63 }
63 64
64 sync_pb::EntitySpecifics BookmarkEntityBuilder::CreateBaseEntitySpecifics() 65 sync_pb::EntitySpecifics BookmarkEntityBuilder::CreateBaseEntitySpecifics()
65 const { 66 const {
66 sync_pb::EntitySpecifics entity_specifics; 67 sync_pb::EntitySpecifics entity_specifics;
67 sync_pb::BookmarkSpecifics* bookmark_specifics = 68 sync_pb::BookmarkSpecifics* bookmark_specifics =
68 entity_specifics.mutable_bookmark(); 69 entity_specifics.mutable_bookmark();
69 bookmark_specifics->set_title(title_); 70 bookmark_specifics->set_title(title_);
70 71
71 return entity_specifics; 72 return entity_specifics;
72 } 73 }
73 74
74 std::unique_ptr<FakeServerEntity> BookmarkEntityBuilder::Build( 75 std::unique_ptr<LoopbackServerEntity> BookmarkEntityBuilder::Build(
75 const sync_pb::EntitySpecifics& entity_specifics, 76 const sync_pb::EntitySpecifics& entity_specifics,
76 bool is_folder) { 77 bool is_folder) {
77 sync_pb::UniquePosition unique_position; 78 sync_pb::UniquePosition unique_position;
78 // TODO(pvalenzuela): Allow caller customization of the position integer. 79 // TODO(pvalenzuela): Allow caller customization of the position integer.
79 const string suffix = GenerateSyncableBookmarkHash( 80 const string suffix = GenerateSyncableBookmarkHash(
80 originator_cache_guid_, originator_client_item_id_); 81 originator_cache_guid_, originator_client_item_id_);
81 syncer::UniquePosition::FromInt64(0, suffix).ToProto(&unique_position); 82 syncer::UniquePosition::FromInt64(0, suffix).ToProto(&unique_position);
82 83
83 if (parent_id_.empty()) { 84 if (parent_id_.empty()) {
84 parent_id_ = FakeServerEntity::CreateId(syncer::BOOKMARKS, "bookmark_bar"); 85 parent_id_ =
86 LoopbackServerEntity::CreateId(syncer::BOOKMARKS, "bookmark_bar");
85 } 87 }
86 88
87 const string id = 89 const string id =
88 FakeServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID()); 90 LoopbackServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID());
89 91
90 return base::WrapUnique<FakeServerEntity>(new BookmarkEntity( 92 return base::WrapUnique<LoopbackServerEntity>(
91 id, kUnusedVersion, title_, originator_cache_guid_, 93 new syncer::PersistentBookmarkEntity(
92 originator_client_item_id_, unique_position, entity_specifics, is_folder, 94 id, kUnusedVersion, title_, originator_cache_guid_,
93 parent_id_, kDefaultTime, kDefaultTime)); 95 originator_client_item_id_, unique_position, entity_specifics,
96 is_folder, parent_id_, kDefaultTime, kDefaultTime));
94 } 97 }
95 98
96 } // namespace fake_server 99 } // namespace fake_server
OLDNEW
« no previous file with comments | « components/sync/test/fake_server/bookmark_entity_builder.h ('k') | components/sync/test/fake_server/fake_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698