1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/autofill/autofill_entity_data_manager_factory.h"
#include "base/no_destructor.h"
#include "chrome/browser/autofill/strike_database_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/webdata_services/web_data_service_factory.h"
#include "components/autofill/core/browser/data_manager/autofill_ai/entity_data_manager.h"
#include "components/autofill/core/browser/strike_databases/strike_database.h"
#include "components/autofill/core/browser/strike_databases/strike_database_base.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/keyed_service/core/service_access_type.h"
namespace autofill {
// static
EntityDataManager* AutofillEntityDataManagerFactory::GetForProfile(
Profile* profile) {
return static_cast<EntityDataManager*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
AutofillEntityDataManagerFactory*
AutofillEntityDataManagerFactory::GetInstance() {
static base::NoDestructor<AutofillEntityDataManagerFactory> instance;
return instance.get();
}
AutofillEntityDataManagerFactory::AutofillEntityDataManagerFactory()
: ProfileKeyedServiceFactory(
"AutofillEntityDataManager",
ProfileSelections::BuildRedirectedInIncognito()) {
DependsOn(WebDataServiceFactory::GetInstance());
DependsOn(HistoryServiceFactory::GetInstance());
DependsOn(StrikeDatabaseFactory::GetInstance());
}
AutofillEntityDataManagerFactory::~AutofillEntityDataManagerFactory() = default;
std::unique_ptr<KeyedService>
AutofillEntityDataManagerFactory::BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const {
if (!base::FeatureList::IsEnabled(
features::kAutofillAiCreateEntityDataManager) &&
!base::FeatureList::IsEnabled(features::kAutofillAiWithDataSchema)) {
return nullptr;
}
Profile* profile = Profile::FromBrowserContext(context);
scoped_refptr<autofill::AutofillWebDataService> local_storage =
WebDataServiceFactory::GetAutofillWebDataForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS);
if (!local_storage) {
// This happens in tests because
// WebDataServiceFactory::ServiceIsNULLWhileTesting() is true.
return nullptr;
}
return std::make_unique<EntityDataManager>(
std::move(local_storage),
HistoryServiceFactory::GetForProfile(profile,
ServiceAccessType::EXPLICIT_ACCESS),
StrikeDatabaseFactory::GetForProfile(profile));
}
bool AutofillEntityDataManagerFactory::ServiceIsCreatedWithBrowserContext()
const {
return true;
}
} // namespace autofill
|