Commit 488523c5 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Sync: Introduce AutofillProfileModelTypeController

This is the USS version of AutofillProfileDataTypeController. It is very
similar to AutofillWalletModelTypeController, and only implements one
bit of custom logic: Notifying the SyncService when
autofill::prefs::kAutofillProfileEnabled changes, so that syncing of
addresses will get turned on or off as appropriate.

Bug: 895824
Change-Id: I932794f8a2d1c3556bdc1b7125743a2154eaf997
Reviewed-on: https://chromium-review.googlesource.com/c/1310393
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605298}
parent 0836c5e7
......@@ -181,6 +181,8 @@ jumbo_static_library("browser") {
"webdata/autofill_entry.h",
"webdata/autofill_profile_data_type_controller.cc",
"webdata/autofill_profile_data_type_controller.h",
"webdata/autofill_profile_model_type_controller.cc",
"webdata/autofill_profile_model_type_controller.h",
"webdata/autofill_profile_sync_bridge.cc",
"webdata/autofill_profile_sync_bridge.h",
"webdata/autofill_profile_sync_difference_tracker.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/autofill/core/browser/webdata/autofill_profile_model_type_controller.h"
#include <utility>
#include "base/bind.h"
#include "components/autofill/core/common/autofill_prefs.h"
#include "components/prefs/pref_service.h"
#include "components/sync/driver/sync_client.h"
#include "components/sync/driver/sync_service.h"
namespace browser_sync {
AutofillProfileModelTypeController::AutofillProfileModelTypeController(
std::unique_ptr<syncer::ModelTypeControllerDelegate> delegate_on_disk,
syncer::SyncClient* sync_client)
: ModelTypeController(syncer::AUTOFILL_PROFILE,
std::move(delegate_on_disk)),
sync_client_(sync_client),
currently_enabled_(IsEnabled()) {
pref_registrar_.Init(sync_client_->GetPrefService());
pref_registrar_.Add(
autofill::prefs::kAutofillProfileEnabled,
base::BindRepeating(
&AutofillProfileModelTypeController::OnUserPrefChanged,
base::Unretained(this)));
}
AutofillProfileModelTypeController::~AutofillProfileModelTypeController() =
default;
bool AutofillProfileModelTypeController::ReadyForStart() const {
DCHECK(CalledOnValidThread());
return currently_enabled_;
}
void AutofillProfileModelTypeController::OnUserPrefChanged() {
DCHECK(CalledOnValidThread());
bool new_enabled = IsEnabled();
if (currently_enabled_ == new_enabled)
return;
currently_enabled_ = new_enabled;
sync_client_->GetSyncService()->ReadyForStartChanged(type());
}
bool AutofillProfileModelTypeController::IsEnabled() {
DCHECK(CalledOnValidThread());
// Require the user-visible pref to be enabled to sync Autofill Profile data.
return autofill::prefs::IsProfileAutofillEnabled(
sync_client_->GetPrefService());
}
} // namespace browser_sync
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_PROFILE_MODEL_TYPE_CONTROLLER_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_PROFILE_MODEL_TYPE_CONTROLLER_H_
#include <memory>
#include "base/macros.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/sync/driver/model_type_controller.h"
namespace syncer {
class ModelTypeControllerDelegate;
class SyncClient;
} // namespace syncer
namespace browser_sync {
// Controls syncing of the AUTOFILL_PROFILE data type.
class AutofillProfileModelTypeController : public syncer::ModelTypeController {
public:
AutofillProfileModelTypeController(
std::unique_ptr<syncer::ModelTypeControllerDelegate> delegate_on_disk,
syncer::SyncClient* sync_client);
~AutofillProfileModelTypeController() override;
// DataTypeController overrides.
bool ReadyForStart() const override;
private:
// Callback for changes to the autofill pref.
void OnUserPrefChanged();
// Returns true if the pref is set such that autofill sync should be enabled.
bool IsEnabled();
syncer::SyncClient* const sync_client_;
// Registrar for listening to prefs::kAutofillProfileEnabled.
PrefChangeRegistrar pref_registrar_;
// Stores whether we're currently syncing autofill data. This is the last
// value computed by IsEnabled.
bool currently_enabled_;
DISALLOW_COPY_AND_ASSIGN(AutofillProfileModelTypeController);
};
} // namespace browser_sync
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_PROFILE_MODEL_TYPE_CONTROLLER_H_
......@@ -14,6 +14,7 @@
#include "components/autofill/core/browser/autofill_wallet_model_type_controller.h"
#include "components/autofill/core/browser/webdata/autocomplete_sync_bridge.h"
#include "components/autofill/core/browser/webdata/autofill_profile_data_type_controller.h"
#include "components/autofill/core/browser/webdata/autofill_profile_model_type_controller.h"
#include "components/autofill/core/browser/webdata/autofill_profile_sync_bridge.h"
#include "components/autofill/core/browser/webdata/autofill_wallet_metadata_sync_bridge.h"
#include "components/autofill/core/browser/webdata/autofill_wallet_sync_bridge.h"
......@@ -152,18 +153,26 @@ ProfileSyncComponentsFactoryImpl::CreateCommonDataTypeControllers(
// Autocomplete sync is enabled by default. Register unless explicitly
// disabled.
if (!disabled_types.Has(syncer::AUTOFILL)) {
controllers.push_back(CreateWebDataModelTypeController(
controllers.push_back(std::make_unique<ModelTypeController>(
syncer::AUTOFILL,
base::BindRepeating(&AutocompleteDelegateFromDataService)));
std::make_unique<syncer::ProxyModelTypeControllerDelegate>(
db_thread_, base::BindRepeating(
&AutocompleteDelegateFromDataService,
base::RetainedRef(web_data_service_on_disk_)))));
}
// Autofill sync is enabled by default. Register unless explicitly
// disabled.
if (!disabled_types.Has(syncer::AUTOFILL_PROFILE)) {
if (FeatureList::IsEnabled(switches::kSyncUSSAutofillProfile)) {
controllers.push_back(CreateWebDataModelTypeController(
syncer::AUTOFILL_PROFILE,
base::BindRepeating(&AutofillProfileDelegateFromDataService)));
controllers.push_back(
std::make_unique<AutofillProfileModelTypeController>(
std::make_unique<syncer::ProxyModelTypeControllerDelegate>(
db_thread_,
base::BindRepeating(
&AutofillProfileDelegateFromDataService,
base::RetainedRef(web_data_service_on_disk_))),
sync_client_));
} else {
controllers.push_back(
std::make_unique<AutofillProfileDataTypeController>(
......@@ -481,19 +490,6 @@ std::unique_ptr<ModelTypeController> ProfileSyncComponentsFactoryImpl::
base::Unretained(sync_client_), type)));
}
std::unique_ptr<ModelTypeController>
ProfileSyncComponentsFactoryImpl::CreateWebDataModelTypeController(
syncer::ModelType type,
const base::RepeatingCallback<
base::WeakPtr<syncer::ModelTypeControllerDelegate>(
autofill::AutofillWebDataService*)>& delegate_from_web_data) {
return std::make_unique<ModelTypeController>(
type, std::make_unique<syncer::ProxyModelTypeControllerDelegate>(
db_thread_, base::BindRepeating(
delegate_from_web_data,
base::RetainedRef(web_data_service_on_disk_))));
}
std::unique_ptr<ModelTypeController>
ProfileSyncComponentsFactoryImpl::CreateWalletModelTypeController(
syncer::ModelType type,
......
......@@ -87,23 +87,16 @@ class ProfileSyncComponentsFactoryImpl
std::unique_ptr<syncer::ModelTypeController>
CreateModelTypeControllerForModelRunningOnUIThread(syncer::ModelType type);
// Factory function for ModelTypeController instances for autofill-related
// datatypes, which live in |db_thread_| and have a delegate accesible via
// Factory function for ModelTypeController instances for wallet-related
// datatypes, which live in |db_thread_| and have a delegate accessible via
// AutofillWebDataService.
std::unique_ptr<syncer::ModelTypeController> CreateWebDataModelTypeController(
syncer::ModelType type,
const base::RepeatingCallback<
base::WeakPtr<syncer::ModelTypeControllerDelegate>(
autofill::AutofillWebDataService*)>& delegate_from_web_data);
// Same as above, but for AUTOFILL_WALLET_* datatypes.
std::unique_ptr<syncer::ModelTypeController> CreateWalletModelTypeController(
syncer::ModelType type,
const base::RepeatingCallback<
base::WeakPtr<syncer::ModelTypeControllerDelegate>(
autofill::AutofillWebDataService*)>& delegate_from_web_data);
// Same as above, but datatypes supporting STORAGE_IN_MEMORY implemented
// as an independent AutofillWebDataService, namely
// |web_data_service_in_memory_|.
// Same as above, but supporting STORAGE_IN_MEMORY implemented as an
// independent AutofillWebDataService, namely |web_data_service_in_memory_|.
std::unique_ptr<syncer::ModelTypeController>
CreateWalletModelTypeControllerWithInMemorySupport(
syncer::ModelType type,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment