| Index: components/autofill/core/browser/autofill_wallet_data_type_controller.cc
|
| diff --git a/chrome/browser/sync/glue/autofill_wallet_data_type_controller.cc b/components/autofill/core/browser/autofill_wallet_data_type_controller.cc
|
| similarity index 75%
|
| rename from chrome/browser/sync/glue/autofill_wallet_data_type_controller.cc
|
| rename to components/autofill/core/browser/autofill_wallet_data_type_controller.cc
|
| index 063666f8746c898c24333c8d5dc7c8e7aaf1233f..3cbf3d7fa16419a93c6091c2a755b02373f7123d 100644
|
| --- a/chrome/browser/sync/glue/autofill_wallet_data_type_controller.cc
|
| +++ b/components/autofill/core/browser/autofill_wallet_data_type_controller.cc
|
| @@ -2,36 +2,34 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/sync/glue/autofill_wallet_data_type_controller.h"
|
| +#include "components/autofill/core/browser/autofill_wallet_data_type_controller.h"
|
|
|
| #include "base/bind.h"
|
| #include "base/prefs/pref_service.h"
|
| -#include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
|
| -#include "chrome/common/pref_names.h"
|
| #include "components/autofill/core/browser/personal_data_manager.h"
|
| #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
|
| +#include "components/autofill/core/common/autofill_pref_names.h"
|
| #include "components/sync_driver/sync_client.h"
|
| #include "components/sync_driver/sync_service.h"
|
| -#include "content/public/browser/browser_thread.h"
|
| #include "sync/api/sync_error.h"
|
| #include "sync/api/syncable_service.h"
|
|
|
| -using content::BrowserThread;
|
| -
|
| namespace browser_sync {
|
|
|
| AutofillWalletDataTypeController::AutofillWalletDataTypeController(
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& db_thread,
|
| + const base::Closure& error_callback,
|
| sync_driver::SyncClient* sync_client,
|
| syncer::ModelType model_type)
|
| - : NonUIDataTypeController(
|
| - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
|
| - base::Bind(&ChromeReportUnrecoverableError),
|
| - sync_client),
|
| + : NonUIDataTypeController(ui_thread, error_callback, sync_client),
|
| + ui_thread_(ui_thread),
|
| + db_thread_(db_thread),
|
| sync_client_(sync_client),
|
| callback_registered_(false),
|
| model_type_(model_type),
|
| currently_enabled_(IsEnabled()) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + DCHECK(ui_thread_->BelongsToCurrentThread());
|
| DCHECK(model_type_ == syncer::AUTOFILL_WALLET_DATA ||
|
| model_type_ == syncer::AUTOFILL_WALLET_METADATA);
|
| pref_registrar_.Init(sync_client_->GetPrefService());
|
| @@ -45,27 +43,26 @@ AutofillWalletDataTypeController::AutofillWalletDataTypeController(
|
| base::Unretained(this)));
|
| }
|
|
|
| -AutofillWalletDataTypeController::~AutofillWalletDataTypeController() {
|
| -}
|
| +AutofillWalletDataTypeController::~AutofillWalletDataTypeController() {}
|
|
|
| syncer::ModelType AutofillWalletDataTypeController::type() const {
|
| return model_type_;
|
| }
|
|
|
| -syncer::ModelSafeGroup
|
| - AutofillWalletDataTypeController::model_safe_group() const {
|
| +syncer::ModelSafeGroup AutofillWalletDataTypeController::model_safe_group()
|
| + const {
|
| return syncer::GROUP_DB;
|
| }
|
|
|
| bool AutofillWalletDataTypeController::PostTaskOnBackendThread(
|
| const tracked_objects::Location& from_here,
|
| const base::Closure& task) {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| - return BrowserThread::PostTask(BrowserThread::DB, from_here, task);
|
| + DCHECK(ui_thread_->BelongsToCurrentThread());
|
| + return db_thread_->PostTask(from_here, task);
|
| }
|
|
|
| bool AutofillWalletDataTypeController::StartModels() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + DCHECK(ui_thread_->BelongsToCurrentThread());
|
| DCHECK_EQ(state(), MODEL_STARTING);
|
|
|
| scoped_refptr<autofill::AutofillWebDataService> web_data_service =
|
| @@ -78,16 +75,16 @@ bool AutofillWalletDataTypeController::StartModels() {
|
| return true;
|
|
|
| if (!callback_registered_) {
|
| - web_data_service->RegisterDBLoadedCallback(base::Bind(
|
| - &AutofillWalletDataTypeController::OnModelLoaded, this));
|
| - callback_registered_ = true;
|
| + web_data_service->RegisterDBLoadedCallback(
|
| + base::Bind(&AutofillWalletDataTypeController::OnModelLoaded, this));
|
| + callback_registered_ = true;
|
| }
|
|
|
| return false;
|
| }
|
|
|
| void AutofillWalletDataTypeController::StopModels() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| // This function is called when shutting down (nothing is changing), when
|
| // sync is disabled completely, or when wallet sync is disabled. In the
|
| @@ -102,8 +99,7 @@ void AutofillWalletDataTypeController::StopModels() {
|
| // currently_enabled_ indicates if the other prefs are enabled. All of these
|
| // have to be enabled to sync wallet data/metadata.
|
| if (!service->HasSyncSetupCompleted() ||
|
| - !service->GetPreferredDataTypes().Has(type()) ||
|
| - !currently_enabled_) {
|
| + !service->GetPreferredDataTypes().Has(type()) || !currently_enabled_) {
|
| autofill::PersonalDataManager* pdm = sync_client_->GetPersonalDataManager();
|
| if (pdm)
|
| pdm->ClearAllServerData();
|
| @@ -111,12 +107,12 @@ void AutofillWalletDataTypeController::StopModels() {
|
| }
|
|
|
| bool AutofillWalletDataTypeController::ReadyForStart() const {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + DCHECK(ui_thread_->BelongsToCurrentThread());
|
| return currently_enabled_;
|
| }
|
|
|
| void AutofillWalletDataTypeController::OnSyncPrefChanged() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| bool new_enabled = IsEnabled();
|
| if (currently_enabled_ == new_enabled)
|
| @@ -136,23 +132,21 @@ void AutofillWalletDataTypeController::OnSyncPrefChanged() {
|
| base::Bind(&DataTypeController::OnSingleDataTypeUnrecoverableError,
|
| this,
|
| syncer::SyncError(
|
| - FROM_HERE,
|
| - syncer::SyncError::DATATYPE_POLICY_ERROR,
|
| - "Wallet syncing is disabled by policy.",
|
| - type())));
|
| + FROM_HERE, syncer::SyncError::DATATYPE_POLICY_ERROR,
|
| + "Wallet syncing is disabled by policy.", type())));
|
| }
|
| }
|
| }
|
|
|
| bool AutofillWalletDataTypeController::IsEnabled() {
|
| - DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
| + DCHECK(ui_thread_->BelongsToCurrentThread());
|
|
|
| // Require both the sync experiment and the user-visible pref to be
|
| // enabled to sync Wallet data/metadata.
|
| PrefService* ps = sync_client_->GetPrefService();
|
| - return
|
| - ps->GetBoolean(autofill::prefs::kAutofillWalletSyncExperimentEnabled) &&
|
| - ps->GetBoolean(autofill::prefs::kAutofillWalletImportEnabled);
|
| + return ps->GetBoolean(
|
| + autofill::prefs::kAutofillWalletSyncExperimentEnabled) &&
|
| + ps->GetBoolean(autofill::prefs::kAutofillWalletImportEnabled);
|
| }
|
|
|
| } // namespace browser_sync
|
|
|