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
3 // found in the LICENSE file.
5 #include "sync/test/fake_server/bookmark_entity_builder.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "sync/internal_api/public/base/model_type.h"
13 #include "sync/internal_api/public/base/unique_position.h"
14 #include "sync/protocol/sync.pb.h"
15 #include "sync/syncable/syncable_util.h"
16 #include "sync/test/fake_server/bookmark_entity.h"
17 #include "sync/test/fake_server/fake_server_entity.h"
18 #include "sync/util/time.h"
23 using syncer::syncable::GenerateSyncableBookmarkHash
;
25 // A version must be passed when creating a FakeServerEntity, but this value
26 // is overrideen immediately when saving the entity in FakeServer.
27 const int64 kUnusedVersion
= 0L;
29 // Default time (creation and last modified) used when creating entities.
30 const int64 kDefaultTime
= 1234L;
32 namespace fake_server
{
34 BookmarkEntityBuilder::BookmarkEntityBuilder(
37 const string
& originator_cache_guid
,
38 const string
& originator_client_item_id
)
39 : EntityBuilder(syncer::BOOKMARKS
, title
),
41 originator_cache_guid_(originator_cache_guid
),
42 originator_client_item_id_(originator_client_item_id
) {
45 BookmarkEntityBuilder::~BookmarkEntityBuilder() {
48 void BookmarkEntityBuilder::SetParentId(const std::string
& parent_id
) {
49 parent_id_
= parent_id
;
52 scoped_ptr
<FakeServerEntity
> BookmarkEntityBuilder::Build() {
53 if (!url_
.is_valid()) {
54 return make_scoped_ptr
<FakeServerEntity
>(NULL
);
57 sync_pb::EntitySpecifics entity_specifics
;
58 sync_pb::BookmarkSpecifics
* bookmark_specifics
=
59 entity_specifics
.mutable_bookmark();
60 bookmark_specifics
->set_title(name_
);
61 bookmark_specifics
->set_url(url_
.spec());
63 sync_pb::UniquePosition unique_position
;
64 // TODO(pvalenzuela): Allow caller customization of the position integer.
65 string suffix
= GenerateSyncableBookmarkHash(originator_cache_guid_
,
66 originator_client_item_id_
);
67 syncer::UniquePosition::FromInt64(0, suffix
).ToProto(&unique_position
);
69 if (parent_id_
.empty()) {
70 parent_id_
= FakeServerEntity::CreateId(syncer::BOOKMARKS
, "bookmark_bar");
73 return make_scoped_ptr
<FakeServerEntity
>(
74 new BookmarkEntity(id_
,
77 originator_cache_guid_
,
78 originator_client_item_id_
,
81 // TODO(pvalenzuela): Support bookmark folders.
88 } // namespace fake_server