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

Side by Side Diff: sync/test/fake_server/bookmark_entity.cc

Issue 319823002: Remove redundant param from Sync FakeServer infra (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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.h" 5 #include "sync/test/fake_server/bookmark_entity.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
11 #include "sync/internal_api/public/base/model_type.h" 11 #include "sync/internal_api/public/base/model_type.h"
12 #include "sync/protocol/sync.pb.h" 12 #include "sync/protocol/sync.pb.h"
13 #include "sync/test/fake_server/fake_server_entity.h" 13 #include "sync/test/fake_server/fake_server_entity.h"
14 14
15 using std::string; 15 using std::string;
16 16
17 using syncer::ModelType; 17 namespace fake_server {
18 18
19 namespace fake_server { 19 namespace {
20
21 // Returns true if and only if |client_entity| is a bookmark.
22 bool IsBookmark(const sync_pb::SyncEntity& client_entity) {
23 return syncer::GetModelType(client_entity) == syncer::BOOKMARKS;
24 }
25
26 } // namespace
20 27
21 BookmarkEntity::~BookmarkEntity() { } 28 BookmarkEntity::~BookmarkEntity() { }
22 29
23 // static 30 // static
24 FakeServerEntity* BookmarkEntity::CreateNew( 31 FakeServerEntity* BookmarkEntity::CreateNew(
25 const sync_pb::SyncEntity& client_entity, 32 const sync_pb::SyncEntity& client_entity,
26 const string& parent_id, 33 const string& parent_id,
27 const string& client_guid) { 34 const string& client_guid) {
28 if (client_entity.version() != 0) { 35 CHECK(client_entity.version() == 0) << "New entities must have version = 0.";
29 return NULL; 36 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark.";
30 }
31 37
32 ModelType model_type = 38 string id = FakeServerEntity::CreateId(syncer::BOOKMARKS,
33 syncer::GetModelTypeFromSpecifics(client_entity.specifics()); 39 base::GenerateGUID());
34 string id = FakeServerEntity::CreateId(model_type, base::GenerateGUID());
35 string originator_cache_guid = client_guid; 40 string originator_cache_guid = client_guid;
36 string originator_client_item_id = client_entity.id_string(); 41 string originator_client_item_id = client_entity.id_string();
37 42
38 return new BookmarkEntity(id, 43 return new BookmarkEntity(id,
39 model_type,
40 client_entity.version(), 44 client_entity.version(),
41 client_entity.name(), 45 client_entity.name(),
42 originator_cache_guid, 46 originator_cache_guid,
43 originator_client_item_id, 47 originator_client_item_id,
44 client_entity.unique_position(), 48 client_entity.unique_position(),
45 client_entity.specifics(), 49 client_entity.specifics(),
46 client_entity.folder(), 50 client_entity.folder(),
47 parent_id, 51 parent_id,
48 client_entity.ctime(), 52 client_entity.ctime(),
49 client_entity.mtime()); 53 client_entity.mtime());
50 } 54 }
51 55
52 // static 56 // static
53 FakeServerEntity* BookmarkEntity::CreateUpdatedVersion( 57 FakeServerEntity* BookmarkEntity::CreateUpdatedVersion(
54 const sync_pb::SyncEntity& client_entity, 58 const sync_pb::SyncEntity& client_entity,
55 FakeServerEntity* current_server_entity, 59 FakeServerEntity* current_server_entity,
56 const string& parent_id) { 60 const string& parent_id) {
57 if (client_entity.version() == 0 || current_server_entity == NULL) { 61 CHECK(client_entity.version() != 0) << "Existing entities must not have a "
58 return NULL; 62 << "version = 0.";
59 } 63 CHECK(IsBookmark(client_entity)) << "The given entity must be a bookmark.";
60 64
61 BookmarkEntity* current_bookmark_entity = 65 BookmarkEntity* current_bookmark_entity =
62 static_cast<BookmarkEntity*>(current_server_entity); 66 static_cast<BookmarkEntity*>(current_server_entity);
63 string originator_cache_guid = 67 string originator_cache_guid =
64 current_bookmark_entity->originator_cache_guid_; 68 current_bookmark_entity->originator_cache_guid_;
65 string originator_client_item_id = 69 string originator_client_item_id =
66 current_bookmark_entity->originator_client_item_id_; 70 current_bookmark_entity->originator_client_item_id_;
67 ModelType model_type =
68 syncer::GetModelTypeFromSpecifics(client_entity.specifics());
69 71
70 return new BookmarkEntity(client_entity.id_string(), 72 return new BookmarkEntity(client_entity.id_string(),
71 model_type,
72 client_entity.version(), 73 client_entity.version(),
73 client_entity.name(), 74 client_entity.name(),
74 originator_cache_guid, 75 originator_cache_guid,
75 originator_client_item_id, 76 originator_client_item_id,
76 client_entity.unique_position(), 77 client_entity.unique_position(),
77 client_entity.specifics(), 78 client_entity.specifics(),
78 client_entity.folder(), 79 client_entity.folder(),
79 parent_id, 80 parent_id,
80 client_entity.ctime(), 81 client_entity.ctime(),
81 client_entity.mtime()); 82 client_entity.mtime());
82 } 83 }
83 84
84 BookmarkEntity::BookmarkEntity( 85 BookmarkEntity::BookmarkEntity(
85 const string& id, 86 const string& id,
86 const ModelType& model_type,
87 int64 version, 87 int64 version,
88 const string& name, 88 const string& name,
89 const string& originator_cache_guid, 89 const string& originator_cache_guid,
90 const string& originator_client_item_id, 90 const string& originator_client_item_id,
91 const sync_pb::UniquePosition& unique_position, 91 const sync_pb::UniquePosition& unique_position,
92 const sync_pb::EntitySpecifics& specifics, 92 const sync_pb::EntitySpecifics& specifics,
93 bool is_folder, 93 bool is_folder,
94 const string& parent_id, 94 const string& parent_id,
95 int64 creation_time, 95 int64 creation_time,
96 int64 last_modified_time) 96 int64 last_modified_time)
97 : FakeServerEntity(id, model_type, version, name), 97 : FakeServerEntity(id, syncer::BOOKMARKS, version, name),
98 originator_cache_guid_(originator_cache_guid), 98 originator_cache_guid_(originator_cache_guid),
99 originator_client_item_id_(originator_client_item_id), 99 originator_client_item_id_(originator_client_item_id),
100 unique_position_(unique_position), 100 unique_position_(unique_position),
101 specifics_(specifics), 101 specifics_(specifics),
102 is_folder_(is_folder), 102 is_folder_(is_folder),
103 parent_id_(parent_id), 103 parent_id_(parent_id),
104 creation_time_(creation_time), 104 creation_time_(creation_time),
105 last_modified_time_(last_modified_time) { } 105 last_modified_time_(last_modified_time) { }
106 106
107 string BookmarkEntity::GetParentId() const { 107 string BookmarkEntity::GetParentId() const {
(...skipping 23 matching lines...) Expand all
131 131
132 bool BookmarkEntity::IsDeleted() const { 132 bool BookmarkEntity::IsDeleted() const {
133 return false; 133 return false;
134 } 134 }
135 135
136 bool BookmarkEntity::IsFolder() const { 136 bool BookmarkEntity::IsFolder() const {
137 return is_folder_; 137 return is_folder_;
138 } 138 }
139 139
140 } // namespace fake_server 140 } // namespace fake_server
OLDNEW
« no previous file with comments | « sync/test/fake_server/bookmark_entity.h ('k') | sync/test/fake_server/bookmark_entity_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698