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

Side by Side Diff: components/reading_list/ios/reading_list_store.cc

Issue 2525663002: Refactor Reading List Model to use URL as key. (Closed)
Patch Set: feedback Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/reading_list/ios/reading_list_store.h" 5 #include "components/reading_list/ios/reading_list_store.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "components/reading_list/ios/proto/reading_list.pb.h" 10 #include "components/reading_list/ios/proto/reading_list.pb.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 DCHECK(CalledOnValidThread()); 64 DCHECK(CalledOnValidThread());
65 pending_transaction_count_--; 65 pending_transaction_count_--;
66 if (pending_transaction_count_ == 0) { 66 if (pending_transaction_count_ == 0) {
67 store_->CommitWriteBatch( 67 store_->CommitWriteBatch(
68 std::move(batch_), 68 std::move(batch_),
69 base::Bind(&ReadingListStore::OnDatabaseSave, base::AsWeakPtr(this))); 69 base::Bind(&ReadingListStore::OnDatabaseSave, base::AsWeakPtr(this)));
70 batch_.reset(); 70 batch_.reset();
71 } 71 }
72 } 72 }
73 73
74 void ReadingListStore::SaveEntry(const ReadingListEntry& entry, bool read) { 74 void ReadingListStore::SaveEntry(const ReadingListEntry& entry) {
75 DCHECK(CalledOnValidThread()); 75 DCHECK(CalledOnValidThread());
76 auto token = EnsureBatchCreated(); 76 auto token = EnsureBatchCreated();
77 77
78 std::unique_ptr<reading_list::ReadingListLocal> pb_entry = 78 std::unique_ptr<reading_list::ReadingListLocal> pb_entry =
79 entry.AsReadingListLocal(read); 79 entry.AsReadingListLocal();
80 80
81 batch_->WriteData(entry.URL().spec(), pb_entry->SerializeAsString()); 81 batch_->WriteData(entry.URL().spec(), pb_entry->SerializeAsString());
82 82
83 if (!change_processor()->IsTrackingMetadata()) { 83 if (!change_processor()->IsTrackingMetadata()) {
84 return; 84 return;
85 } 85 }
86 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry_sync = 86 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry_sync =
87 entry.AsReadingListSpecifics(read); 87 entry.AsReadingListSpecifics();
88 88
89 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list = 89 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list =
90 CreateMetadataChangeList(); 90 CreateMetadataChangeList();
91 91
92 std::unique_ptr<syncer::EntityData> entity_data(new syncer::EntityData()); 92 std::unique_ptr<syncer::EntityData> entity_data(new syncer::EntityData());
93 *entity_data->specifics.mutable_reading_list() = *pb_entry_sync; 93 *entity_data->specifics.mutable_reading_list() = *pb_entry_sync;
94 entity_data->non_unique_name = pb_entry_sync->entry_id(); 94 entity_data->non_unique_name = pb_entry_sync->entry_id();
95 95
96 change_processor()->Put(entry.URL().spec(), std::move(entity_data), 96 change_processor()->Put(entry.URL().spec(), std::move(entity_data),
97 metadata_change_list.get()); 97 metadata_change_list.get());
(...skipping 19 matching lines...) Expand all
117 syncer::ModelTypeStore::Result result, 117 syncer::ModelTypeStore::Result result,
118 std::unique_ptr<syncer::ModelTypeStore::RecordList> entries) { 118 std::unique_ptr<syncer::ModelTypeStore::RecordList> entries) {
119 DCHECK(CalledOnValidThread()); 119 DCHECK(CalledOnValidThread());
120 if (result != syncer::ModelTypeStore::Result::SUCCESS) { 120 if (result != syncer::ModelTypeStore::Result::SUCCESS) {
121 change_processor()->OnMetadataLoaded( 121 change_processor()->OnMetadataLoaded(
122 change_processor()->CreateAndUploadError( 122 change_processor()->CreateAndUploadError(
123 FROM_HERE, "Cannot load Reading List Database."), 123 FROM_HERE, "Cannot load Reading List Database."),
124 nullptr); 124 nullptr);
125 return; 125 return;
126 } 126 }
127 auto read = base::MakeUnique<ReadingListEntries>(); 127 auto loaded_entries = base::MakeUnique<ReadingListEntries>();
128 auto unread = base::MakeUnique<ReadingListEntries>();
129 128
130 for (const syncer::ModelTypeStore::Record& r : *entries.get()) { 129 for (const syncer::ModelTypeStore::Record& r : *entries.get()) {
131 // for (const reading_list::ReadingListLocal& pb_entry : *entries) { 130 // for (const reading_list::ReadingListLocal& pb_entry : *entries) {
132 reading_list::ReadingListLocal proto; 131 reading_list::ReadingListLocal proto;
133 if (!proto.ParseFromString(r.value)) { 132 if (!proto.ParseFromString(r.value)) {
134 continue; 133 continue;
135 // TODO(skym, crbug.com/582460): Handle unrecoverable initialization 134 // TODO(skym, crbug.com/582460): Handle unrecoverable initialization
136 // failure. 135 // failure.
137 } 136 }
138 137
139 std::unique_ptr<ReadingListEntry> entry( 138 std::unique_ptr<ReadingListEntry> entry(
140 ReadingListEntry::FromReadingListLocal(proto)); 139 ReadingListEntry::FromReadingListLocal(proto));
141 if (!entry) { 140 if (!entry) {
142 continue; 141 continue;
143 } 142 }
144 if (proto.status() == reading_list::ReadingListLocal::READ) { 143 GURL url = entry->URL();
145 read->push_back(std::move(*entry)); 144 DCHECK(!loaded_entries->count(url));
146 } else { 145 loaded_entries->insert(std::make_pair(url, std::move(*entry)));
jif-google 2016/11/28 16:28:21 use operator[] if possible
Olivier 2016/11/28 17:58:25 Not possible
147 unread->push_back(std::move(*entry));
148 }
149 } 146 }
150 147
151 delegate_->StoreLoaded(std::move(unread), std::move(read)); 148 delegate_->StoreLoaded(std::move(loaded_entries));
152 149
153 store_->ReadAllMetadata( 150 store_->ReadAllMetadata(
154 base::Bind(&ReadingListStore::OnReadAllMetadata, base::AsWeakPtr(this))); 151 base::Bind(&ReadingListStore::OnReadAllMetadata, base::AsWeakPtr(this)));
155 } 152 }
156 153
157 void ReadingListStore::OnReadAllMetadata( 154 void ReadingListStore::OnReadAllMetadata(
158 syncer::SyncError sync_error, 155 syncer::SyncError sync_error,
159 std::unique_ptr<syncer::MetadataBatch> metadata_batch) { 156 std::unique_ptr<syncer::MetadataBatch> metadata_batch) {
160 DCHECK(CalledOnValidThread()); 157 DCHECK(CalledOnValidThread());
161 change_processor()->OnMetadataLoaded(sync_error, std::move(metadata_batch)); 158 change_processor()->OnMetadataLoaded(sync_error, std::move(metadata_batch));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 std::set<std::string> synced_entries; 209 std::set<std::string> synced_entries;
213 std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate> 210 std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate>
214 model_batch_updates = model_->BeginBatchUpdates(); 211 model_batch_updates = model_->BeginBatchUpdates();
215 212
216 // Merge sync to local data. 213 // Merge sync to local data.
217 for (const auto& kv : entity_data_map) { 214 for (const auto& kv : entity_data_map) {
218 synced_entries.insert(kv.first); 215 synced_entries.insert(kv.first);
219 const sync_pb::ReadingListSpecifics& specifics = 216 const sync_pb::ReadingListSpecifics& specifics =
220 kv.second.value().specifics.reading_list(); 217 kv.second.value().specifics.reading_list();
221 // Deserialize entry. 218 // Deserialize entry.
222 bool read = specifics.status() == sync_pb::ReadingListSpecifics::READ;
223 std::unique_ptr<ReadingListEntry> entry( 219 std::unique_ptr<ReadingListEntry> entry(
224 ReadingListEntry::FromReadingListSpecifics(specifics)); 220 ReadingListEntry::FromReadingListSpecifics(specifics));
225 221
226 bool was_read;
227 const ReadingListEntry* existing_entry = 222 const ReadingListEntry* existing_entry =
228 model_->GetEntryFromURL(entry->URL(), &was_read); 223 model_->GetEntryByURL(entry->URL());
229 224
230 if (!existing_entry) { 225 if (!existing_entry) {
231 // This entry is new. Add it to the store and model. 226 // This entry is new. Add it to the store and model.
232 // Convert to local store format and write to store. 227 // Convert to local store format and write to store.
233 std::unique_ptr<reading_list::ReadingListLocal> entry_pb = 228 std::unique_ptr<reading_list::ReadingListLocal> entry_pb =
234 entry->AsReadingListLocal(read); 229 entry->AsReadingListLocal();
235 batch_->WriteData(entry->URL().spec(), entry_pb->SerializeAsString()); 230 batch_->WriteData(entry->URL().spec(), entry_pb->SerializeAsString());
236 231
237 // Notify model about updated entry. 232 // Notify model about updated entry.
238 delegate_->SyncAddEntry(std::move(entry), read); 233 delegate_->SyncAddEntry(std::move(entry));
239 } else if (existing_entry->UpdateTime() < entry->UpdateTime()) { 234 } else if (existing_entry->UpdateTime() < entry->UpdateTime()) {
240 // The entry from sync is more recent. 235 // The entry from sync is more recent.
241 // Merge the local data to it and store it. 236 // Merge the local data to it and store it.
242 ReadingListEntry* merged_entry = 237 ReadingListEntry* merged_entry =
243 delegate_->SyncMergeEntry(std::move(entry), read); 238 delegate_->SyncMergeEntry(std::move(entry));
244 239
245 // Write to the store. 240 // Write to the store.
246 std::unique_ptr<reading_list::ReadingListLocal> entry_local_pb = 241 std::unique_ptr<reading_list::ReadingListLocal> entry_local_pb =
247 merged_entry->AsReadingListLocal(read); 242 merged_entry->AsReadingListLocal();
248 batch_->WriteData(entry->URL().spec(), 243 batch_->WriteData(entry->URL().spec(),
249 entry_local_pb->SerializeAsString()); 244 entry_local_pb->SerializeAsString());
250 245
251 // Send to sync 246 // Send to sync
252 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_sync_pb = 247 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_sync_pb =
253 merged_entry->AsReadingListSpecifics(read); 248 merged_entry->AsReadingListSpecifics();
254 auto entity_data = base::MakeUnique<syncer::EntityData>(); 249 auto entity_data = base::MakeUnique<syncer::EntityData>();
255 *(entity_data->specifics.mutable_reading_list()) = *entry_sync_pb; 250 *(entity_data->specifics.mutable_reading_list()) = *entry_sync_pb;
256 entity_data->non_unique_name = entry_sync_pb->entry_id(); 251 entity_data->non_unique_name = entry_sync_pb->entry_id();
257 252
258 // TODO(crbug.com/666232): Investigate if there is a risk of sync 253 // TODO(crbug.com/666232): Investigate if there is a risk of sync
259 // ping-pong. 254 // ping-pong.
260 change_processor()->Put(entry_sync_pb->entry_id(), std::move(entity_data), 255 change_processor()->Put(entry_sync_pb->entry_id(), std::move(entity_data),
261 metadata_change_list.get()); 256 metadata_change_list.get());
262 257
263 } else { 258 } else {
264 // The entry from sync is out of date. 259 // The entry from sync is out of date.
265 // Send back the local more recent entry. 260 // Send back the local more recent entry.
266 // No need to update 261 // No need to update
267 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb = 262 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb =
268 existing_entry->AsReadingListSpecifics(was_read); 263 existing_entry->AsReadingListSpecifics();
269 auto entity_data = base::MakeUnique<syncer::EntityData>(); 264 auto entity_data = base::MakeUnique<syncer::EntityData>();
270 *(entity_data->specifics.mutable_reading_list()) = *entry_pb; 265 *(entity_data->specifics.mutable_reading_list()) = *entry_pb;
271 entity_data->non_unique_name = entry_pb->entry_id(); 266 entity_data->non_unique_name = entry_pb->entry_id();
272 267
273 change_processor()->Put(entry_pb->entry_id(), std::move(entity_data), 268 change_processor()->Put(entry_pb->entry_id(), std::move(entity_data),
274 metadata_change_list.get()); 269 metadata_change_list.get());
275 } 270 }
276 } 271 }
277 272
278 // Commit local only entries to server. 273 // Commit local only entries to server.
279 int unread_count = model_->unread_size(); 274 for (const auto& iterator : *model_) {
280 int read_count = model_->read_size(); 275 // for (int index = 0; index < count; index++) {
jif-google 2016/11/28 16:28:21 remove
Olivier 2016/11/28 17:58:25 Done.
281 for (int index = 0; index < unread_count + read_count; index++) { 276 const ReadingListEntry& entry = iterator.second;
282 bool read = index >= unread_count;
283 const ReadingListEntry& entry =
284 read ? model_->GetReadEntryAtIndex(index - unread_count)
285 : model_->GetUnreadEntryAtIndex(index);
286 if (synced_entries.count(entry.URL().spec())) { 277 if (synced_entries.count(entry.URL().spec())) {
287 // Entry already exists and has been merged above. 278 // Entry already exists and has been merged above.
288 continue; 279 continue;
289 } 280 }
290 281
291 // Local entry has later timestamp. It should be committed to server. 282 // Local entry has later timestamp. It should be committed to server.
292 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb = 283 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb =
293 entry.AsReadingListSpecifics(read); 284 entry.AsReadingListSpecifics();
294 285
295 auto entity_data = base::MakeUnique<syncer::EntityData>(); 286 auto entity_data = base::MakeUnique<syncer::EntityData>();
296 *(entity_data->specifics.mutable_reading_list()) = *entry_pb; 287 *(entity_data->specifics.mutable_reading_list()) = *entry_pb;
297 entity_data->non_unique_name = entry_pb->entry_id(); 288 entity_data->non_unique_name = entry_pb->entry_id();
298 289
299 change_processor()->Put(entry_pb->entry_id(), std::move(entity_data), 290 change_processor()->Put(entry_pb->entry_id(), std::move(entity_data),
300 metadata_change_list.get()); 291 metadata_change_list.get());
301 } 292 }
302 batch_->TransferMetadataChanges(std::move(metadata_change_list)); 293 batch_->TransferMetadataChanges(std::move(metadata_change_list));
303 294
(...skipping 15 matching lines...) Expand all
319 310
320 for (syncer::EntityChange& change : entity_changes) { 311 for (syncer::EntityChange& change : entity_changes) {
321 if (change.type() == syncer::EntityChange::ACTION_DELETE) { 312 if (change.type() == syncer::EntityChange::ACTION_DELETE) {
322 batch_->DeleteData(change.storage_key()); 313 batch_->DeleteData(change.storage_key());
323 // Need to notify model that entry is deleted. 314 // Need to notify model that entry is deleted.
324 delegate_->SyncRemoveEntry(GURL(change.storage_key())); 315 delegate_->SyncRemoveEntry(GURL(change.storage_key()));
325 } else { 316 } else {
326 // Deserialize entry. 317 // Deserialize entry.
327 const sync_pb::ReadingListSpecifics& specifics = 318 const sync_pb::ReadingListSpecifics& specifics =
328 change.data().specifics.reading_list(); 319 change.data().specifics.reading_list();
329 bool read = specifics.status() == sync_pb::ReadingListSpecifics::READ;
330 std::unique_ptr<ReadingListEntry> entry( 320 std::unique_ptr<ReadingListEntry> entry(
331 ReadingListEntry::FromReadingListSpecifics(specifics)); 321 ReadingListEntry::FromReadingListSpecifics(specifics));
332 322
333 bool was_read;
334 const ReadingListEntry* existing_entry = 323 const ReadingListEntry* existing_entry =
335 model_->GetEntryFromURL(entry->URL(), &was_read); 324 model_->GetEntryByURL(entry->URL());
336 325
337 if (!existing_entry) { 326 if (!existing_entry) {
338 // This entry is new. Add it to the store and model. 327 // This entry is new. Add it to the store and model.
339 // Convert to local store format and write to store. 328 // Convert to local store format and write to store.
340 std::unique_ptr<reading_list::ReadingListLocal> entry_pb = 329 std::unique_ptr<reading_list::ReadingListLocal> entry_pb =
341 entry->AsReadingListLocal(read); 330 entry->AsReadingListLocal();
342 batch_->WriteData(entry->URL().spec(), entry_pb->SerializeAsString()); 331 batch_->WriteData(entry->URL().spec(), entry_pb->SerializeAsString());
343 332
344 // Notify model about updated entry. 333 // Notify model about updated entry.
345 delegate_->SyncAddEntry(std::move(entry), read); 334 delegate_->SyncAddEntry(std::move(entry));
346 } else if (existing_entry->UpdateTime() < entry->UpdateTime()) { 335 } else if (existing_entry->UpdateTime() < entry->UpdateTime()) {
347 // The entry from sync is more recent. 336 // The entry from sync is more recent.
348 // Merge the local data to it and store it. 337 // Merge the local data to it and store it.
349 ReadingListEntry* merged_entry = 338 ReadingListEntry* merged_entry =
350 delegate_->SyncMergeEntry(std::move(entry), read); 339 delegate_->SyncMergeEntry(std::move(entry));
351 340
352 // Write to the store. 341 // Write to the store.
353 std::unique_ptr<reading_list::ReadingListLocal> entry_local_pb = 342 std::unique_ptr<reading_list::ReadingListLocal> entry_local_pb =
354 merged_entry->AsReadingListLocal(read); 343 merged_entry->AsReadingListLocal();
355 batch_->WriteData(merged_entry->URL().spec(), 344 batch_->WriteData(merged_entry->URL().spec(),
356 entry_local_pb->SerializeAsString()); 345 entry_local_pb->SerializeAsString());
357 346
358 // Send to sync 347 // Send to sync
359 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_sync_pb = 348 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_sync_pb =
360 merged_entry->AsReadingListSpecifics(read); 349 merged_entry->AsReadingListSpecifics();
361 auto entity_data = base::MakeUnique<syncer::EntityData>(); 350 auto entity_data = base::MakeUnique<syncer::EntityData>();
362 *(entity_data->specifics.mutable_reading_list()) = *entry_sync_pb; 351 *(entity_data->specifics.mutable_reading_list()) = *entry_sync_pb;
363 entity_data->non_unique_name = entry_sync_pb->entry_id(); 352 entity_data->non_unique_name = entry_sync_pb->entry_id();
364 353
365 // TODO(crbug.com/666232): Investigate if there is a risk of sync 354 // TODO(crbug.com/666232): Investigate if there is a risk of sync
366 // ping-pong. 355 // ping-pong.
367 change_processor()->Put(entry_sync_pb->entry_id(), 356 change_processor()->Put(entry_sync_pb->entry_id(),
368 std::move(entity_data), 357 std::move(entity_data),
369 metadata_change_list.get()); 358 metadata_change_list.get());
370 359
371 } else { 360 } else {
372 // The entry from sync is out of date. 361 // The entry from sync is out of date.
373 // Send back the local more recent entry. 362 // Send back the local more recent entry.
374 // No need to update 363 // No need to update
375 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb = 364 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb =
376 existing_entry->AsReadingListSpecifics(was_read); 365 existing_entry->AsReadingListSpecifics();
377 auto entity_data = base::MakeUnique<syncer::EntityData>(); 366 auto entity_data = base::MakeUnique<syncer::EntityData>();
378 *(entity_data->specifics.mutable_reading_list()) = *entry_pb; 367 *(entity_data->specifics.mutable_reading_list()) = *entry_pb;
379 entity_data->non_unique_name = entry_pb->entry_id(); 368 entity_data->non_unique_name = entry_pb->entry_id();
380 369
381 change_processor()->Put(entry_pb->entry_id(), std::move(entity_data), 370 change_processor()->Put(entry_pb->entry_id(), std::move(entity_data),
382 metadata_change_list.get()); 371 metadata_change_list.get());
383 } 372 }
384 } 373 }
385 } 374 }
386 375
387 batch_->TransferMetadataChanges(std::move(metadata_change_list)); 376 batch_->TransferMetadataChanges(std::move(metadata_change_list));
388 return syncer::SyncError(); 377 return syncer::SyncError();
389 } 378 }
390 379
391 void ReadingListStore::GetData(StorageKeyList storage_keys, 380 void ReadingListStore::GetData(StorageKeyList storage_keys,
392 DataCallback callback) { 381 DataCallback callback) {
393 DCHECK(CalledOnValidThread()); 382 DCHECK(CalledOnValidThread());
394 auto batch = base::MakeUnique<syncer::MutableDataBatch>(); 383 auto batch = base::MakeUnique<syncer::MutableDataBatch>();
395 for (std::string url_string : storage_keys) { 384 for (std::string url_string : storage_keys) {
jif-google 2016/11/28 16:28:21 const std::string& url_string
Olivier 2016/11/28 17:58:25 Done.
396 bool read; 385 const ReadingListEntry* entry = model_->GetEntryByURL(GURL(url_string));
397 const ReadingListEntry* entry =
398 model_->GetEntryFromURL(GURL(url_string), &read);
399 if (entry) { 386 if (entry) {
400 AddEntryToBatch(batch.get(), *entry, read); 387 AddEntryToBatch(batch.get(), *entry);
401 } 388 }
402 } 389 }
403 390
404 callback.Run(syncer::SyncError(), std::move(batch)); 391 callback.Run(syncer::SyncError(), std::move(batch));
405 } 392 }
406 393
407 void ReadingListStore::GetAllData(DataCallback callback) { 394 void ReadingListStore::GetAllData(DataCallback callback) {
408 DCHECK(CalledOnValidThread()); 395 DCHECK(CalledOnValidThread());
409 auto batch = base::MakeUnique<syncer::MutableDataBatch>(); 396 auto batch = base::MakeUnique<syncer::MutableDataBatch>();
410 int unread_count = model_->unread_size(); 397
411 int read_count = model_->read_size(); 398 for (const auto& iterator : *model_) {
412 for (int index = 0; index < unread_count + read_count; index++) { 399 AddEntryToBatch(batch.get(), iterator.second);
413 bool read = index >= unread_count;
414 const ReadingListEntry& entry =
415 read ? model_->GetReadEntryAtIndex(index - unread_count)
416 : model_->GetUnreadEntryAtIndex(index);
417 AddEntryToBatch(batch.get(), entry, read);
418 } 400 }
419 401
420 callback.Run(syncer::SyncError(), std::move(batch)); 402 callback.Run(syncer::SyncError(), std::move(batch));
421 } 403 }
422 404
423 void ReadingListStore::AddEntryToBatch(syncer::MutableDataBatch* batch, 405 void ReadingListStore::AddEntryToBatch(syncer::MutableDataBatch* batch,
424 const ReadingListEntry& entry, 406 const ReadingListEntry& entry) {
425 bool read) {
426 DCHECK(CalledOnValidThread()); 407 DCHECK(CalledOnValidThread());
427 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb = 408 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb =
428 entry.AsReadingListSpecifics(read); 409 entry.AsReadingListSpecifics();
429 410
430 std::unique_ptr<syncer::EntityData> entity_data(new syncer::EntityData()); 411 std::unique_ptr<syncer::EntityData> entity_data(new syncer::EntityData());
431 *(entity_data->specifics.mutable_reading_list()) = *entry_pb; 412 *(entity_data->specifics.mutable_reading_list()) = *entry_pb;
432 entity_data->non_unique_name = entry_pb->entry_id(); 413 entity_data->non_unique_name = entry_pb->entry_id();
433 414
434 batch->Put(entry_pb->entry_id(), std::move(entity_data)); 415 batch->Put(entry_pb->entry_id(), std::move(entity_data));
435 } 416 }
436 417
437 // Get or generate a client tag for |entity_data|. This must be the same tag 418 // Get or generate a client tag for |entity_data|. This must be the same tag
438 // that was/would have been generated in the SyncableService/Directory world 419 // that was/would have been generated in the SyncableService/Directory world
(...skipping 12 matching lines...) Expand all
451 // called once when first encountering a remote entity. Local changes will 432 // called once when first encountering a remote entity. Local changes will
452 // provide their storage keys directly to Put instead of using this method. 433 // provide their storage keys directly to Put instead of using this method.
453 // Theoretically this function doesn't need to be stable across multiple calls 434 // Theoretically this function doesn't need to be stable across multiple calls
454 // on the same or different clients, but to keep things simple, it probably 435 // on the same or different clients, but to keep things simple, it probably
455 // should be. 436 // should be.
456 std::string ReadingListStore::GetStorageKey( 437 std::string ReadingListStore::GetStorageKey(
457 const syncer::EntityData& entity_data) { 438 const syncer::EntityData& entity_data) {
458 DCHECK(CalledOnValidThread()); 439 DCHECK(CalledOnValidThread());
459 return entity_data.specifics.reading_list().entry_id(); 440 return entity_data.specifics.reading_list().entry_id();
460 } 441 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698