blob: a8611ab0e6153c60a627f606e71b1c6cadd55dc9 [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.
#include "ios/web_view/internal/autofill/web_view_strike_database_factory.h"
#include <utility>
#include "base/no_destructor.h"
#include "components/autofill/core/browser/payments/strike_database.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "ios/web_view/internal/app/application_context.h"
#include "ios/web_view/internal/web_view_browser_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace ios_web_view {
// static
autofill::StrikeDatabase* WebViewStrikeDatabaseFactory::GetForBrowserState(
WebViewBrowserState* browser_state) {
return static_cast<autofill::StrikeDatabase*>(
GetInstance()->GetServiceForBrowserState(browser_state, true));
}
// static
WebViewStrikeDatabaseFactory* WebViewStrikeDatabaseFactory::GetInstance() {
static base::NoDestructor<WebViewStrikeDatabaseFactory> instance;
return instance.get();
}
WebViewStrikeDatabaseFactory::WebViewStrikeDatabaseFactory()
: BrowserStateKeyedServiceFactory(
"AutofillStrikeDatabase",
BrowserStateDependencyManager::GetInstance()) {
}
WebViewStrikeDatabaseFactory::~WebViewStrikeDatabaseFactory() {}
std::unique_ptr<KeyedService>
WebViewStrikeDatabaseFactory::BuildServiceInstanceFor(
web::BrowserState* context) const {
WebViewBrowserState* browser_state =
WebViewBrowserState::FromBrowserState(context);
leveldb_proto::ProtoDatabaseProvider* db_provider =
browser_state->GetProtoDatabaseProvider();
return std::make_unique<autofill::StrikeDatabase>(
db_provider, browser_state->GetStatePath());
}
} // namespace ios_web_view