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

Side by Side Diff: components/sync/engine_impl/net/loopback_server/bookmark_entity.cc

Issue 2106743002: WIP: Local sync only... (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix after rebase. Created 4 years, 2 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.h" 5 #include "components/sync/engine_impl/net/loopback_server/bookmark_entity.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 "components/sync/base/model_type.h" 13 #include "components/sync/base/model_type.h"
14 #include "components/sync/engine_impl/net/loopback_server/loopback_server_entity .h"
13 #include "components/sync/protocol/sync.pb.h" 15 #include "components/sync/protocol/sync.pb.h"
14 #include "components/sync/test/fake_server/fake_server_entity.h"
15 16
16 using std::string; 17 using std::string;
17 18
18 namespace fake_server { 19 namespace syncer {
19 20
20 namespace { 21 namespace {
21 22
22 // Returns true if and only if |client_entity| is a bookmark. 23 // Returns true if and only if |client_entity| is a bookmark.
23 bool IsBookmark(const sync_pb::SyncEntity& client_entity) { 24 bool IsBookmark(const sync_pb::SyncEntity& client_entity) {
24 return syncer::GetModelType(client_entity) == syncer::BOOKMARKS; 25 return syncer::GetModelType(client_entity) == syncer::BOOKMARKS;
25 } 26 }
26 27
27 } // namespace 28 } // namespace
28 29
29 BookmarkEntity::~BookmarkEntity() {} 30 BookmarkEntity::~BookmarkEntity() { }
30 31
31 // static 32 // static
32 std::unique_ptr<FakeServerEntity> BookmarkEntity::CreateNew( 33 std::unique_ptr<LoopbackServerEntity> BookmarkEntity::CreateNew(
33 const sync_pb::SyncEntity& client_entity, 34 const sync_pb::SyncEntity& client_entity,
34 const string& parent_id, 35 const string& parent_id,
35 const string& client_guid) { 36 const string& client_guid) {
36 CHECK(client_entity.version() == 0) << "New entities must have version = 0."; 37 CHECK(client_entity.version() == 0) << "New entities must have version = 0.";
37 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; 38 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark.";
38 39
39 const string id = 40 const string id =
40 FakeServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID()); 41 LoopbackServerEntity::CreateId(syncer::BOOKMARKS, base::GenerateGUID());
41 const string originator_cache_guid = client_guid; 42 const string originator_cache_guid = client_guid;
42 const string originator_client_item_id = client_entity.id_string(); 43 const string originator_client_item_id = client_entity.id_string();
43 44
44 return std::unique_ptr<FakeServerEntity>(new BookmarkEntity( 45 return std::unique_ptr<LoopbackServerEntity>(new BookmarkEntity(
45 id, client_entity.version(), client_entity.name(), originator_cache_guid, 46 id, 0, client_entity.name(), originator_cache_guid,
46 originator_client_item_id, client_entity.unique_position(), 47 originator_client_item_id, client_entity.unique_position(),
47 client_entity.specifics(), client_entity.folder(), parent_id, 48 client_entity.specifics(), client_entity.folder(), parent_id,
48 client_entity.ctime(), client_entity.mtime())); 49 client_entity.ctime(), client_entity.mtime()));
49 } 50 }
50 51
51 // static 52 // static
52 std::unique_ptr<FakeServerEntity> BookmarkEntity::CreateUpdatedVersion( 53 std::unique_ptr<LoopbackServerEntity> BookmarkEntity::CreateUpdatedVersion(
53 const sync_pb::SyncEntity& client_entity, 54 const sync_pb::SyncEntity& client_entity,
54 const FakeServerEntity& current_server_entity, 55 const LoopbackServerEntity& current_server_entity,
55 const string& parent_id) { 56 const string& parent_id) {
56 CHECK(client_entity.version() != 0) << "Existing entities must not have a " 57 CHECK(client_entity.version() != 0) << "Existing entities must not have a "
57 << "version = 0."; 58 << "version = 0.";
58 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark."; 59 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark.";
59 60
60 const BookmarkEntity& current_bookmark_entity = 61 const BookmarkEntity& current_bookmark_entity =
61 static_cast<const BookmarkEntity&>(current_server_entity); 62 static_cast<const BookmarkEntity&>(current_server_entity);
62 const string originator_cache_guid = 63 const string originator_cache_guid =
63 current_bookmark_entity.originator_cache_guid_; 64 current_bookmark_entity.originator_cache_guid_;
64 const string originator_client_item_id = 65 const string originator_client_item_id =
65 current_bookmark_entity.originator_client_item_id_; 66 current_bookmark_entity.originator_client_item_id_;
66 67
67 return std::unique_ptr<FakeServerEntity>(new BookmarkEntity( 68 return std::unique_ptr<LoopbackServerEntity>(new BookmarkEntity(
68 client_entity.id_string(), client_entity.version(), client_entity.name(), 69 client_entity.id_string(), 0, client_entity.name(),
69 originator_cache_guid, originator_client_item_id, 70 originator_cache_guid, originator_client_item_id,
70 client_entity.unique_position(), client_entity.specifics(), 71 client_entity.unique_position(), client_entity.specifics(),
71 client_entity.folder(), parent_id, client_entity.ctime(), 72 client_entity.folder(), parent_id, client_entity.ctime(),
72 client_entity.mtime())); 73 client_entity.mtime()));
73 } 74 }
74 75
76 // static
77 std::unique_ptr<LoopbackServerEntity> BookmarkEntity::CreateFromEntity(
78 const sync_pb::SyncEntity& client_entity) {
79 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark.";
80
81 return std::unique_ptr<LoopbackServerEntity>(new BookmarkEntity(
82 client_entity.id_string(), client_entity.version(), client_entity.name(),
83 client_entity.originator_cache_guid(),
84 client_entity.originator_client_item_id(),
85 client_entity.unique_position(), client_entity.specifics(),
86 client_entity.folder(), client_entity.parent_id_string(),
87 client_entity.ctime(), client_entity.mtime()));
88 }
75 BookmarkEntity::BookmarkEntity(const string& id, 89 BookmarkEntity::BookmarkEntity(const string& id,
76 int64_t version, 90 int64_t version,
77 const string& name, 91 const string& name,
78 const string& originator_cache_guid, 92 const string& originator_cache_guid,
79 const string& originator_client_item_id, 93 const string& originator_client_item_id,
80 const sync_pb::UniquePosition& unique_position, 94 const sync_pb::UniquePosition& unique_position,
81 const sync_pb::EntitySpecifics& specifics, 95 const sync_pb::EntitySpecifics& specifics,
82 bool is_folder, 96 bool is_folder,
83 const string& parent_id, 97 const string& parent_id,
84 int64_t creation_time, 98 int64_t creation_time,
85 int64_t last_modified_time) 99 int64_t last_modified_time)
86 : FakeServerEntity(id, string(), syncer::BOOKMARKS, version, name), 100 : LoopbackServerEntity(id, syncer::BOOKMARKS, version, name),
87 originator_cache_guid_(originator_cache_guid), 101 originator_cache_guid_(originator_cache_guid),
88 originator_client_item_id_(originator_client_item_id), 102 originator_client_item_id_(originator_client_item_id),
89 unique_position_(unique_position), 103 unique_position_(unique_position),
90 is_folder_(is_folder), 104 is_folder_(is_folder),
91 parent_id_(parent_id), 105 parent_id_(parent_id),
92 creation_time_(creation_time), 106 creation_time_(creation_time),
93 last_modified_time_(last_modified_time) { 107 last_modified_time_(last_modified_time) {
94 SetSpecifics(specifics); 108 SetSpecifics(specifics);
95 } 109 }
96 110
97 void BookmarkEntity::SetParentId(const string& parent_id) { 111 void BookmarkEntity::SetParentId(const string& parent_id) {
98 parent_id_ = parent_id; 112 parent_id_ = parent_id;
99 } 113 }
100 114
101 bool BookmarkEntity::RequiresParentId() const { 115 bool BookmarkEntity::RequiresParentId() const {
102 // Bookmarks are stored as a hierarchy. All bookmarks must have a parent ID. 116 // Bookmarks are stored as a hierarchy. All bookmarks must have a parent ID.
103 return true; 117 return true;
104 } 118 }
105 119
106 string BookmarkEntity::GetParentId() const { 120 string BookmarkEntity::GetParentId() const {
107 return parent_id_; 121 return parent_id_;
108 } 122 }
109 123
110 void BookmarkEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const { 124 void BookmarkEntity::SerializeAsProto(sync_pb::SyncEntity* proto) const {
111 FakeServerEntity::SerializeBaseProtoFields(proto); 125 LoopbackServerEntity::SerializeBaseProtoFields(proto);
112 126
113 proto->set_originator_cache_guid(originator_cache_guid_); 127 proto->set_originator_cache_guid(originator_cache_guid_);
114 proto->set_originator_client_item_id(originator_client_item_id_); 128 proto->set_originator_client_item_id(originator_client_item_id_);
115 129
116 proto->set_ctime(creation_time_); 130 proto->set_ctime(creation_time_);
117 proto->set_mtime(last_modified_time_); 131 proto->set_mtime(last_modified_time_);
118 132
119 sync_pb::UniquePosition* unique_position = proto->mutable_unique_position(); 133 sync_pb::UniquePosition* unique_position = proto->mutable_unique_position();
120 unique_position->CopyFrom(unique_position_); 134 unique_position->CopyFrom(unique_position_);
121 } 135 }
122 136
123 bool BookmarkEntity::IsFolder() const { 137 bool BookmarkEntity::IsFolder() const {
124 return is_folder_; 138 return is_folder_;
125 } 139 }
126 140
127 } // namespace fake_server 141 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698