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
|
// Copyright 2023 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/tpcd/experiment/eligibility_service_factory.h"
#include "base/feature_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/privacy_sandbox/privacy_sandbox_settings_factory.h"
#include "chrome/browser/privacy_sandbox/tracking_protection_onboarding_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tpcd/experiment/eligibility_service.h"
#include "chrome/browser/tpcd/experiment/experiment_manager_impl.h"
#include "components/privacy_sandbox/tracking_protection_onboarding.h"
#include "content/public/common/content_features.h"
namespace tpcd::experiment {
// static
EligibilityService* EligibilityServiceFactory::GetForProfile(Profile* profile) {
return static_cast<EligibilityService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
EligibilityServiceFactory* EligibilityServiceFactory::GetInstance() {
static base::NoDestructor<EligibilityServiceFactory> factory;
return factory.get();
}
EligibilityServiceFactory::EligibilityServiceFactory()
: ProfileKeyedServiceFactory(
"EligibilityServiceFactory",
ProfileSelections::Builder()
.WithRegular(ProfileSelection::kOwnInstance)
.WithGuest(ProfileSelection::kOwnInstance)
.WithAshInternals(ProfileSelection::kNone)
.Build()) {
DependsOn(PrivacySandboxSettingsFactory::GetInstance());
DependsOn(TrackingProtectionOnboardingFactory::GetInstance());
}
bool EligibilityServiceFactory::ServiceIsCreatedWithBrowserContext() const {
return true;
}
std::unique_ptr<KeyedService>
EligibilityServiceFactory::BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const {
Profile* profile = Profile::FromBrowserContext(context);
auto* onboarding_service =
TrackingProtectionOnboardingFactory::GetForProfile(profile);
auto* privacy_sandbox_settings =
PrivacySandboxSettingsFactory::GetForProfile(profile);
if (auto* experiment_manager =
ExperimentManagerImpl::GetForProfile(profile)) {
return std::make_unique<EligibilityService>(profile, onboarding_service,
privacy_sandbox_settings,
experiment_manager);
}
if (base::FeatureList::IsEnabled(
features::kCookieDeprecationFacilitatedTesting)) {
return nullptr;
}
return nullptr;
}
} // namespace tpcd::experiment
|