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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/debug/dump_without_crashing.h" | 14 #include "base/debug/dump_without_crashing.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "components/autofill/core/browser/proto/autofill_sync.pb.h" | 17 #include "components/autofill/core/browser/proto/autofill_sync.pb.h" |
18 #include "components/autofill/core/browser/webdata/autofill_metadata_change_list
.h" | |
19 #include "components/autofill/core/browser/webdata/autofill_table.h" | 18 #include "components/autofill/core/browser/webdata/autofill_table.h" |
20 #include "components/autofill/core/browser/webdata/autofill_webdata_backend.h" | 19 #include "components/autofill/core/browser/webdata/autofill_webdata_backend.h" |
21 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 20 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
22 #include "components/sync/model/entity_data.h" | 21 #include "components/sync/model/entity_data.h" |
23 #include "components/sync/model/model_type_change_processor.h" | 22 #include "components/sync/model/model_type_change_processor.h" |
24 #include "components/sync/model/mutable_data_batch.h" | 23 #include "components/sync/model/mutable_data_batch.h" |
| 24 #include "components/sync/model_impl/sync_metadata_store_change_list.h" |
25 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
26 | 26 |
27 using base::Optional; | 27 using base::Optional; |
28 using base::Time; | 28 using base::Time; |
29 using base::debug::DumpWithoutCrashing; | 29 using base::debug::DumpWithoutCrashing; |
30 using sync_pb::AutofillSpecifics; | 30 using sync_pb::AutofillSpecifics; |
31 using syncer::EntityChange; | 31 using syncer::EntityChange; |
32 using syncer::EntityChangeList; | 32 using syncer::EntityChangeList; |
33 using syncer::EntityData; | 33 using syncer::EntityData; |
34 using syncer::EntityDataMap; | 34 using syncer::EntityDataMap; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // calling IncorporateRemoteDelete, while only MergeSyncData should be | 209 // calling IncorporateRemoteDelete, while only MergeSyncData should be |
210 // passing in true for |include_local_only|. If this requirement | 210 // passing in true for |include_local_only|. If this requirement |
211 // changes, this DCHECK can change to act as a filter. | 211 // changes, this DCHECK can change to act as a filter. |
212 DCHECK(delete_from_local_.find(entry.key()) == | 212 DCHECK(delete_from_local_.find(entry.key()) == |
213 delete_from_local_.end()); | 213 delete_from_local_.end()); |
214 change_processor->Put(GetStorageKeyFromModel(entry.key()), | 214 change_processor->Put(GetStorageKeyFromModel(entry.key()), |
215 CreateEntityData(entry), | 215 CreateEntityData(entry), |
216 metadata_change_list.get()); | 216 metadata_change_list.get()); |
217 } | 217 } |
218 } | 218 } |
219 return static_cast<AutofillMetadataChangeList*>(metadata_change_list.get()) | 219 return static_cast<syncer::SyncMetadataStoreChangeList*>( |
| 220 metadata_change_list.get()) |
220 ->TakeError(); | 221 ->TakeError(); |
221 } | 222 } |
222 | 223 |
223 private: | 224 private: |
224 // There are three major outcomes of this method. | 225 // There are three major outcomes of this method. |
225 // 1. An error is encountered reading from the db, false is returned. | 226 // 1. An error is encountered reading from the db, false is returned. |
226 // 2. The entry is not found, |entry| will not be touched. | 227 // 2. The entry is not found, |entry| will not be touched. |
227 // 3. The entry is found, |entry| will be set. | 228 // 3. The entry is found, |entry| will be set. |
228 bool ReadEntry(const AutofillKey& key, Optional<AutofillEntry>* entry) { | 229 bool ReadEntry(const AutofillKey& key, Optional<AutofillEntry>* entry) { |
229 if (!InitializeIfNeeded()) { | 230 if (!InitializeIfNeeded()) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 LoadMetadata(); | 313 LoadMetadata(); |
313 } | 314 } |
314 | 315 |
315 AutocompleteSyncBridge::~AutocompleteSyncBridge() { | 316 AutocompleteSyncBridge::~AutocompleteSyncBridge() { |
316 DCHECK(thread_checker_.CalledOnValidThread()); | 317 DCHECK(thread_checker_.CalledOnValidThread()); |
317 } | 318 } |
318 | 319 |
319 std::unique_ptr<MetadataChangeList> | 320 std::unique_ptr<MetadataChangeList> |
320 AutocompleteSyncBridge::CreateMetadataChangeList() { | 321 AutocompleteSyncBridge::CreateMetadataChangeList() { |
321 DCHECK(thread_checker_.CalledOnValidThread()); | 322 DCHECK(thread_checker_.CalledOnValidThread()); |
322 return base::MakeUnique<AutofillMetadataChangeList>(GetAutofillTable(), | 323 return base::MakeUnique<syncer::SyncMetadataStoreChangeList>( |
323 syncer::AUTOFILL); | 324 GetAutofillTable(), syncer::AUTOFILL); |
324 } | 325 } |
325 | 326 |
326 Optional<syncer::ModelError> AutocompleteSyncBridge::MergeSyncData( | 327 Optional<syncer::ModelError> AutocompleteSyncBridge::MergeSyncData( |
327 std::unique_ptr<MetadataChangeList> metadata_change_list, | 328 std::unique_ptr<MetadataChangeList> metadata_change_list, |
328 EntityDataMap entity_data_map) { | 329 EntityDataMap entity_data_map) { |
329 DCHECK(thread_checker_.CalledOnValidThread()); | 330 DCHECK(thread_checker_.CalledOnValidThread()); |
330 | 331 |
331 SyncDifferenceTracker tracker(GetAutofillTable()); | 332 SyncDifferenceTracker tracker(GetAutofillTable()); |
332 for (auto kv : entity_data_map) { | 333 for (auto kv : entity_data_map) { |
333 DCHECK(kv.second->specifics.has_autofill()); | 334 DCHECK(kv.second->specifics.has_autofill()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 } | 406 } |
406 callback.Run(std::move(batch)); | 407 callback.Run(std::move(batch)); |
407 } | 408 } |
408 | 409 |
409 void AutocompleteSyncBridge::ActOnLocalChanges( | 410 void AutocompleteSyncBridge::ActOnLocalChanges( |
410 const AutofillChangeList& changes) { | 411 const AutofillChangeList& changes) { |
411 if (!change_processor()->IsTrackingMetadata()) { | 412 if (!change_processor()->IsTrackingMetadata()) { |
412 return; | 413 return; |
413 } | 414 } |
414 | 415 |
415 auto metadata_change_list = base::MakeUnique<AutofillMetadataChangeList>( | 416 auto metadata_change_list = |
416 GetAutofillTable(), syncer::AUTOFILL); | 417 base::MakeUnique<syncer::SyncMetadataStoreChangeList>(GetAutofillTable(), |
| 418 syncer::AUTOFILL); |
417 for (const auto& change : changes) { | 419 for (const auto& change : changes) { |
418 const std::string storage_key = GetStorageKeyFromModel(change.key()); | 420 const std::string storage_key = GetStorageKeyFromModel(change.key()); |
419 switch (change.type()) { | 421 switch (change.type()) { |
420 case AutofillChange::ADD: | 422 case AutofillChange::ADD: |
421 case AutofillChange::UPDATE: { | 423 case AutofillChange::UPDATE: { |
422 base::Time date_created, date_last_used; | 424 base::Time date_created, date_last_used; |
423 bool success = GetAutofillTable()->GetAutofillTimestamps( | 425 bool success = GetAutofillTable()->GetAutofillTimestamps( |
424 change.key().name(), change.key().value(), &date_created, | 426 change.key().name(), change.key().value(), &date_created, |
425 &date_last_used); | 427 &date_last_used); |
426 if (!success) { | 428 if (!success) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 const AutofillChangeList& changes) { | 482 const AutofillChangeList& changes) { |
481 DCHECK(thread_checker_.CalledOnValidThread()); | 483 DCHECK(thread_checker_.CalledOnValidThread()); |
482 ActOnLocalChanges(changes); | 484 ActOnLocalChanges(changes); |
483 } | 485 } |
484 | 486 |
485 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const { | 487 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const { |
486 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase()); | 488 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase()); |
487 } | 489 } |
488 | 490 |
489 } // namespace autofill | 491 } // namespace autofill |
OLD | NEW |