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

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: jif 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) {
132 reading_list::ReadingListLocal proto; 130 reading_list::ReadingListLocal proto;
133 if (!proto.ParseFromString(r.value)) { 131 if (!proto.ParseFromString(r.value)) {
134 continue; 132 continue;
135 // TODO(skym, crbug.com/582460): Handle unrecoverable initialization 133 // TODO(skym, crbug.com/582460): Handle unrecoverable initialization
136 // failure. 134 // failure.
137 } 135 }
138 136
139 std::unique_ptr<ReadingListEntry> entry( 137 std::unique_ptr<ReadingListEntry> entry(
140 ReadingListEntry::FromReadingListLocal(proto)); 138 ReadingListEntry::FromReadingListLocal(proto));
141 if (!entry) { 139 if (!entry) {
142 continue; 140 continue;
143 } 141 }
144 if (proto.status() == reading_list::ReadingListLocal::READ) { 142 GURL url = entry->URL();
145 read->push_back(std::move(*entry)); 143 DCHECK(!loaded_entries->count(url));
146 } else { 144 loaded_entries->insert(std::make_pair(url, std::move(*entry)));
147 unread->push_back(std::move(*entry));
148 }
149 } 145 }
150 146
151 delegate_->StoreLoaded(std::move(unread), std::move(read)); 147 delegate_->StoreLoaded(std::move(loaded_entries));
152 148
153 store_->ReadAllMetadata( 149 store_->ReadAllMetadata(
154 base::Bind(&ReadingListStore::OnReadAllMetadata, base::AsWeakPtr(this))); 150 base::Bind(&ReadingListStore::OnReadAllMetadata, base::AsWeakPtr(this)));
155 } 151 }
156 152
157 void ReadingListStore::OnReadAllMetadata( 153 void ReadingListStore::OnReadAllMetadata(
158 syncer::SyncError sync_error, 154 syncer::SyncError sync_error,
159 std::unique_ptr<syncer::MetadataBatch> metadata_batch) { 155 std::unique_ptr<syncer::MetadataBatch> metadata_batch) {
160 DCHECK(CalledOnValidThread()); 156 DCHECK(CalledOnValidThread());
161 change_processor()->OnMetadataLoaded(sync_error, std::move(metadata_batch)); 157 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; 208 std::set<std::string> synced_entries;
213 std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate> 209 std::unique_ptr<ReadingListModel::ScopedReadingListBatchUpdate>
214 model_batch_updates = model_->BeginBatchUpdates(); 210 model_batch_updates = model_->BeginBatchUpdates();
215 211
216 // Merge sync to local data. 212 // Merge sync to local data.
217 for (const auto& kv : entity_data_map) { 213 for (const auto& kv : entity_data_map) {
218 synced_entries.insert(kv.first); 214 synced_entries.insert(kv.first);
219 const sync_pb::ReadingListSpecifics& specifics = 215 const sync_pb::ReadingListSpecifics& specifics =
220 kv.second.value().specifics.reading_list(); 216 kv.second.value().specifics.reading_list();
221 // Deserialize entry. 217 // Deserialize entry.
222 bool read = specifics.status() == sync_pb::ReadingListSpecifics::READ;
223 std::unique_ptr<ReadingListEntry> entry( 218 std::unique_ptr<ReadingListEntry> entry(
224 ReadingListEntry::FromReadingListSpecifics(specifics)); 219 ReadingListEntry::FromReadingListSpecifics(specifics));
225 220
226 bool was_read;
227 const ReadingListEntry* existing_entry = 221 const ReadingListEntry* existing_entry =
228 model_->GetEntryFromURL(entry->URL(), &was_read); 222 model_->GetEntryByURL(entry->URL());
229 223
230 if (!existing_entry) { 224 if (!existing_entry) {
231 // This entry is new. Add it to the store and model. 225 // This entry is new. Add it to the store and model.
232 // Convert to local store format and write to store. 226 // Convert to local store format and write to store.
233 std::unique_ptr<reading_list::ReadingListLocal> entry_pb = 227 std::unique_ptr<reading_list::ReadingListLocal> entry_pb =
234 entry->AsReadingListLocal(read); 228 entry->AsReadingListLocal();
235 batch_->WriteData(entry->URL().spec(), entry_pb->SerializeAsString()); 229 batch_->WriteData(entry->URL().spec(), entry_pb->SerializeAsString());
236 230
237 // Notify model about updated entry. 231 // Notify model about updated entry.
238 delegate_->SyncAddEntry(std::move(entry), read); 232 delegate_->SyncAddEntry(std::move(entry));
239 } else if (existing_entry->UpdateTime() < entry->UpdateTime()) { 233 } else if (existing_entry->UpdateTime() < entry->UpdateTime()) {
240 // The entry from sync is more recent. 234 // The entry from sync is more recent.
241 // Merge the local data to it and store it. 235 // Merge the local data to it and store it.
242 ReadingListEntry* merged_entry = 236 ReadingListEntry* merged_entry =
243 delegate_->SyncMergeEntry(std::move(entry), read); 237 delegate_->SyncMergeEntry(std::move(entry));
244 238
245 // Write to the store. 239 // Write to the store.
246 std::unique_ptr<reading_list::ReadingListLocal> entry_local_pb = 240 std::unique_ptr<reading_list::ReadingListLocal> entry_local_pb =
247 merged_entry->AsReadingListLocal(read); 241 merged_entry->AsReadingListLocal();
248 batch_->WriteData(entry->URL().spec(), 242 batch_->WriteData(entry->URL().spec(),
249 entry_local_pb->SerializeAsString()); 243 entry_local_pb->SerializeAsString());
250 244
251 // Send to sync 245 // Send to sync
252 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_sync_pb = 246 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_sync_pb =
253 merged_entry->AsReadingListSpecifics(read); 247 merged_entry->AsReadingListSpecifics();
254 auto entity_data = base::MakeUnique<syncer::EntityData>(); 248 auto entity_data = base::MakeUnique<syncer::EntityData>();
255 *(entity_data->specifics.mutable_reading_list()) = *entry_sync_pb; 249 *(entity_data->specifics.mutable_reading_list()) = *entry_sync_pb;
256 entity_data->non_unique_name = entry_sync_pb->entry_id(); 250 entity_data->non_unique_name = entry_sync_pb->entry_id();
257 251
258 // TODO(crbug.com/666232): Investigate if there is a risk of sync 252 // TODO(crbug.com/666232): Investigate if there is a risk of sync
259 // ping-pong. 253 // ping-pong.
260 change_processor()->Put(entry_sync_pb->entry_id(), std::move(entity_data), 254 change_processor()->Put(entry_sync_pb->entry_id(), std::move(entity_data),
261 metadata_change_list.get()); 255 metadata_change_list.get());
262 256
263 } else { 257 } else {
264 // The entry from sync is out of date. 258 // The entry from sync is out of date.
265 // Send back the local more recent entry. 259 // Send back the local more recent entry.
266 // No need to update 260 // No need to update
267 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb = 261 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb =
268 existing_entry->AsReadingListSpecifics(was_read); 262 existing_entry->AsReadingListSpecifics();
269 auto entity_data = base::MakeUnique<syncer::EntityData>(); 263 auto entity_data = base::MakeUnique<syncer::EntityData>();
270 *(entity_data->specifics.mutable_reading_list()) = *entry_pb; 264 *(entity_data->specifics.mutable_reading_list()) = *entry_pb;
271 entity_data->non_unique_name = entry_pb->entry_id(); 265 entity_data->non_unique_name = entry_pb->entry_id();
272 266
273 change_processor()->Put(entry_pb->entry_id(), std::move(entity_data), 267 change_processor()->Put(entry_pb->entry_id(), std::move(entity_data),
274 metadata_change_list.get()); 268 metadata_change_list.get());
275 } 269 }
276 } 270 }
277 271
278 // Commit local only entries to server. 272 // Commit local only entries to server.
279 int unread_count = model_->unread_size(); 273 for (const auto& iterator : *model_) {
280 int read_count = model_->read_size(); 274 const ReadingListEntry& entry = iterator.second;
281 for (int index = 0; index < unread_count + read_count; index++) {
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())) { 275 if (synced_entries.count(entry.URL().spec())) {
287 // Entry already exists and has been merged above. 276 // Entry already exists and has been merged above.
288 continue; 277 continue;
289 } 278 }
290 279
291 // Local entry has later timestamp. It should be committed to server. 280 // Local entry has later timestamp. It should be committed to server.
292 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb = 281 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb =
293 entry.AsReadingListSpecifics(read); 282 entry.AsReadingListSpecifics();
294 283
295 auto entity_data = base::MakeUnique<syncer::EntityData>(); 284 auto entity_data = base::MakeUnique<syncer::EntityData>();
296 *(entity_data->specifics.mutable_reading_list()) = *entry_pb; 285 *(entity_data->specifics.mutable_reading_list()) = *entry_pb;
297 entity_data->non_unique_name = entry_pb->entry_id(); 286 entity_data->non_unique_name = entry_pb->entry_id();
298 287
299 change_processor()->Put(entry_pb->entry_id(), std::move(entity_data), 288 change_processor()->Put(entry_pb->entry_id(), std::move(entity_data),
300 metadata_change_list.get()); 289 metadata_change_list.get());
301 } 290 }
302 batch_->TransferMetadataChanges(std::move(metadata_change_list)); 291 batch_->TransferMetadataChanges(std::move(metadata_change_list));
303 292
(...skipping 15 matching lines...) Expand all
319 308
320 for (syncer::EntityChange& change : entity_changes) { 309 for (syncer::EntityChange& change : entity_changes) {
321 if (change.type() == syncer::EntityChange::ACTION_DELETE) { 310 if (change.type() == syncer::EntityChange::ACTION_DELETE) {
322 batch_->DeleteData(change.storage_key()); 311 batch_->DeleteData(change.storage_key());
323 // Need to notify model that entry is deleted. 312 // Need to notify model that entry is deleted.
324 delegate_->SyncRemoveEntry(GURL(change.storage_key())); 313 delegate_->SyncRemoveEntry(GURL(change.storage_key()));
325 } else { 314 } else {
326 // Deserialize entry. 315 // Deserialize entry.
327 const sync_pb::ReadingListSpecifics& specifics = 316 const sync_pb::ReadingListSpecifics& specifics =
328 change.data().specifics.reading_list(); 317 change.data().specifics.reading_list();
329 bool read = specifics.status() == sync_pb::ReadingListSpecifics::READ;
330 std::unique_ptr<ReadingListEntry> entry( 318 std::unique_ptr<ReadingListEntry> entry(
331 ReadingListEntry::FromReadingListSpecifics(specifics)); 319 ReadingListEntry::FromReadingListSpecifics(specifics));
332 320
333 bool was_read;
334 const ReadingListEntry* existing_entry = 321 const ReadingListEntry* existing_entry =
335 model_->GetEntryFromURL(entry->URL(), &was_read); 322 model_->GetEntryByURL(entry->URL());
336 323
337 if (!existing_entry) { 324 if (!existing_entry) {
338 // This entry is new. Add it to the store and model. 325 // This entry is new. Add it to the store and model.
339 // Convert to local store format and write to store. 326 // Convert to local store format and write to store.
340 std::unique_ptr<reading_list::ReadingListLocal> entry_pb = 327 std::unique_ptr<reading_list::ReadingListLocal> entry_pb =
341 entry->AsReadingListLocal(read); 328 entry->AsReadingListLocal();
342 batch_->WriteData(entry->URL().spec(), entry_pb->SerializeAsString()); 329 batch_->WriteData(entry->URL().spec(), entry_pb->SerializeAsString());
343 330
344 // Notify model about updated entry. 331 // Notify model about updated entry.
345 delegate_->SyncAddEntry(std::move(entry), read); 332 delegate_->SyncAddEntry(std::move(entry));
346 } else if (existing_entry->UpdateTime() < entry->UpdateTime()) { 333 } else if (existing_entry->UpdateTime() < entry->UpdateTime()) {
347 // The entry from sync is more recent. 334 // The entry from sync is more recent.
348 // Merge the local data to it and store it. 335 // Merge the local data to it and store it.
349 ReadingListEntry* merged_entry = 336 ReadingListEntry* merged_entry =
350 delegate_->SyncMergeEntry(std::move(entry), read); 337 delegate_->SyncMergeEntry(std::move(entry));
351 338
352 // Write to the store. 339 // Write to the store.
353 std::unique_ptr<reading_list::ReadingListLocal> entry_local_pb = 340 std::unique_ptr<reading_list::ReadingListLocal> entry_local_pb =
354 merged_entry->AsReadingListLocal(read); 341 merged_entry->AsReadingListLocal();
355 batch_->WriteData(merged_entry->URL().spec(), 342 batch_->WriteData(merged_entry->URL().spec(),
356 entry_local_pb->SerializeAsString()); 343 entry_local_pb->SerializeAsString());
357 344
358 // Send to sync 345 // Send to sync
359 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_sync_pb = 346 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_sync_pb =
360 merged_entry->AsReadingListSpecifics(read); 347 merged_entry->AsReadingListSpecifics();
361 auto entity_data = base::MakeUnique<syncer::EntityData>(); 348 auto entity_data = base::MakeUnique<syncer::EntityData>();
362 *(entity_data->specifics.mutable_reading_list()) = *entry_sync_pb; 349 *(entity_data->specifics.mutable_reading_list()) = *entry_sync_pb;
363 entity_data->non_unique_name = entry_sync_pb->entry_id(); 350 entity_data->non_unique_name = entry_sync_pb->entry_id();
364 351
365 // TODO(crbug.com/666232): Investigate if there is a risk of sync 352 // TODO(crbug.com/666232): Investigate if there is a risk of sync
366 // ping-pong. 353 // ping-pong.
367 change_processor()->Put(entry_sync_pb->entry_id(), 354 change_processor()->Put(entry_sync_pb->entry_id(),
368 std::move(entity_data), 355 std::move(entity_data),
369 metadata_change_list.get()); 356 metadata_change_list.get());
370 357
371 } else { 358 } else {
372 // The entry from sync is out of date. 359 // The entry from sync is out of date.
373 // Send back the local more recent entry. 360 // Send back the local more recent entry.
374 // No need to update 361 // No need to update
375 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb = 362 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb =
376 existing_entry->AsReadingListSpecifics(was_read); 363 existing_entry->AsReadingListSpecifics();
377 auto entity_data = base::MakeUnique<syncer::EntityData>(); 364 auto entity_data = base::MakeUnique<syncer::EntityData>();
378 *(entity_data->specifics.mutable_reading_list()) = *entry_pb; 365 *(entity_data->specifics.mutable_reading_list()) = *entry_pb;
379 entity_data->non_unique_name = entry_pb->entry_id(); 366 entity_data->non_unique_name = entry_pb->entry_id();
380 367
381 change_processor()->Put(entry_pb->entry_id(), std::move(entity_data), 368 change_processor()->Put(entry_pb->entry_id(), std::move(entity_data),
382 metadata_change_list.get()); 369 metadata_change_list.get());
383 } 370 }
384 } 371 }
385 } 372 }
386 373
387 batch_->TransferMetadataChanges(std::move(metadata_change_list)); 374 batch_->TransferMetadataChanges(std::move(metadata_change_list));
388 return syncer::SyncError(); 375 return syncer::SyncError();
389 } 376 }
390 377
391 void ReadingListStore::GetData(StorageKeyList storage_keys, 378 void ReadingListStore::GetData(StorageKeyList storage_keys,
392 DataCallback callback) { 379 DataCallback callback) {
393 DCHECK(CalledOnValidThread()); 380 DCHECK(CalledOnValidThread());
394 auto batch = base::MakeUnique<syncer::MutableDataBatch>(); 381 auto batch = base::MakeUnique<syncer::MutableDataBatch>();
395 for (std::string url_string : storage_keys) { 382 for (const std::string& url_string : storage_keys) {
396 bool read; 383 const ReadingListEntry* entry = model_->GetEntryByURL(GURL(url_string));
397 const ReadingListEntry* entry =
398 model_->GetEntryFromURL(GURL(url_string), &read);
399 if (entry) { 384 if (entry) {
400 AddEntryToBatch(batch.get(), *entry, read); 385 AddEntryToBatch(batch.get(), *entry);
401 } 386 }
402 } 387 }
403 388
404 callback.Run(syncer::SyncError(), std::move(batch)); 389 callback.Run(syncer::SyncError(), std::move(batch));
405 } 390 }
406 391
407 void ReadingListStore::GetAllData(DataCallback callback) { 392 void ReadingListStore::GetAllData(DataCallback callback) {
408 DCHECK(CalledOnValidThread()); 393 DCHECK(CalledOnValidThread());
409 auto batch = base::MakeUnique<syncer::MutableDataBatch>(); 394 auto batch = base::MakeUnique<syncer::MutableDataBatch>();
410 int unread_count = model_->unread_size(); 395
411 int read_count = model_->read_size(); 396 for (const auto& iterator : *model_) {
412 for (int index = 0; index < unread_count + read_count; index++) { 397 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 } 398 }
419 399
420 callback.Run(syncer::SyncError(), std::move(batch)); 400 callback.Run(syncer::SyncError(), std::move(batch));
421 } 401 }
422 402
423 void ReadingListStore::AddEntryToBatch(syncer::MutableDataBatch* batch, 403 void ReadingListStore::AddEntryToBatch(syncer::MutableDataBatch* batch,
424 const ReadingListEntry& entry, 404 const ReadingListEntry& entry) {
425 bool read) {
426 DCHECK(CalledOnValidThread()); 405 DCHECK(CalledOnValidThread());
427 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb = 406 std::unique_ptr<sync_pb::ReadingListSpecifics> entry_pb =
428 entry.AsReadingListSpecifics(read); 407 entry.AsReadingListSpecifics();
429 408
430 std::unique_ptr<syncer::EntityData> entity_data(new syncer::EntityData()); 409 std::unique_ptr<syncer::EntityData> entity_data(new syncer::EntityData());
431 *(entity_data->specifics.mutable_reading_list()) = *entry_pb; 410 *(entity_data->specifics.mutable_reading_list()) = *entry_pb;
432 entity_data->non_unique_name = entry_pb->entry_id(); 411 entity_data->non_unique_name = entry_pb->entry_id();
433 412
434 batch->Put(entry_pb->entry_id(), std::move(entity_data)); 413 batch->Put(entry_pb->entry_id(), std::move(entity_data));
435 } 414 }
436 415
437 // Get or generate a client tag for |entity_data|. This must be the same tag 416 // 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 417 // 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 430 // called once when first encountering a remote entity. Local changes will
452 // provide their storage keys directly to Put instead of using this method. 431 // 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 432 // 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 433 // on the same or different clients, but to keep things simple, it probably
455 // should be. 434 // should be.
456 std::string ReadingListStore::GetStorageKey( 435 std::string ReadingListStore::GetStorageKey(
457 const syncer::EntityData& entity_data) { 436 const syncer::EntityData& entity_data) {
458 DCHECK(CalledOnValidThread()); 437 DCHECK(CalledOnValidThread());
459 return entity_data.specifics.reading_list().entry_id(); 438 return entity_data.specifics.reading_list().entry_id();
460 } 439 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698