| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 ui_thread_(ui_thread) {} | 189 ui_thread_(ui_thread) {} |
| 190 | 190 |
| 191 ~MockAutofillBackend() override {} | 191 ~MockAutofillBackend() override {} |
| 192 WebDatabase* GetDatabase() override { return web_database_; } | 192 WebDatabase* GetDatabase() override { return web_database_; } |
| 193 void AddObserver( | 193 void AddObserver( |
| 194 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {} | 194 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {} |
| 195 void RemoveObserver( | 195 void RemoveObserver( |
| 196 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {} | 196 autofill::AutofillWebDataServiceObserverOnDBThread* observer) override {} |
| 197 void RemoveExpiredFormElements() override {} | 197 void RemoveExpiredFormElements() override {} |
| 198 void NotifyOfMultipleAutofillChanges() override { | 198 void NotifyOfMultipleAutofillChanges() override { |
| 199 DCHECK(!ui_thread_->RunsTasksOnCurrentThread()); | 199 DCHECK(!ui_thread_->RunsTasksInCurrentSequence()); |
| 200 ui_thread_->PostTask(FROM_HERE, on_changed_); | 200 ui_thread_->PostTask(FROM_HERE, on_changed_); |
| 201 } | 201 } |
| 202 void NotifyThatSyncHasStarted(syncer::ModelType model_type) override { | 202 void NotifyThatSyncHasStarted(syncer::ModelType model_type) override { |
| 203 DCHECK(!ui_thread_->RunsTasksOnCurrentThread()); | 203 DCHECK(!ui_thread_->RunsTasksInCurrentSequence()); |
| 204 ui_thread_->PostTask(FROM_HERE, base::Bind(on_sync_started_, model_type)); | 204 ui_thread_->PostTask(FROM_HERE, base::Bind(on_sync_started_, model_type)); |
| 205 } | 205 } |
| 206 | 206 |
| 207 private: | 207 private: |
| 208 WebDatabase* web_database_; | 208 WebDatabase* web_database_; |
| 209 base::Closure on_changed_; | 209 base::Closure on_changed_; |
| 210 base::Callback<void(syncer::ModelType)> on_sync_started_; | 210 base::Callback<void(syncer::ModelType)> on_sync_started_; |
| 211 const scoped_refptr<base::SequencedTaskRunner> ui_thread_; | 211 const scoped_refptr<base::SequencedTaskRunner> ui_thread_; |
| 212 }; | 212 }; |
| 213 | 213 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 base::Bind(&RunAndSignal, notify_cb, &event)); | 325 base::Bind(&RunAndSignal, notify_cb, &event)); |
| 326 event.Wait(); | 326 event.Wait(); |
| 327 } | 327 } |
| 328 | 328 |
| 329 private: | 329 private: |
| 330 ~WebDataServiceFake() override {} | 330 ~WebDataServiceFake() override {} |
| 331 | 331 |
| 332 void CreateSyncableService( | 332 void CreateSyncableService( |
| 333 const base::Closure& on_changed_callback, | 333 const base::Closure& on_changed_callback, |
| 334 const base::Callback<void(syncer::ModelType)>& on_sync_started) { | 334 const base::Callback<void(syncer::ModelType)>& on_sync_started) { |
| 335 ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread()); | 335 ASSERT_TRUE(db_thread_->RunsTasksInCurrentSequence()); |
| 336 // These services are deleted in DestroySyncableService(). | 336 // These services are deleted in DestroySyncableService(). |
| 337 backend_ = base::MakeUnique<MockAutofillBackend>( | 337 backend_ = base::MakeUnique<MockAutofillBackend>( |
| 338 GetDatabase(), on_changed_callback, on_sync_started, ui_thread_.get()); | 338 GetDatabase(), on_changed_callback, on_sync_started, ui_thread_.get()); |
| 339 AutocompleteSyncableService::CreateForWebDataServiceAndBackend( | 339 AutocompleteSyncableService::CreateForWebDataServiceAndBackend( |
| 340 this, backend_.get()); | 340 this, backend_.get()); |
| 341 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend( | 341 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend( |
| 342 this, backend_.get(), "en-US"); | 342 this, backend_.get(), "en-US"); |
| 343 | 343 |
| 344 autocomplete_syncable_service_ = | 344 autocomplete_syncable_service_ = |
| 345 AutocompleteSyncableService::FromWebDataService(this); | 345 AutocompleteSyncableService::FromWebDataService(this); |
| 346 autofill_profile_syncable_service_ = | 346 autofill_profile_syncable_service_ = |
| 347 AutofillProfileSyncableService::FromWebDataService(this); | 347 AutofillProfileSyncableService::FromWebDataService(this); |
| 348 | 348 |
| 349 syncable_service_created_or_destroyed_.Signal(); | 349 syncable_service_created_or_destroyed_.Signal(); |
| 350 } | 350 } |
| 351 | 351 |
| 352 void DestroySyncableService() { | 352 void DestroySyncableService() { |
| 353 ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread()); | 353 ASSERT_TRUE(db_thread_->RunsTasksInCurrentSequence()); |
| 354 autocomplete_syncable_service_ = nullptr; | 354 autocomplete_syncable_service_ = nullptr; |
| 355 autofill_profile_syncable_service_ = nullptr; | 355 autofill_profile_syncable_service_ = nullptr; |
| 356 backend_.reset(); | 356 backend_.reset(); |
| 357 syncable_service_created_or_destroyed_.Signal(); | 357 syncable_service_created_or_destroyed_.Signal(); |
| 358 } | 358 } |
| 359 | 359 |
| 360 WebDatabase* web_database_; | 360 WebDatabase* web_database_; |
| 361 AutocompleteSyncableService* autocomplete_syncable_service_; | 361 AutocompleteSyncableService* autocomplete_syncable_service_; |
| 362 AutofillProfileSyncableService* autofill_profile_syncable_service_; | 362 AutofillProfileSyncableService* autofill_profile_syncable_service_; |
| 363 std::unique_ptr<autofill::AutofillWebDataBackend> backend_; | 363 std::unique_ptr<autofill::AutofillWebDataBackend> backend_; |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 : entry_(MakeAutofillEntry("0", "0", 0)), | 733 : entry_(MakeAutofillEntry("0", "0", 0)), |
| 734 service_(service), | 734 service_(service), |
| 735 wait_for_start_(wait_for_start), | 735 wait_for_start_(wait_for_start), |
| 736 wait_for_syncapi_(wait_for_syncapi), | 736 wait_for_syncapi_(wait_for_syncapi), |
| 737 is_finished_(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 737 is_finished_(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 738 base::WaitableEvent::InitialState::NOT_SIGNALED), | 738 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 739 db_thread_(db_thread) {} | 739 db_thread_(db_thread) {} |
| 740 | 740 |
| 741 void Update() { | 741 void Update() { |
| 742 // This gets called in a modelsafeworker thread. | 742 // This gets called in a modelsafeworker thread. |
| 743 ASSERT_TRUE(db_thread_->RunsTasksOnCurrentThread()); | 743 ASSERT_TRUE(db_thread_->RunsTasksInCurrentSequence()); |
| 744 | 744 |
| 745 syncer::UserShare* user_share = service_->GetUserShare(); | 745 syncer::UserShare* user_share = service_->GetUserShare(); |
| 746 syncer::syncable::Directory* directory = user_share->directory.get(); | 746 syncer::syncable::Directory* directory = user_share->directory.get(); |
| 747 | 747 |
| 748 // Create autofill protobuf. | 748 // Create autofill protobuf. |
| 749 std::string tag = AutocompleteSyncableService::KeyToTag( | 749 std::string tag = AutocompleteSyncableService::KeyToTag( |
| 750 base::UTF16ToUTF8(entry_.key().name()), | 750 base::UTF16ToUTF8(entry_.key().name()), |
| 751 base::UTF16ToUTF8(entry_.key().value())); | 751 base::UTF16ToUTF8(entry_.key().value())); |
| 752 sync_pb::AutofillSpecifics new_autofill; | 752 sync_pb::AutofillSpecifics new_autofill; |
| 753 new_autofill.set_name(base::UTF16ToUTF8(entry_.key().name())); | 753 new_autofill.set_name(base::UTF16ToUTF8(entry_.key().name())); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 782 item.PutId(server_item_id); | 782 item.PutId(server_item_id); |
| 783 syncer::syncable::Id new_predecessor; | 783 syncer::syncable::Id new_predecessor; |
| 784 ASSERT_TRUE(item.PutPredecessor(new_predecessor)); | 784 ASSERT_TRUE(item.PutPredecessor(new_predecessor)); |
| 785 } | 785 } |
| 786 DVLOG(1) << "FakeServerUpdater finishing."; | 786 DVLOG(1) << "FakeServerUpdater finishing."; |
| 787 is_finished_.Signal(); | 787 is_finished_.Signal(); |
| 788 } | 788 } |
| 789 | 789 |
| 790 void CreateNewEntry(const AutofillEntry& entry) { | 790 void CreateNewEntry(const AutofillEntry& entry) { |
| 791 entry_ = entry; | 791 entry_ = entry; |
| 792 ASSERT_FALSE(db_thread_->RunsTasksOnCurrentThread()); | 792 ASSERT_FALSE(db_thread_->RunsTasksInCurrentSequence()); |
| 793 if (!db_thread_->PostTask(FROM_HERE, | 793 if (!db_thread_->PostTask(FROM_HERE, |
| 794 base::Bind(&FakeServerUpdater::Update, this))) { | 794 base::Bind(&FakeServerUpdater::Update, this))) { |
| 795 NOTREACHED() << "Failed to post task to the db thread."; | 795 NOTREACHED() << "Failed to post task to the db thread."; |
| 796 return; | 796 return; |
| 797 } | 797 } |
| 798 } | 798 } |
| 799 | 799 |
| 800 void WaitForUpdateCompletion() { is_finished_.Wait(); } | 800 void WaitForUpdateCompletion() { is_finished_.Wait(); } |
| 801 | 801 |
| 802 private: | 802 private: |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1553 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); | 1553 ASSERT_TRUE(GetAutofillEntriesFromSyncDB(&sync_entries, &sync_profiles)); |
| 1554 EXPECT_EQ(3U, sync_entries.size()); | 1554 EXPECT_EQ(3U, sync_entries.size()); |
| 1555 EXPECT_EQ(0U, sync_profiles.size()); | 1555 EXPECT_EQ(0U, sync_profiles.size()); |
| 1556 for (size_t i = 0; i < sync_entries.size(); i++) { | 1556 for (size_t i = 0; i < sync_entries.size(); i++) { |
| 1557 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() << ", " | 1557 DVLOG(1) << "Entry " << i << ": " << sync_entries[i].key().name() << ", " |
| 1558 << sync_entries[i].key().value(); | 1558 << sync_entries[i].key().value(); |
| 1559 } | 1559 } |
| 1560 } | 1560 } |
| 1561 | 1561 |
| 1562 } // namespace browser_sync | 1562 } // namespace browser_sync |
| OLD | NEW |