Commit f7ea3388 authored by Mikel Astiz's avatar Mikel Astiz Committed by Commit Bot

Introduce skeleton code for Wallet USS implementation

No actual implementation included, just the basic skeleton files and
classes, the required plumbing and the associated feature toggle.

Follow-up patches will introduce the actual implementation, to
ultimately replace AutofillWalletSyncableService.

Bug: 853688
Change-Id: Ia0963fbad2d3e046686e93aea6468283bad186fd
Reviewed-on: https://chromium-review.googlesource.com/1147223Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Reviewed-by: default avatarCait Phillips <caitkp@chromium.org>
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577570}
parent 26fefaa1
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "components/autofill/core/browser/webdata/autofill_profile_sync_bridge.h" #include "components/autofill/core/browser/webdata/autofill_profile_sync_bridge.h"
#include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h" #include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h"
#include "components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.h" #include "components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.h"
#include "components/autofill/core/browser/webdata/autofill_wallet_sync_bridge.h"
#include "components/autofill/core/browser/webdata/autofill_wallet_syncable_service.h" #include "components/autofill/core/browser/webdata/autofill_wallet_syncable_service.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h" #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_features.h"
...@@ -597,6 +598,17 @@ ChromeSyncClient::GetControllerDelegateForModelType(syncer::ModelType type) { ...@@ -597,6 +598,17 @@ ChromeSyncClient::GetControllerDelegateForModelType(syncer::ModelType type) {
profile_web_data_service_.get()) profile_web_data_service_.get())
->change_processor() ->change_processor()
->GetControllerDelegateOnUIThread(); ->GetControllerDelegateOnUIThread();
case syncer::AUTOFILL_WALLET_DATA: {
// TODO(feuunk): This doesn't allow switching which database to use at
// runtime. This should be fixed as part of the USS migration for
// payments.
auto service = account_web_data_service_ ? account_web_data_service_
: profile_web_data_service_;
return autofill::AutofillWalletSyncBridge::FromWebDataService(
service.get())
->change_processor()
->GetControllerDelegateOnUIThread();
}
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
case syncer::PRINTERS: case syncer::PRINTERS:
return chromeos::SyncedPrintersManagerFactory::GetForBrowserContext( return chromeos::SyncedPrintersManagerFactory::GetForBrowserContext(
......
...@@ -183,6 +183,8 @@ static_library("browser") { ...@@ -183,6 +183,8 @@ static_library("browser") {
"webdata/autofill_table_encryptor_factory.h", "webdata/autofill_table_encryptor_factory.h",
"webdata/autofill_wallet_metadata_syncable_service.cc", "webdata/autofill_wallet_metadata_syncable_service.cc",
"webdata/autofill_wallet_metadata_syncable_service.h", "webdata/autofill_wallet_metadata_syncable_service.h",
"webdata/autofill_wallet_sync_bridge.cc",
"webdata/autofill_wallet_sync_bridge.h",
"webdata/autofill_wallet_syncable_service.cc", "webdata/autofill_wallet_syncable_service.cc",
"webdata/autofill_wallet_syncable_service.h", "webdata/autofill_wallet_syncable_service.h",
"webdata/autofill_webdata.h", "webdata/autofill_webdata.h",
......
per-file *sync_bridge*=jkrcal@chromium.org
// 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_wallet_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 kAutofillWalletSyncBridgeUserDataKey = 0;
} // namespace
// static
void AutofillWalletSyncBridge::CreateForWebDataServiceAndBackend(
const std::string& app_locale,
AutofillWebDataBackend* web_data_backend,
AutofillWebDataService* web_data_service) {
web_data_service->GetDBUserData()->SetUserData(
&kAutofillWalletSyncBridgeUserDataKey,
std::make_unique<AutofillWalletSyncBridge>(
std::make_unique<syncer::ClientTagBasedModelTypeProcessor>(
syncer::AUTOFILL_WALLET_DATA,
/*dump_stack=*/base::RepeatingClosure())));
}
// static
syncer::ModelTypeSyncBridge* AutofillWalletSyncBridge::FromWebDataService(
AutofillWebDataService* web_data_service) {
return static_cast<AutofillWalletSyncBridge*>(
web_data_service->GetDBUserData()->GetUserData(
&kAutofillWalletSyncBridgeUserDataKey));
}
AutofillWalletSyncBridge::AutofillWalletSyncBridge(
std::unique_ptr<syncer::ModelTypeChangeProcessor> change_processor)
: ModelTypeSyncBridge(std::move(change_processor)) {}
AutofillWalletSyncBridge::~AutofillWalletSyncBridge() {}
std::unique_ptr<syncer::MetadataChangeList>
AutofillWalletSyncBridge::CreateMetadataChangeList() {
NOTIMPLEMENTED();
return nullptr;
}
base::Optional<syncer::ModelError> AutofillWalletSyncBridge::MergeSyncData(
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
syncer::EntityChangeList entity_data) {
return ApplySyncChanges(std::move(metadata_change_list),
std::move(entity_data));
}
base::Optional<syncer::ModelError> AutofillWalletSyncBridge::ApplySyncChanges(
std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
syncer::EntityChangeList entity_data) {
NOTIMPLEMENTED();
return base::nullopt;
}
void AutofillWalletSyncBridge::GetData(StorageKeyList storage_keys,
DataCallback callback) {
NOTIMPLEMENTED();
}
void AutofillWalletSyncBridge::GetAllDataForDebugging(DataCallback callback) {
NOTIMPLEMENTED();
}
std::string AutofillWalletSyncBridge::GetClientTag(
const syncer::EntityData& entity_data) {
NOTIMPLEMENTED();
return "";
}
std::string AutofillWalletSyncBridge::GetStorageKey(
const syncer::EntityData& entity_data) {
NOTIMPLEMENTED();
return "";
}
} // namespace autofill
// 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_WALLET_SYNC_BRIDGE_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WALLET_SYNC_BRIDGE_H_
#include <memory>
#include <string>
#include "base/macros.h"
#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 propagating local changes to the processor and
// applying remote changes to the local database.
class AutofillWalletSyncBridge : 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(
const std::string& app_locale,
AutofillWebDataBackend* webdata_backend,
AutofillWebDataService* web_data_service);
static syncer::ModelTypeSyncBridge* FromWebDataService(
AutofillWebDataService* web_data_service);
explicit AutofillWalletSyncBridge(
std::unique_ptr<syncer::ModelTypeChangeProcessor> change_processor);
~AutofillWalletSyncBridge() override;
// ModelTypeSyncBridge implementation.
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;
private:
DISALLOW_COPY_AND_ASSIGN(AutofillWalletSyncBridge);
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WALLET_SYNC_BRIDGE_H_
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/autofill/core/browser/webdata/autocomplete_sync_bridge.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_data_type_controller.h"
#include "components/autofill/core/browser/webdata/autofill_profile_sync_bridge.h" #include "components/autofill/core/browser/webdata/autofill_profile_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/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/browser/webdata/web_data_model_type_controller.h" #include "components/autofill/core/browser/webdata/web_data_model_type_controller.h"
#include "components/browser_sync/browser_sync_switches.h" #include "components/browser_sync/browser_sync_switches.h"
...@@ -151,9 +152,18 @@ ProfileSyncComponentsFactoryImpl::CreateCommonDataTypeControllers( ...@@ -151,9 +152,18 @@ ProfileSyncComponentsFactoryImpl::CreateCommonDataTypeControllers(
// enforced by the datatype controller. Register unless explicitly disabled. // enforced by the datatype controller. Register unless explicitly disabled.
bool wallet_disabled = disabled_types.Has(syncer::AUTOFILL_WALLET_DATA); bool wallet_disabled = disabled_types.Has(syncer::AUTOFILL_WALLET_DATA);
if (!wallet_disabled) { if (!wallet_disabled) {
controllers.push_back(std::make_unique<AutofillWalletDataTypeController>( if (base::FeatureList::IsEnabled(switches::kSyncUSSAutofillWalletData)) {
syncer::AUTOFILL_WALLET_DATA, db_thread_, error_callback, controllers.push_back(
sync_client_, web_data_service_)); std::make_unique<autofill::WebDataModelTypeController>(
syncer::AUTOFILL_WALLET_DATA, sync_client_, db_thread_,
web_data_service_,
base::BindRepeating(&AutofillProfileDelegateFromDataService)));
} else {
controllers.push_back(
std::make_unique<AutofillWalletDataTypeController>(
syncer::AUTOFILL_WALLET_DATA, db_thread_, error_callback,
sync_client_, web_data_service_));
}
} }
// Wallet metadata sync depends on Wallet data sync. Register if Wallet data // Wallet metadata sync depends on Wallet data sync. Register if Wallet data
......
...@@ -74,4 +74,8 @@ const base::Feature kSyncUSSSessions{"SyncUSSSessions", ...@@ -74,4 +74,8 @@ const base::Feature kSyncUSSSessions{"SyncUSSSessions",
const base::Feature kSyncUSSAutofillProfile{"SyncUSSAutofillProfile", const base::Feature kSyncUSSAutofillProfile{"SyncUSSAutofillProfile",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
// Enable USS implementation of autofill wallet datatype.
const base::Feature kSyncUSSAutofillWalletData{
"SyncUSSAutofillWalletData", base::FEATURE_DISABLED_BY_DEFAULT};
} // namespace switches } // namespace switches
...@@ -29,6 +29,7 @@ extern const base::Feature kSyncUserTranslationEvents; ...@@ -29,6 +29,7 @@ extern const base::Feature kSyncUserTranslationEvents;
extern const base::Feature kSyncUSSBookmarks; extern const base::Feature kSyncUSSBookmarks;
extern const base::Feature kSyncUSSSessions; extern const base::Feature kSyncUSSSessions;
extern const base::Feature kSyncUSSAutofillProfile; extern const base::Feature kSyncUSSAutofillProfile;
extern const base::Feature kSyncUSSAutofillWalletData;
} // namespace switches } // namespace switches
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h" #include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h"
#include "components/autofill/core/browser/webdata/autofill_table.h" #include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.h" #include "components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.h"
#include "components/autofill/core/browser/webdata/autofill_wallet_sync_bridge.h"
#include "components/autofill/core/browser/webdata/autofill_wallet_syncable_service.h" #include "components/autofill/core/browser/webdata/autofill_wallet_syncable_service.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h" #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_features.h"
...@@ -71,6 +72,9 @@ void InitSyncableProfileServicesOnDBSequence( ...@@ -71,6 +72,9 @@ void InitSyncableProfileServicesOnDBSequence(
} }
} }
// TODO(jkrcal): Rename this function when the last webdata sync type get
// converted to USS, e.g. to InitSyncBridgesOnDBSequence(). Check also other
// related functions.
void InitSyncableAccountServicesOnDBSequence( void InitSyncableAccountServicesOnDBSequence(
scoped_refptr<base::SingleThreadTaskRunner> db_task_runner, scoped_refptr<base::SingleThreadTaskRunner> db_task_runner,
const syncer::SyncableService::StartSyncFlare& sync_flare, const syncer::SyncableService::StartSyncFlare& sync_flare,
...@@ -79,15 +83,21 @@ void InitSyncableAccountServicesOnDBSequence( ...@@ -79,15 +83,21 @@ void InitSyncableAccountServicesOnDBSequence(
const std::string& app_locale, const std::string& app_locale,
autofill::AutofillWebDataBackend* autofill_backend) { autofill::AutofillWebDataBackend* autofill_backend) {
DCHECK(db_task_runner->RunsTasksInCurrentSequence()); DCHECK(db_task_runner->RunsTasksInCurrentSequence());
autofill::AutofillWalletSyncableService::CreateForWebDataServiceAndBackend(
autofill_web_data.get(), autofill_backend, app_locale); if (base::FeatureList::IsEnabled(switches::kSyncUSSAutofillWalletData)) {
autofill::AutofillWalletSyncBridge::CreateForWebDataServiceAndBackend(
app_locale, autofill_backend, autofill_web_data.get());
} else {
autofill::AutofillWalletSyncableService::CreateForWebDataServiceAndBackend(
autofill_web_data.get(), autofill_backend, app_locale);
autofill::AutofillWalletSyncableService::FromWebDataService(
autofill_web_data.get())
->InjectStartSyncFlare(sync_flare);
}
autofill::AutofillWalletMetadataSyncableService:: autofill::AutofillWalletMetadataSyncableService::
CreateForWebDataServiceAndBackend(autofill_web_data.get(), CreateForWebDataServiceAndBackend(autofill_web_data.get(),
autofill_backend, app_locale); autofill_backend, app_locale);
autofill::AutofillWalletSyncableService::FromWebDataService(
autofill_web_data.get())
->InjectStartSyncFlare(sync_flare);
} }
} // namespace } // namespace
......
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