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

Side by Side Diff: sync/test/fake_server/bookmark_entity.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
(Empty)
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.
4
5 #include "sync/test/fake_server/bookmark_entity.h"
6
7 #include <stdint.h>
8
9 #include <string>
10
11 #include "base/guid.h"
12 #include "sync/internal_api/public/base/model_type.h"
13 #include "sync/protocol/sync.pb.h"
14 #include "sync/test/fake_server/fake_server_entity.h"
15
16 using std::string;
17
18 namespace fake_server {
19
20 namespace {
21
22 // Returns true if and only if |client_entity| is a bookmark.
23 bool IsBookmark(const sync_pb::SyncEntity& client_entity) {
24 return syncer::GetModelType(client_entity) == syncer::BOOKMARKS;
25 }
26
27 } // namespace
28
29 BookmarkEntity::~BookmarkEntity() { }
30
31 // static
32 std::unique_ptr<FakeServerEntity> BookmarkEntity::CreateNew(
33 const sync_pb::SyncEntity& client_entity,
34 const string& parent_id,
35 const string& client_guid) {
36 CHECK(client_entity.version() == 0) << "New entities must have version = 0.";
37 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark.";
38
39 const string id =
40 FakeServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID());
41 const string originator_cache_guid = client_guid;
42 const string originator_client_item_id = client_entity.id_string();
43
44 return std::unique_ptr<FakeServerEntity>(new BookmarkEntity(
45 id, client_entity.version(), client_entity.name(), originator_cache_guid,
46 originator_client_item_id, client_entity.unique_position(),
47 client_entity.specifics(), client_entity.folder(), parent_id,
48 client_entity.ctime(), client_entity.mtime()));
49 }
50
51 // static
52 std::unique_ptr<FakeServerEntity> BookmarkEntity::CreateUpdatedVersion(
53 const sync_pb::SyncEntity& client_entity,
54 const FakeServerEntity& current_server_entity,
55 const string& parent_id) {
56 CHECK(client_entity.version() != 0) << "Existing entities must not have a "
57 << "version = 0.";
58 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark.";
59
60 const BookmarkEntity& current_bookmark_entity =
61 static_cast<const BookmarkEntity&>(current_server_entity);
62 const string originator_cache_guid =
63 current_bookmark_entity.originator_cache_guid_;
64 const string originator_client_item_id =
65 current_bookmark_entity.originator_client_item_id_;
66
67 return std::unique_ptr<FakeServerEntity>(new BookmarkEntity(
68 client_entity.id_string(), client_entity.version(), client_entity.name(),
69 originator_cache_guid, originator_client_item_id,
70 client_entity.unique_position(), client_entity.specifics(),
71 client_entity.folder(), parent_id, client_entity.ctime(),
72 client_entity.mtime()));
73 }
74
75 BookmarkEntity::BookmarkEntity(const string& id,
76 int64_t version,
77 const string& name,
78 const string& originator_cache_guid,
79 const string& originator_client_item_id,
80 const sync_pb::UniquePosition& unique_position,
81 const sync_pb::EntitySpecifics& specifics,
82 bool is_folder,
83 const string& parent_id,
84 int64_t creation_time,
85 int64_t last_modified_time)
86 : FakeServerEntity(id, syncer::BOOKMARKS, version, name),
87 originator_cache_guid_(originator_cache_guid),
88 originator_client_item_id_(originator_client_item_id),
89 unique_position_(unique_position),
90 is_folder_(is_folder),
91 parent_id_(parent_id),
92 creation_time_(creation_time),
93 last_modified_time_(last_modified_time) {
94 SetSpecifics(specifics);
95 }
96
97 void BookmarkEntity::SetParentId(const string& parent_id) {
98 parent_id_ = parent_id;
99 }
100
101 bool BookmarkEntity::RequiresParentId() const {
102 // Bookmarks are stored as a hierarchy. All bookmarks must have a parent ID.
103 return true;
104 }
105
106 string BookmarkEntity::GetParentId() const {
107 return parent_id_;
108 }
109
110 void BookmarkEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const {
111 FakeServerEntity::SerializeBaseProtoFields(proto);
112
113 proto->set_originator_cache_guid(originator_cache_guid_);
114 proto->set_originator_client_item_id(originator_client_item_id_);
115
116 proto->set_ctime(creation_time_);
117 proto->set_mtime(last_modified_time_);
118
119 sync_pb::UniquePosition* unique_position = proto->mutable_unique_position();
120 unique_position->CopyFrom(unique_position_);
121 }
122
123 bool BookmarkEntity::IsFolder() const {
124 return is_folder_;
125 }
126
127 } // namespace fake_server
OLDNEW
« no previous file with comments | « sync/test/fake_server/bookmark_entity.h ('k') | sync/test/fake_server/bookmark_entity_builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698