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

Side by Side Diff: sync/internal_api/test/test_entry_factory.cc

Issue 10905191: [Sync] Add keystore migration conflict support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add more comments Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "sync/internal_api/public/test/test_entry_factory.h" 5 #include "sync/internal_api/public/test/test_entry_factory.h"
6 6
7 #include "sync/syncable/directory.h" 7 #include "sync/syncable/directory.h"
8 #include "sync/syncable/entry.h"
8 #include "sync/syncable/mutable_entry.h" 9 #include "sync/syncable/mutable_entry.h"
10 #include "sync/syncable/read_transaction.h"
9 #include "sync/syncable/syncable_id.h" 11 #include "sync/syncable/syncable_id.h"
10 #include "sync/syncable/write_transaction.h" 12 #include "sync/syncable/write_transaction.h"
11 #include "sync/test/engine/test_id_factory.h" 13 #include "sync/test/engine/test_id_factory.h"
12 14
13 using std::string; 15 using std::string;
14 16
15 namespace syncer { 17 namespace syncer {
16 18
17 using syncable::Id; 19 using syncable::Id;
18 using syncable::MutableEntry; 20 using syncable::MutableEntry;
(...skipping 16 matching lines...) Expand all
35 DCHECK(entry.good()); 37 DCHECK(entry.good());
36 entry.Put(syncable::SERVER_VERSION, GetNextRevision()); 38 entry.Put(syncable::SERVER_VERSION, GetNextRevision());
37 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); 39 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
38 40
39 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); 41 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id);
40 entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id)); 42 entry.Put(syncable::SERVER_PARENT_ID, Id::CreateFromServerId(parent_id));
41 entry.Put(syncable::SERVER_IS_DIR, true); 43 entry.Put(syncable::SERVER_IS_DIR, true);
42 entry.Put(syncable::SERVER_SPECIFICS, specifics); 44 entry.Put(syncable::SERVER_SPECIFICS, specifics);
43 } 45 }
44 46
45 void TestEntryFactory::CreateUnappliedNewItem( 47 int64 TestEntryFactory::CreateUnappliedNewItem(
46 const string& item_id, 48 const string& item_id,
47 const sync_pb::EntitySpecifics& specifics, 49 const sync_pb::EntitySpecifics& specifics,
48 bool is_unique) { 50 bool is_unique) {
49 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); 51 WriteTransaction trans(FROM_HERE, UNITTEST, directory_);
50 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM, 52 MutableEntry entry(&trans, syncable::CREATE_NEW_UPDATE_ITEM,
51 Id::CreateFromServerId(item_id)); 53 Id::CreateFromServerId(item_id));
52 DCHECK(entry.good()); 54 DCHECK(entry.good());
53 entry.Put(syncable::SERVER_VERSION, GetNextRevision()); 55 entry.Put(syncable::SERVER_VERSION, GetNextRevision());
54 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); 56 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
55 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id); 57 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, item_id);
56 entry.Put(syncable::SERVER_PARENT_ID, syncable::GetNullId()); 58 entry.Put(syncable::SERVER_PARENT_ID, syncable::GetNullId());
57 entry.Put(syncable::SERVER_IS_DIR, false); 59 entry.Put(syncable::SERVER_IS_DIR, false);
58 entry.Put(syncable::SERVER_SPECIFICS, specifics); 60 entry.Put(syncable::SERVER_SPECIFICS, specifics);
59 if (is_unique) // For top-level nodes. 61 if (is_unique) // For top-level nodes.
60 entry.Put(syncable::UNIQUE_SERVER_TAG, item_id); 62 entry.Put(syncable::UNIQUE_SERVER_TAG, item_id);
63 return entry.Get(syncable::META_HANDLE);
61 } 64 }
62 65
63 void TestEntryFactory::CreateUnsyncedItem( 66 void TestEntryFactory::CreateUnsyncedItem(
64 const Id& item_id, 67 const Id& item_id,
65 const Id& parent_id, 68 const Id& parent_id,
66 const string& name, 69 const string& name,
67 bool is_folder, 70 bool is_folder,
68 ModelType model_type, 71 ModelType model_type,
69 int64* metahandle_out) { 72 int64* metahandle_out) {
70 WriteTransaction trans(FROM_HERE, UNITTEST, directory_); 73 WriteTransaction trans(FROM_HERE, UNITTEST, directory_);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, "X"); 155 entry.Put(syncable::SERVER_NON_UNIQUE_NAME, "X");
153 entry.Put(syncable::SERVER_PARENT_ID, TestIdFactory::MakeServer("Y")); 156 entry.Put(syncable::SERVER_PARENT_ID, TestIdFactory::MakeServer("Y"));
154 entry.Put(syncable::SERVER_IS_DIR, is_folder); 157 entry.Put(syncable::SERVER_IS_DIR, is_folder);
155 entry.Put(syncable::SERVER_IS_DEL, false); 158 entry.Put(syncable::SERVER_IS_DEL, false);
156 entry.Put(syncable::SERVER_SPECIFICS, default_specifics); 159 entry.Put(syncable::SERVER_SPECIFICS, default_specifics);
157 entry.Put(syncable::SERVER_PARENT_ID, parent_id); 160 entry.Put(syncable::SERVER_PARENT_ID, parent_id);
158 161
159 return entry.Get(syncable::META_HANDLE); 162 return entry.Get(syncable::META_HANDLE);
160 } 163 }
161 164
165 bool TestEntryFactory::SetSpecificsForItem(
166 int64 meta_handle,
167 SpecificsType specifics_type,
168 const sync_pb::EntitySpecifics specifics) {
169 WriteTransaction trans(FROM_HERE, UNITTEST, directory_);
170 MutableEntry entry(&trans, syncable::GET_BY_HANDLE, meta_handle);
171 if (!entry.good()) {
172 return false;
173 }
174 if (specifics_type == SERVER_SPECIFICS) {
175 entry.Put(syncable::SERVER_SPECIFICS, specifics);
176 entry.Put(syncable::IS_UNAPPLIED_UPDATE, true);
177 } else {
178 entry.Put(syncable::SPECIFICS, specifics);
179 entry.Put(syncable::IS_UNSYNCED, true);
180 }
181 return true;
182 }
183
184 const sync_pb::EntitySpecifics& TestEntryFactory::GetSpecificsForItem(
185 int64 meta_handle,
186 SpecificsType specifics_type) const {
187 syncable::ReadTransaction trans(FROM_HERE, directory_);
188 syncable::Entry entry(&trans, syncable::GET_BY_HANDLE, meta_handle);
189 if (!entry.good()) {
rlarocque 2012/09/13 22:10:51 DCHECK() instead?
Nicolas Zea 2012/09/13 22:50:14 Done.
190 NOTREACHED();
191 }
192 if (specifics_type == SERVER_SPECIFICS) {
rlarocque 2012/09/13 22:10:51 Whereas the current definition allows you to reuse
Nicolas Zea 2012/09/13 22:50:14 Done (same for SetSpecificsForItem).
193 return entry.Get(syncable::SERVER_SPECIFICS);
194 } else {
195 return entry.Get(syncable::SPECIFICS);
196 }
197 }
198
199 bool TestEntryFactory::GetIsUnsyncedForItem(int64 meta_handle) const {
200 syncable::ReadTransaction trans(FROM_HERE, directory_);
201 syncable::Entry entry(&trans, syncable::GET_BY_HANDLE, meta_handle);
202 if (!entry.good()) {
203 NOTREACHED();
204 return false;
205 }
206 return entry.Get(syncable::IS_UNSYNCED);
207 }
208
209 bool TestEntryFactory::GetIsUnappliedForItem(int64 meta_handle) const {
210 syncable::ReadTransaction trans(FROM_HERE, directory_);
211 syncable::Entry entry(&trans, syncable::GET_BY_HANDLE, meta_handle);
212 if (!entry.good()) {
213 NOTREACHED();
214 return false;
215 }
216 return entry.Get(syncable::IS_UNAPPLIED_UPDATE);
217 }
218
162 int64 TestEntryFactory::GetNextRevision() { 219 int64 TestEntryFactory::GetNextRevision() {
163 return next_revision_++; 220 return next_revision_++;
164 } 221 }
165 222
166 } // namespace syncer 223 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698