| Index: chrome/browser/sync/glue/autofill_wallet_data_type_controller.cc
|
| diff --git a/chrome/browser/sync/glue/autofill_wallet_data_type_controller.cc b/chrome/browser/sync/glue/autofill_wallet_data_type_controller.cc
|
| index 5050de97ef3b4bd8f0fbf96e1daafb1077356af5..00ec1a8f2d29e74c042f55ff850037eab482a8f0 100644
|
| --- a/chrome/browser/sync/glue/autofill_wallet_data_type_controller.cc
|
| +++ b/chrome/browser/sync/glue/autofill_wallet_data_type_controller.cc
|
| @@ -5,10 +5,14 @@
|
| #include "chrome/browser/sync/glue/autofill_wallet_data_type_controller.h"
|
|
|
| #include "base/bind.h"
|
| +#include "base/prefs/pref_service.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/sync/glue/chrome_report_unrecoverable_error.h"
|
| #include "chrome/browser/sync/profile_sync_components_factory.h"
|
| +#include "chrome/browser/sync/profile_sync_service.h"
|
| +#include "chrome/browser/sync/profile_sync_service_factory.h"
|
| #include "chrome/browser/webdata/web_data_service_factory.h"
|
| +#include "chrome/common/pref_names.h"
|
| #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "sync/api/sync_error.h"
|
| @@ -27,6 +31,12 @@ AutofillWalletDataTypeController::AutofillWalletDataTypeController(
|
| profile_sync_factory),
|
| profile_(profile),
|
| callback_registered_(false) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + pref_registrar_.Init(profile->GetPrefs());
|
| + pref_registrar_.Add(
|
| + autofill::prefs::kAutofillWalletSyncExperimentEnabled,
|
| + base::Bind(&AutofillWalletDataTypeController::OnSyncExperimentPrefChanged,
|
| + base::Unretained(this)));
|
| }
|
|
|
| AutofillWalletDataTypeController::~AutofillWalletDataTypeController() {
|
| @@ -75,8 +85,40 @@ void AutofillWalletDataTypeController::StopModels() {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| }
|
|
|
| +bool AutofillWalletDataTypeController::ReadyForStart() const {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + return profile_->GetPrefs()->GetBoolean(
|
| + autofill::prefs::kAutofillWalletSyncExperimentEnabled);
|
| +}
|
| +
|
| void AutofillWalletDataTypeController::WebDatabaseLoaded() {
|
| OnModelLoaded();
|
| }
|
|
|
| +void AutofillWalletDataTypeController::OnSyncExperimentPrefChanged() {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + if (!profile_->GetPrefs()->GetBoolean(
|
| + autofill::prefs::kAutofillWalletSyncExperimentEnabled)) {
|
| + // If autofill wallet sync is disabled, post a task to the backend thread to
|
| + // stop the datatype.
|
| + if (state() != NOT_RUNNING && state() != STOPPING) {
|
| + syncer::SyncError error(FROM_HERE,
|
| + syncer::SyncError::DATATYPE_POLICY_ERROR,
|
| + "Wallet syncing is disabled by policy.",
|
| + syncer::AUTOFILL_WALLET_DATA);
|
| + PostTaskOnBackendThread(
|
| + FROM_HERE,
|
| + base::Bind(&DataTypeController::OnSingleDataTypeUnrecoverableError,
|
| + this,
|
| + error));
|
| + }
|
| + } else {
|
| + // The experiment was just enabled. Trigger a reconfiguration. This will do
|
| + // nothing if the type isn't preferred.
|
| + ProfileSyncService* sync_service =
|
| + ProfileSyncServiceFactory::GetForProfile(profile_);
|
| + sync_service->ReenableDatatype(type());
|
| + }
|
| +}
|
| +
|
| } // namespace browser_sync
|
|
|