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

Side by Side Diff: components/autofill/core/browser/webdata/autocomplete_sync_bridge.cc

Issue 2620783002: [sync] Handle local changes in AutocompleteSyncBridge (Closed)
Patch Set: rebase onto sky's changes Created 3 years, 11 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 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/autofill/core/browser/webdata/autocomplete_sync_bridge.h" 5 #include "components/autofill/core/browser/webdata/autocomplete_sync_bridge.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <unordered_set> 9 #include <unordered_set>
10 #include <utility> 10 #include <utility>
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 286
287 AutocompleteSyncBridge::AutocompleteSyncBridge( 287 AutocompleteSyncBridge::AutocompleteSyncBridge(
288 AutofillWebDataBackend* backend, 288 AutofillWebDataBackend* backend,
289 const ChangeProcessorFactory& change_processor_factory) 289 const ChangeProcessorFactory& change_processor_factory)
290 : ModelTypeSyncBridge(change_processor_factory, syncer::AUTOFILL), 290 : ModelTypeSyncBridge(change_processor_factory, syncer::AUTOFILL),
291 web_data_backend_(backend), 291 web_data_backend_(backend),
292 scoped_observer_(this) { 292 scoped_observer_(this) {
293 DCHECK(web_data_backend_); 293 DCHECK(web_data_backend_);
294 294
295 scoped_observer_.Add(web_data_backend_); 295 scoped_observer_.Add(web_data_backend_);
296
297 LoadMetadata();
skym 2017/01/14 00:04:33 As far as I can tell, no unit tests check that thi
Patrick Noland 2017/01/17 22:59:55 Done.
296 } 298 }
297 299
298 AutocompleteSyncBridge::~AutocompleteSyncBridge() { 300 AutocompleteSyncBridge::~AutocompleteSyncBridge() {
299 DCHECK(thread_checker_.CalledOnValidThread()); 301 DCHECK(thread_checker_.CalledOnValidThread());
300 } 302 }
301 303
302 std::unique_ptr<MetadataChangeList> 304 std::unique_ptr<MetadataChangeList>
303 AutocompleteSyncBridge::CreateMetadataChangeList() { 305 AutocompleteSyncBridge::CreateMetadataChangeList() {
304 DCHECK(thread_checker_.CalledOnValidThread()); 306 DCHECK(thread_checker_.CalledOnValidThread());
305 return base::MakeUnique<AutofillMetadataChangeList>(GetAutofillTable(), 307 return base::MakeUnique<AutofillMetadataChangeList>(GetAutofillTable(),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 return; 385 return;
384 } 386 }
385 387
386 auto batch = base::MakeUnique<MutableDataBatch>(); 388 auto batch = base::MakeUnique<MutableDataBatch>();
387 for (const AutofillEntry& entry : entries) { 389 for (const AutofillEntry& entry : entries) {
388 batch->Put(GetStorageKeyFromModel(entry.key()), CreateEntityData(entry)); 390 batch->Put(GetStorageKeyFromModel(entry.key()), CreateEntityData(entry));
389 } 391 }
390 callback.Run(std::move(batch)); 392 callback.Run(std::move(batch));
391 } 393 }
392 394
395 void AutocompleteSyncBridge::ActOnLocalChanges(
396 const AutofillChangeList& changes) {
397 if (!change_processor()->IsTrackingMetadata()) {
398 return;
399 }
400
401 std::unique_ptr<AutofillMetadataChangeList> change_list =
maxbogue 2017/01/14 00:39:02 auto mcl = base::MakeUnique... auto because MakeU
skym 2017/01/17 17:57:21 I'm not a huge fan of abbreviations. I'd prefer me
Patrick Noland 2017/01/17 22:59:55 Done. I also don't love abbreviations whose meanin
402 base::MakeUnique<AutofillMetadataChangeList>(GetAutofillTable(),
403 syncer::AUTOFILL);
404 for (const auto& change : changes) {
405 const std::string storage_key = GetStorageKeyFromModel(change.key());
406 switch (change.type()) {
407 case AutofillChange::ADD:
408 case AutofillChange::UPDATE: {
409 base::Time date_created, date_last_used;
410 bool success = GetAutofillTable()->GetAutofillTimestamps(
411 change.key().name(), change.key().value(), &date_created,
412 &date_last_used);
413 if (!success) {
414 change_processor()->ReportError(
415 FROM_HERE, "Failed reading autofill entry from WebDatabase.");
416 return;
417 }
418
419 AutofillEntry entry(change.key(), date_created, date_last_used);
skym 2017/01/14 00:04:33 If you're going to const the storage_key, might as
Patrick Noland 2017/01/17 22:59:55 Done.
420 std::unique_ptr<syncer::EntityData> entity_data =
skym 2017/01/14 00:04:33 I'd personally inline this, you're only saving a s
maxbogue 2017/01/14 00:39:02 +1
Patrick Noland 2017/01/17 22:59:55 Done.
421 CreateEntityData(entry);
422 change_processor()->Put(storage_key, std::move(entity_data),
423 change_list.get());
424 break;
425 }
426 case AutofillChange::REMOVE: {
427 change_processor()->Delete(storage_key, change_list.get());
428 break;
429 }
430 }
431 }
432
433 Optional<ModelError> error = change_list->TakeError();
434 if (error) {
435 change_processor()->ReportError(
skym 2017/01/14 00:04:33 You should give |error| (via error.value()) to Rep
maxbogue 2017/01/14 00:39:02 +1
Patrick Noland 2017/01/17 22:59:55 Done.
436 FROM_HERE, "Failed writing autofill metadata to WebDatabase.");
437 }
438 }
439
440 void AutocompleteSyncBridge::LoadMetadata() {
441 std::unique_ptr<syncer::MetadataBatch> batch =
skym 2017/01/14 00:04:33 auto!
Patrick Noland 2017/01/17 22:59:55 Done.
442 base::MakeUnique<syncer::MetadataBatch>();
443 if (!GetAutofillTable()->GetAllSyncMetadata(syncer::AUTOFILL, batch.get())) {
444 change_processor()->ReportError(
445 FROM_HERE, "Failed reading autofill metadata from WebDatabase.");
446 return;
447 }
448 change_processor()->OnMetadataLoaded(std::move(batch));
449 }
450
393 std::string AutocompleteSyncBridge::GetClientTag( 451 std::string AutocompleteSyncBridge::GetClientTag(
394 const EntityData& entity_data) { 452 const EntityData& entity_data) {
395 DCHECK(entity_data.specifics.has_autofill()); 453 DCHECK(entity_data.specifics.has_autofill());
396 const AutofillSpecifics specifics = entity_data.specifics.autofill(); 454 const AutofillSpecifics specifics = entity_data.specifics.autofill();
397 return std::string(kAutocompleteEntryNamespaceTag) + 455 return std::string(kAutocompleteEntryNamespaceTag) +
398 net::EscapePath(specifics.name()) + 456 net::EscapePath(specifics.name()) +
399 std::string(kAutocompleteTagDelimiter) + 457 std::string(kAutocompleteTagDelimiter) +
400 net::EscapePath(specifics.value()); 458 net::EscapePath(specifics.value());
401 } 459 }
402 460
403 std::string AutocompleteSyncBridge::GetStorageKey( 461 std::string AutocompleteSyncBridge::GetStorageKey(
404 const EntityData& entity_data) { 462 const EntityData& entity_data) {
405 DCHECK(entity_data.specifics.has_autofill()); 463 DCHECK(entity_data.specifics.has_autofill());
406 const AutofillSpecifics specifics = entity_data.specifics.autofill(); 464 const AutofillSpecifics specifics = entity_data.specifics.autofill();
407 return BuildSerializedStorageKey(specifics.name(), specifics.value()); 465 return BuildSerializedStorageKey(specifics.name(), specifics.value());
408 } 466 }
409 467
410 // AutofillWebDataServiceObserverOnDBThread implementation. 468 // AutofillWebDataServiceObserverOnDBThread implementation.
411 void AutocompleteSyncBridge::AutofillEntriesChanged( 469 void AutocompleteSyncBridge::AutofillEntriesChanged(
412 const AutofillChangeList& changes) { 470 const AutofillChangeList& changes) {
413 DCHECK(thread_checker_.CalledOnValidThread()); 471 DCHECK(thread_checker_.CalledOnValidThread());
472 ActOnLocalChanges(changes);
414 } 473 }
415 474
416 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const { 475 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const {
417 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase()); 476 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase());
418 } 477 }
419 478
420 } // namespace autofill 479 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698