Chromium Code Reviews| 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..595fe6549b45bd57805ef1c9e53f55b5f396016c 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,11 @@ AutofillWalletDataTypeController::AutofillWalletDataTypeController( |
| profile_sync_factory), |
| profile_(profile), |
| callback_registered_(false) { |
| + pref_registrar_.Init(profile->GetPrefs()); |
|
maniscalco
2015/03/25 00:31:47
We're on the UI thread here, right? How about add
Nicolas Zea
2015/03/25 00:41:16
Done.
|
| + pref_registrar_.Add( |
| + autofill::prefs::kAutofillWalletSyncExperimentEnabled, |
| + base::Bind(&AutofillWalletDataTypeController::OnSyncExperimentPrefChanged, |
| + base::Unretained(this))); |
| } |
| AutofillWalletDataTypeController::~AutofillWalletDataTypeController() { |
| @@ -75,8 +84,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 |