blob: eabd20c18c25d78a91c210b16d32656cba6c6fb0 [file] [log] [blame]
// 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 "base/threading/thread_checker.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 AutofillTable;
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,
AutofillWebDataBackend* web_data_backend);
~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:
AutofillTable* GetAutofillTable();
// The bridge should be used on the same sequence where it is constructed.
THREAD_CHECKER(thread_checker_);
// AutofillProfileSyncBridge is owned by |web_data_backend_| through
// SupportsUserData, so it's guaranteed to outlive |this|.
AutofillWebDataBackend* const web_data_backend_;
DISALLOW_COPY_AND_ASSIGN(AutofillWalletSyncBridge);
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_WALLET_SYNC_BRIDGE_H_