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

Side by Side Diff: components/sync/engine_impl/test_entry_factory.cc

Issue 2442583003: [Sync] Start implementation of migration for USS. (Closed)
Patch Set: Rebase. Created 4 years, 1 month 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/engine_impl/test_entry_factory.h" 5 #include "components/sync/engine_impl/test_entry_factory.h"
6 6
7 #include "components/sync/base/model_type.h"
7 #include "components/sync/syncable/directory.h" 8 #include "components/sync/syncable/directory.h"
8 #include "components/sync/syncable/entry.h" 9 #include "components/sync/syncable/entry.h"
10 #include "components/sync/syncable/model_neutral_mutable_entry.h"
9 #include "components/sync/syncable/mutable_entry.h" 11 #include "components/sync/syncable/mutable_entry.h"
10 #include "components/sync/syncable/syncable_id.h" 12 #include "components/sync/syncable/syncable_id.h"
13 #include "components/sync/syncable/syncable_model_neutral_write_transaction.h"
11 #include "components/sync/syncable/syncable_read_transaction.h" 14 #include "components/sync/syncable/syncable_read_transaction.h"
12 #include "components/sync/syncable/syncable_util.h" 15 #include "components/sync/syncable/syncable_util.h"
13 #include "components/sync/syncable/syncable_write_transaction.h" 16 #include "components/sync/syncable/syncable_write_transaction.h"
14 #include "components/sync/test/engine/test_id_factory.h" 17 #include "components/sync/test/engine/test_id_factory.h"
15 18
16 using std::string; 19 using std::string;
17 20
18 namespace syncer { 21 namespace syncer {
19 22
20 using syncable::Id; 23 using syncable::Id;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 137
135 entry.PutIsUnappliedUpdate(true); 138 entry.PutIsUnappliedUpdate(true);
136 entry.PutServerVersion(GetNextRevision()); 139 entry.PutServerVersion(GetNextRevision());
137 140
138 return metahandle; 141 return metahandle;
139 } 142 }
140 143
141 int64_t TestEntryFactory::CreateSyncedItem(const std::string& name, 144 int64_t TestEntryFactory::CreateSyncedItem(const std::string& name,
142 ModelType model_type, 145 ModelType model_type,
143 bool is_folder) { 146 bool is_folder) {
147 return CreateSyncedItem(name, model_type, is_folder,
148 sync_pb::EntitySpecifics());
149 }
150
151 int64_t TestEntryFactory::CreateSyncedItem(
152 const std::string& name,
153 ModelType model_type,
154 bool is_folder,
155 const sync_pb::EntitySpecifics& specifics) {
144 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); 156 WriteTransaction trans(FROM_HERE, UNITTEST, directory_);
145 157
146 syncable::Id parent_id(TestIdFactory::root()); 158 // Use the type root if it exists or the real root otherwise.
159 syncable::Entry root(&trans, syncable::GET_TYPE_ROOT, model_type);
160 syncable::Id parent_id = root.good() ? root.GetId() : TestIdFactory::root();
147 syncable::Id item_id(TestIdFactory::MakeServer(name)); 161 syncable::Id item_id(TestIdFactory::MakeServer(name));
148 int64_t version = GetNextRevision(); 162 int64_t version = GetNextRevision();
163 base::Time now = base::Time::Now();
149 164
150 MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name); 165 MutableEntry entry(&trans, syncable::CREATE, model_type, parent_id, name);
151 if (!entry.good()) { 166 if (!entry.good()) {
152 NOTREACHED(); 167 NOTREACHED();
153 return syncable::kInvalidMetaHandle; 168 return syncable::kInvalidMetaHandle;
154 } 169 }
155 170
156 entry.PutId(item_id); 171 entry.PutId(item_id);
172 entry.PutCtime(now);
173 entry.PutMtime(now);
174 entry.PutUniqueClientTag(syncable::GenerateSyncableHash(model_type, name));
157 entry.PutBaseVersion(version); 175 entry.PutBaseVersion(version);
158 entry.PutIsUnsynced(false); 176 entry.PutIsUnsynced(false);
159 entry.PutNonUniqueName(name); 177 entry.PutNonUniqueName(name);
160 entry.PutIsDir(is_folder); 178 entry.PutIsDir(is_folder);
161 entry.PutIsDel(false); 179 entry.PutIsDel(false);
162 entry.PutParentId(parent_id); 180 entry.PutParentId(parent_id);
163 181
164 entry.PutServerVersion(GetNextRevision()); 182 entry.PutServerCtime(now);
183 entry.PutServerMtime(now);
184 entry.PutServerVersion(version);
165 entry.PutIsUnappliedUpdate(false); 185 entry.PutIsUnappliedUpdate(false);
166 entry.PutServerNonUniqueName(name); 186 entry.PutServerNonUniqueName(name);
167 entry.PutServerParentId(parent_id); 187 entry.PutServerParentId(parent_id);
168 entry.PutServerIsDir(is_folder); 188 entry.PutServerIsDir(is_folder);
169 entry.PutServerIsDel(false); 189 entry.PutServerIsDel(false);
170 entry.PutServerSpecifics(entry.GetSpecifics()); 190
191 // Only rewrite the default specifics inside the entry (which have the model
192 // type marker already) if |specifics| actually contains data.
193 if (specifics.ByteSize() > 0) {
194 entry.PutSpecifics(specifics);
195 entry.PutServerSpecifics(specifics);
196 } else {
197 entry.PutServerSpecifics(entry.GetSpecifics());
198 }
171 199
172 return entry.GetMetahandle(); 200 return entry.GetMetahandle();
173 } 201 }
174 202
203 int64_t TestEntryFactory::CreateTypeRootNode(ModelType model_type) {
204 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, syncable::UNITTEST,
205 directory_);
206 sync_pb::EntitySpecifics specifics;
207 AddDefaultFieldValue(model_type, &specifics);
208 syncable::ModelNeutralMutableEntry entry(
209 &trans, syncable::CREATE_NEW_TYPE_ROOT, model_type);
210 DCHECK(entry.good());
211 entry.PutServerIsDir(true);
212 entry.PutUniqueServerTag(ModelTypeToRootTag(model_type));
213 return entry.GetMetahandle();
214 }
215
175 int64_t TestEntryFactory::CreateUnappliedRootNode(ModelType model_type) { 216 int64_t TestEntryFactory::CreateUnappliedRootNode(ModelType model_type) {
176 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory_); 217 syncable::WriteTransaction trans(FROM_HERE, syncable::UNITTEST, directory_);
177 sync_pb::EntitySpecifics specifics; 218 sync_pb::EntitySpecifics specifics;
178 AddDefaultFieldValue(model_type, &specifics); 219 AddDefaultFieldValue(model_type, &specifics);
179 syncable::Id node_id = TestIdFactory::MakeServer("xyz"); 220 syncable::Id node_id = TestIdFactory::MakeServer("xyz");
180 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, 221 syncable::MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM,
181 node_id); 222 node_id);
182 DCHECK(entry.good()); 223 DCHECK(entry.good());
183 // Make it look like sort of like a pending creation from the server. 224 // Make it look like sort of like a pending creation from the server.
184 // The SERVER_PARENT_ID and UNIQUE_CLIENT_TAG aren't quite right, but 225 // The SERVER_PARENT_ID and UNIQUE_CLIENT_TAG aren't quite right, but
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 return false; 337 return false;
297 } 338 }
298 return entry.GetIsUnappliedUpdate(); 339 return entry.GetIsUnappliedUpdate();
299 } 340 }
300 341
301 int64_t TestEntryFactory::GetNextRevision() { 342 int64_t TestEntryFactory::GetNextRevision() {
302 return next_revision_++; 343 return next_revision_++;
303 } 344 }
304 345
305 } // namespace syncer 346 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698