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

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

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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 "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 <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/guid.h" 12 #include "base/guid.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "sync/internal_api/public/base/model_type.h" 15 #include "components/sync/base/model_type.h"
16 #include "sync/internal_api/public/base/unique_position.h" 16 #include "components/sync/base/time.h"
17 #include "sync/protocol/sync.pb.h" 17 #include "components/sync/base/unique_position.h"
18 #include "sync/syncable/syncable_util.h" 18 #include "components/sync/protocol/sync.pb.h"
19 #include "sync/test/fake_server/bookmark_entity.h" 19 #include "components/sync/syncable/syncable_util.h"
20 #include "sync/test/fake_server/fake_server_entity.h" 20 #include "components/sync/test/fake_server/bookmark_entity.h"
21 #include "sync/util/time.h" 21 #include "components/sync/test/fake_server/fake_server_entity.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 using std::string; 24 using std::string;
25 25
26 using syncer::syncable::GenerateSyncableBookmarkHash; 26 using syncer::syncable::GenerateSyncableBookmarkHash;
27 27
28 // A version must be passed when creating a FakeServerEntity, but this value 28 // A version must be passed when creating a FakeServerEntity, but this value
29 // is overrideen immediately when saving the entity in FakeServer. 29 // is overrideen immediately when saving the entity in FakeServer.
30 const int64_t kUnusedVersion = 0L; 30 const int64_t kUnusedVersion = 0L;
31 31
32 // Default time (creation and last modified) used when creating entities. 32 // Default time (creation and last modified) used when creating entities.
33 const int64_t kDefaultTime = 1234L; 33 const int64_t kDefaultTime = 1234L;
34 34
35 namespace fake_server { 35 namespace fake_server {
36 36
37 BookmarkEntityBuilder::BookmarkEntityBuilder( 37 BookmarkEntityBuilder::BookmarkEntityBuilder(
38 const string& title, 38 const string& title,
39 const string& originator_cache_guid, 39 const string& originator_cache_guid,
40 const string& originator_client_item_id) 40 const string& originator_client_item_id)
41 : title_(title), 41 : title_(title),
42 originator_cache_guid_(originator_cache_guid), 42 originator_cache_guid_(originator_cache_guid),
43 originator_client_item_id_(originator_client_item_id) { 43 originator_client_item_id_(originator_client_item_id) {}
44 }
45 44
46 BookmarkEntityBuilder::BookmarkEntityBuilder( 45 BookmarkEntityBuilder::BookmarkEntityBuilder(
47 const BookmarkEntityBuilder& other) = default; 46 const BookmarkEntityBuilder& other) = default;
48 47
49 BookmarkEntityBuilder::~BookmarkEntityBuilder() { 48 BookmarkEntityBuilder::~BookmarkEntityBuilder() {}
50 }
51 49
52 void BookmarkEntityBuilder::SetParentId(const std::string& parent_id) { 50 void BookmarkEntityBuilder::SetParentId(const std::string& parent_id) {
53 parent_id_ = parent_id; 51 parent_id_ = parent_id;
54 } 52 }
55 53
56 std::unique_ptr<FakeServerEntity> BookmarkEntityBuilder::BuildBookmark( 54 std::unique_ptr<FakeServerEntity> BookmarkEntityBuilder::BuildBookmark(
57 const GURL& url) { 55 const GURL& url) {
58 if (!url.is_valid()) { 56 if (!url.is_valid()) {
59 return base::WrapUnique<FakeServerEntity>(NULL); 57 return base::WrapUnique<FakeServerEntity>(NULL);
60 } 58 }
(...skipping 18 matching lines...) Expand all
79 77
80 return entity_specifics; 78 return entity_specifics;
81 } 79 }
82 80
83 std::unique_ptr<FakeServerEntity> BookmarkEntityBuilder::Build( 81 std::unique_ptr<FakeServerEntity> BookmarkEntityBuilder::Build(
84 const sync_pb::EntitySpecifics& entity_specifics, 82 const sync_pb::EntitySpecifics& entity_specifics,
85 bool is_folder) { 83 bool is_folder) {
86 sync_pb::UniquePosition unique_position; 84 sync_pb::UniquePosition unique_position;
87 // TODO(pvalenzuela): Allow caller customization of the position integer. 85 // TODO(pvalenzuela): Allow caller customization of the position integer.
88 const string suffix = GenerateSyncableBookmarkHash( 86 const string suffix = GenerateSyncableBookmarkHash(
89 originator_cache_guid_, 87 originator_cache_guid_, originator_client_item_id_);
90 originator_client_item_id_);
91 syncer::UniquePosition::FromInt64(0, suffix).ToProto(&unique_position); 88 syncer::UniquePosition::FromInt64(0, suffix).ToProto(&unique_position);
92 89
93 if (parent_id_.empty()) { 90 if (parent_id_.empty()) {
94 parent_id_ = FakeServerEntity::CreateId(syncer::BOOKMARKS, "bookmark_bar"); 91 parent_id_ = FakeServerEntity::CreateId(syncer::BOOKMARKS, "bookmark_bar");
95 } 92 }
96 93
97 const string id = FakeServerEntity::CreateId(syncer::BOOKMARKS, 94 const string id =
98 base::GenerateGUID()); 95 FakeServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID());
99 96
100 return base::WrapUnique<FakeServerEntity>(new BookmarkEntity( 97 return base::WrapUnique<FakeServerEntity>(new BookmarkEntity(
101 id, kUnusedVersion, title_, originator_cache_guid_, 98 id, kUnusedVersion, title_, originator_cache_guid_,
102 originator_client_item_id_, unique_position, entity_specifics, is_folder, 99 originator_client_item_id_, unique_position, entity_specifics, is_folder,
103 parent_id_, kDefaultTime, kDefaultTime)); 100 parent_id_, kDefaultTime, kDefaultTime));
104 } 101 }
105 102
106 } // namespace fake_server 103 } // namespace fake_server
OLDNEW
« no previous file with comments | « components/sync/test/fake_server/bookmark_entity_builder.h ('k') | components/sync/test/fake_server/entity_builder_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698