Commit 7e9c0c4a authored by Siyu An's avatar Siyu An Committed by Commit Bot

[Autofill Offer] Introduce skeleton of autofill_wallet_offer_sync_bridge

Introduced the skeleton of the new autofill offer sync bridge.
Will add more to it in the following CLs.

The offer data and the wallet credit card data now will controlled by
the same toggle in the Chrome sync settings page. Therefore the sync
logic will be almost same. So reuse the current model type controller.

Bug: 1112095
Change-Id: I7464dde02b84f0a020f262c5453e8ac4a067edfe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2365854Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Commit-Queue: Siyu An <siyua@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800561}
parent c033b411
......@@ -280,6 +280,8 @@ static_library("browser") {
"webdata/autofill_table_encryptor_factory.h",
"webdata/autofill_wallet_metadata_sync_bridge.cc",
"webdata/autofill_wallet_metadata_sync_bridge.h",
"webdata/autofill_wallet_offer_sync_bridge.cc",
"webdata/autofill_wallet_offer_sync_bridge.h",
"webdata/autofill_wallet_sync_bridge.cc",
"webdata/autofill_wallet_sync_bridge.h",
"webdata/autofill_webdata_backend.h",
......
......@@ -38,7 +38,8 @@ AutofillWalletModelTypeController::AutofillWalletModelTypeController(
pref_service_(pref_service),
sync_service_(sync_service) {
DCHECK(type == syncer::AUTOFILL_WALLET_DATA ||
type == syncer::AUTOFILL_WALLET_METADATA);
type == syncer::AUTOFILL_WALLET_METADATA ||
type == syncer::AUTOFILL_WALLET_OFFER);
SubscribeToPrefChanges();
// TODO(crbug.com/906995): remove this observing mechanism once all sync
// datatypes are stopped by ProfileSyncService, when sync is paused.
......@@ -59,7 +60,8 @@ AutofillWalletModelTypeController::AutofillWalletModelTypeController(
pref_service_(pref_service),
sync_service_(sync_service) {
DCHECK(type == syncer::AUTOFILL_WALLET_DATA ||
type == syncer::AUTOFILL_WALLET_METADATA);
type == syncer::AUTOFILL_WALLET_METADATA ||
type == syncer::AUTOFILL_WALLET_OFFER);
SubscribeToPrefChanges();
// TODO(crbug.com/906995): remove this observing mechanism once all sync
// datatypes are stopped by ProfileSyncService, when sync is paused.
......@@ -76,8 +78,8 @@ void AutofillWalletModelTypeController::Stop(
DCHECK(CalledOnValidThread());
switch (shutdown_reason) {
case syncer::STOP_SYNC:
// Special case: For AUTOFILL_WALLET_DATA and AUTOFILL_WALLET_METADATA, we
// want to clear all data even when Sync is stopped temporarily.
// Special case: For Wallet-related data types, we want to clear all data
// even when Sync is stopped temporarily.
shutdown_reason = syncer::DISABLE_SYNC;
break;
case syncer::DISABLE_SYNC:
......
// Copyright 2020 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_wallet_offer_sync_bridge.h"
#include <utility>
#include "base/logging.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/sync/model_impl/client_tag_based_model_type_processor.h"
namespace autofill {
namespace {
// Address to this variable used as the user data key.
static int kAutofillWalletOfferSyncBridgeUserDataKey = 0;
} // namespace
// static
void AutofillWalletOfferSyncBridge::CreateForWebDataServiceAndBackend(
AutofillWebDataBackend* web_data_backend,
AutofillWebDataService* web_data_service) {
web_data_service->GetDBUserData()->SetUserData(
&kAutofillWalletOfferSyncBridgeUserDataKey,
std::make_unique<AutofillWalletOfferSyncBridge>(
std::make_unique<syncer::ClientTagBasedModelTypeProcessor>(
syncer::AUTOFILL_WALLET_OFFER,
/*dump_stack=*/base::RepeatingClosure())));
}
// static
syncer::ModelTypeSyncBridge* AutofillWalletOfferSyncBridge::FromWebDataService(
AutofillWebDataService* web_data_service) {
return static_cast<AutofillWalletOfferSyncBridge*>(
web_data_service->GetDBUserData()->GetUserData(
&kAutofillWalletOfferSyncBridgeUserDataKey));
}
AutofillWalletOfferSyncBridge::AutofillWalletOfferSyncBridge(
std::unique_ptr<syncer::ModelTypeChangeProcessor> change_processor)
: ModelTypeSyncBridge(std::move(change_processor)) {}
AutofillWalletOfferSyncBridge::~AutofillWalletOfferSyncBridge() = default;
std::unique_ptr<syncer::MetadataChangeList>
AutofillWalletOfferSyncBridge::CreateMetadataChangeList() {
NOTIMPLEMENTED();
return nullptr;
}
base::Optional<syncer::ModelError> AutofillWalletOfferSyncBridge::MergeSyncData(
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
syncer::EntityChangeList entity_data) {
NOTIMPLEMENTED();
return base::nullopt;
}
base::Optional<syncer::ModelError>
AutofillWalletOfferSyncBridge::ApplySyncChanges(
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
syncer::EntityChangeList entity_data) {
NOTIMPLEMENTED();
return base::nullopt;
}
void AutofillWalletOfferSyncBridge::GetData(StorageKeyList storage_keys,
DataCallback callback) {
NOTIMPLEMENTED();
}
void AutofillWalletOfferSyncBridge::GetAllDataForDebugging(
DataCallback callback) {
NOTIMPLEMENTED();
}
std::string AutofillWalletOfferSyncBridge::GetClientTag(
const syncer::EntityData& entity_data) {
NOTIMPLEMENTED();
return "";
}
std::string AutofillWalletOfferSyncBridge::GetStorageKey(
const syncer::EntityData& entity_data) {
NOTIMPLEMENTED();
return "";
}
bool AutofillWalletOfferSyncBridge::SupportsIncrementalUpdates() const {
return false;
}
void AutofillWalletOfferSyncBridge::ApplyStopSyncChanges(
std::unique_ptr<syncer::MetadataChangeList> delete_metadata_change_list) {
NOTIMPLEMENTED();
}
} // namespace autofill
// Copyright 2020 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_WALLET_OFFER_SYNC_BRIDGE_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WALLET_OFFER_SYNC_BRIDGE_H_
#include <memory>
#include <string>
#include "base/supports_user_data.h"
#include "components/sync/model/metadata_change_list.h"
#include "components/sync/model/model_error.h"
#include "components/sync/model/model_type_change_processor.h"
#include "components/sync/model/model_type_sync_bridge.h"
namespace autofill {
class AutofillWebDataBackend;
class AutofillWebDataService;
// Sync bridge responsible for applying remote changes of offer data to the
// local database.
class AutofillWalletOfferSyncBridge : public base::SupportsUserData::Data,
public syncer::ModelTypeSyncBridge {
public:
// Factory method that hides dealing with change_processor and also stores the
// created bridge within |web_data_service|. This method should only be
// called on |web_data_service|'s DB thread.
static void CreateForWebDataServiceAndBackend(
AutofillWebDataBackend* webdata_backend,
AutofillWebDataService* web_data_service);
static syncer::ModelTypeSyncBridge* FromWebDataService(
AutofillWebDataService* web_data_service);
explicit AutofillWalletOfferSyncBridge(
std::unique_ptr<syncer::ModelTypeChangeProcessor> change_processor);
~AutofillWalletOfferSyncBridge() override;
AutofillWalletOfferSyncBridge(const AutofillWalletOfferSyncBridge&) = delete;
AutofillWalletOfferSyncBridge& operator=(
const AutofillWalletOfferSyncBridge&) = delete;
// ModelTypeSyncBridge
std::unique_ptr<syncer::MetadataChangeList> CreateMetadataChangeList()
override;
base::Optional<syncer::ModelError> MergeSyncData(
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
syncer::EntityChangeList entity_data) override;
base::Optional<syncer::ModelError> ApplySyncChanges(
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
syncer::EntityChangeList entity_changes) override;
void GetData(StorageKeyList storage_keys, DataCallback callback) override;
void GetAllDataForDebugging(DataCallback callback) override;
std::string GetClientTag(const syncer::EntityData& entity_data) override;
std::string GetStorageKey(const syncer::EntityData& entity_data) override;
bool SupportsIncrementalUpdates() const override;
void ApplyStopSyncChanges(std::unique_ptr<syncer::MetadataChangeList>
delete_metadata_change_list) override;
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WALLET_OFFER_SYNC_BRIDGE_H_
......@@ -15,6 +15,7 @@
#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_offer_sync_bridge.h"
#include "components/autofill/core/browser/webdata/autofill_wallet_sync_bridge.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/browser_sync/browser_sync_client.h"
......@@ -95,6 +96,14 @@ AutofillWalletMetadataDelegateFromDataService(
->GetControllerDelegate();
}
base::WeakPtr<syncer::ModelTypeControllerDelegate>
AutofillWalletOfferDelegateFromDataService(
autofill::AutofillWebDataService* service) {
return autofill::AutofillWalletOfferSyncBridge::FromWebDataService(service)
->change_processor()
->GetControllerDelegate();
}
} // namespace
ProfileSyncComponentsFactoryImpl::ProfileSyncComponentsFactoryImpl(
......@@ -201,6 +210,19 @@ ProfileSyncComponentsFactoryImpl::CreateCommonDataTypeControllers(
base::BindRepeating(&AutofillWalletMetadataDelegateFromDataService),
sync_service));
}
// Wallet offer data is enabled by default. Register unless explicitly
// disabled.
// TODO(crbug.com/1112095): Currently the offer data depends on Wallet data
// sync, but revisit after other offer types are implemented.
if (base::FeatureList::IsEnabled(switches::kSyncAutofillWalletOfferData) &&
!disabled_types.Has(syncer::AUTOFILL_WALLET_DATA) &&
!disabled_types.Has(syncer::AUTOFILL_WALLET_OFFER)) {
controllers.push_back(CreateWalletModelTypeController(
syncer::AUTOFILL_WALLET_OFFER,
base::BindRepeating(&AutofillWalletOfferDelegateFromDataService),
sync_service));
}
}
// Bookmark sync is enabled by default. Register unless explicitly
......
......@@ -40,15 +40,19 @@ const char kSyncShortInitialRetryOverride[] =
// sure that it's what you want.
const char kSyncShortNudgeDelayForTest[] = "sync-short-nudge-delay-for-test";
// If enabled, the sync engine will be shut down in the "paused" state.
const base::Feature kStopSyncInPausedState{"StopSyncInPausedState",
base::FEATURE_ENABLED_BY_DEFAULT};
// Allows custom passphrase users to receive Wallet data for secondary accounts
// while in transport-only mode.
const base::Feature kSyncAllowWalletDataInTransportModeWithCustomPassphrase{
"SyncAllowAutofillWalletDataInTransportModeWithCustomPassphrase",
base::FEATURE_DISABLED_BY_DEFAULT};
// If enabled, the sync engine will be shut down in the "paused" state.
const base::Feature kStopSyncInPausedState{"StopSyncInPausedState",
base::FEATURE_ENABLED_BY_DEFAULT};
// Controls whether to enable syncing of Autofill Wallet offer data.
const base::Feature kSyncAutofillWalletOfferData{
"SyncAutofillWalletOfferData", base::FEATURE_DISABLED_BY_DEFAULT};
// Controls whether to enable syncing of Wi-Fi configurations.
const base::Feature kSyncWifiConfigurations{"SyncWifiConfigurations",
......
......@@ -28,6 +28,7 @@ extern const char kSyncShortNudgeDelayForTest[];
extern const base::Feature kStopSyncInPausedState;
extern const base::Feature
kSyncAllowWalletDataInTransportModeWithCustomPassphrase;
extern const base::Feature kSyncAutofillWalletOfferData;
extern const base::Feature kSyncWifiConfigurations;
extern const base::Feature kSyncDeviceInfoInTransportMode;
extern const base::Feature kDecoupleSyncFromAndroidMasterSync;
......
......@@ -18,6 +18,7 @@
#include "components/autofill/core/browser/webdata/autofill_profile_sync_bridge.h"
#include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/autofill/core/browser/webdata/autofill_wallet_metadata_sync_bridge.h"
#include "components/autofill/core/browser/webdata/autofill_wallet_offer_sync_bridge.h"
#include "components/autofill/core/browser/webdata/autofill_wallet_sync_bridge.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_features.h"
......@@ -53,7 +54,6 @@ void InitAutofillSyncBridgesOnDBSequence(
void InitWalletSyncBridgesOnDBSequence(
scoped_refptr<base::SingleThreadTaskRunner> db_task_runner,
const scoped_refptr<autofill::AutofillWebDataService>& autofill_web_data,
const base::FilePath& context_path,
const std::string& app_locale,
autofill::AutofillWebDataBackend* autofill_backend) {
DCHECK(db_task_runner->RunsTasksInCurrentSequence());
......@@ -64,6 +64,15 @@ void InitWalletSyncBridgesOnDBSequence(
app_locale, autofill_backend, autofill_web_data.get());
}
void InitWalletOfferSyncBridgeOnDBSequence(
scoped_refptr<base::SingleThreadTaskRunner> db_task_runner,
const scoped_refptr<autofill::AutofillWebDataService>& autofill_web_data,
autofill::AutofillWebDataBackend* autofill_backend) {
DCHECK(db_task_runner->RunsTasksInCurrentSequence());
autofill::AutofillWalletOfferSyncBridge::CreateForWebDataServiceAndBackend(
autofill_backend, autofill_web_data.get());
}
} // namespace
WebDataServiceWrapper::WebDataServiceWrapper() {}
......@@ -123,9 +132,14 @@ WebDataServiceWrapper::WebDataServiceWrapper(
profile_autofill_web_data_->GetAutofillBackend(
base::BindOnce(&InitAutofillSyncBridgesOnDBSequence, db_task_runner,
profile_autofill_web_data_, application_locale));
profile_autofill_web_data_->GetAutofillBackend(base::BindOnce(
&InitWalletSyncBridgesOnDBSequence, db_task_runner,
profile_autofill_web_data_, context_path, application_locale));
profile_autofill_web_data_->GetAutofillBackend(
base::BindOnce(&InitWalletSyncBridgesOnDBSequence, db_task_runner,
profile_autofill_web_data_, application_locale));
if (base::FeatureList::IsEnabled(switches::kSyncAutofillWalletOfferData)) {
profile_autofill_web_data_->GetAutofillBackend(
base::BindOnce(&InitWalletOfferSyncBridgeOnDBSequence, db_task_runner,
profile_autofill_web_data_));
}
if (base::FeatureList::IsEnabled(
autofill::features::kAutofillEnableAccountWalletStorage)) {
......@@ -145,9 +159,9 @@ WebDataServiceWrapper::WebDataServiceWrapper(
account_database_, ui_task_runner, db_task_runner);
account_autofill_web_data_->Init(
base::BindOnce(show_error_callback, ERROR_LOADING_ACCOUNT_AUTOFILL));
account_autofill_web_data_->GetAutofillBackend(base::BindOnce(
&InitWalletSyncBridgesOnDBSequence, db_task_runner,
account_autofill_web_data_, context_path, application_locale));
account_autofill_web_data_->GetAutofillBackend(
base::BindOnce(&InitWalletSyncBridgesOnDBSequence, db_task_runner,
account_autofill_web_data_, application_locale));
}
}
......
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