Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 batch->Put(key, CreateEntityData(entry)); | 387 batch->Put(key, CreateEntityData(entry)); |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 callback.Run(std::move(batch)); | 390 callback.Run(std::move(batch)); |
| 391 } | 391 } |
| 392 | 392 |
| 393 void AutocompleteSyncBridge::GetAllData(DataCallback callback) { | 393 void AutocompleteSyncBridge::GetAllData(DataCallback callback) { |
| 394 DCHECK(thread_checker_.CalledOnValidThread()); | 394 DCHECK(thread_checker_.CalledOnValidThread()); |
| 395 | 395 |
| 396 std::vector<AutofillEntry> entries; | 396 std::vector<AutofillEntry> entries; |
| 397 if (!GetAutofillTable()->GetAllAutofillEntries(&entries)) { | 397 if (!GetAutofillTable()->GetAllAutofillEntries(&entries)) { |
|
skym
2017/05/08 22:22:12
We're still going to crash if the user goes to chr
Patrick Noland
2017/05/08 22:36:33
When I tested this, sync-internals didn't crash. T
| |
| 398 change_processor()->ReportError(FROM_HERE, | 398 change_processor()->ReportError(FROM_HERE, |
| 399 "Failed to load entries from table."); | 399 "Failed to load entries from table."); |
| 400 return; | 400 return; |
| 401 } | 401 } |
| 402 | 402 |
| 403 auto batch = base::MakeUnique<MutableDataBatch>(); | 403 auto batch = base::MakeUnique<MutableDataBatch>(); |
| 404 for (const AutofillEntry& entry : entries) { | 404 for (const AutofillEntry& entry : entries) { |
| 405 batch->Put(GetStorageKeyFromModel(entry.key()), CreateEntityData(entry)); | 405 batch->Put(GetStorageKeyFromModel(entry.key()), CreateEntityData(entry)); |
| 406 } | 406 } |
| 407 callback.Run(std::move(batch)); | 407 callback.Run(std::move(batch)); |
| 408 } | 408 } |
| 409 | 409 |
| 410 void AutocompleteSyncBridge::ActOnLocalChanges( | 410 void AutocompleteSyncBridge::ActOnLocalChanges( |
|
skym
2017/05/08 22:22:12
Presumably this will never get called if the db is
Patrick Noland
2017/05/08 22:36:33
When I tested, this was never called if the db was
| |
| 411 const AutofillChangeList& changes) { | 411 const AutofillChangeList& changes) { |
| 412 if (!change_processor()->IsTrackingMetadata()) { | 412 if (!change_processor()->IsTrackingMetadata()) { |
| 413 return; | 413 return; |
| 414 } | 414 } |
| 415 | 415 |
| 416 auto metadata_change_list = | 416 auto metadata_change_list = |
| 417 base::MakeUnique<syncer::SyncMetadataStoreChangeList>(GetAutofillTable(), | 417 base::MakeUnique<syncer::SyncMetadataStoreChangeList>(GetAutofillTable(), |
| 418 syncer::AUTOFILL); | 418 syncer::AUTOFILL); |
| 419 for (const auto& change : changes) { | 419 for (const auto& change : changes) { |
| 420 const std::string storage_key = GetStorageKeyFromModel(change.key()); | 420 const std::string storage_key = GetStorageKeyFromModel(change.key()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 441 break; | 441 break; |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 | 445 |
| 446 if (Optional<ModelError> error = metadata_change_list->TakeError()) | 446 if (Optional<ModelError> error = metadata_change_list->TakeError()) |
| 447 change_processor()->ReportError(error.value()); | 447 change_processor()->ReportError(error.value()); |
| 448 } | 448 } |
| 449 | 449 |
| 450 void AutocompleteSyncBridge::LoadMetadata() { | 450 void AutocompleteSyncBridge::LoadMetadata() { |
| 451 auto batch = base::MakeUnique<syncer::MetadataBatch>(); | 451 auto batch = base::MakeUnique<syncer::MetadataBatch>(); |
|
skym
2017/05/08 22:22:13
Why make the batch first?
Patrick Noland
2017/05/08 22:36:33
Done.
| |
| 452 if (!web_data_backend_ || !web_data_backend_->GetDatabase() || | |
| 453 !GetAutofillTable()) { | |
| 454 change_processor()->ReportError(FROM_HERE, | |
| 455 "Failed to load AutofillWebDatabase."); | |
| 456 return; | |
| 457 } | |
| 458 | |
| 452 if (!GetAutofillTable()->GetAllSyncMetadata(syncer::AUTOFILL, batch.get())) { | 459 if (!GetAutofillTable()->GetAllSyncMetadata(syncer::AUTOFILL, batch.get())) { |
| 453 change_processor()->ReportError( | 460 change_processor()->ReportError( |
| 454 FROM_HERE, "Failed reading autofill metadata from WebDatabase."); | 461 FROM_HERE, "Failed reading autofill metadata from WebDatabase."); |
| 455 return; | 462 return; |
| 456 } | 463 } |
| 457 change_processor()->ModelReadyToSync(std::move(batch)); | 464 change_processor()->ModelReadyToSync(std::move(batch)); |
| 458 } | 465 } |
| 459 | 466 |
| 460 std::string AutocompleteSyncBridge::GetClientTag( | 467 std::string AutocompleteSyncBridge::GetClientTag( |
| 461 const EntityData& entity_data) { | 468 const EntityData& entity_data) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 482 const AutofillChangeList& changes) { | 489 const AutofillChangeList& changes) { |
| 483 DCHECK(thread_checker_.CalledOnValidThread()); | 490 DCHECK(thread_checker_.CalledOnValidThread()); |
| 484 ActOnLocalChanges(changes); | 491 ActOnLocalChanges(changes); |
| 485 } | 492 } |
| 486 | 493 |
| 487 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const { | 494 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const { |
| 488 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase()); | 495 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase()); |
| 489 } | 496 } |
| 490 | 497 |
| 491 } // namespace autofill | 498 } // namespace autofill |
| OLD | NEW |