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
|
// Copyright 2020 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/browsing_data/chrome_browsing_data_lifetime_manager_factory.h"
#include "base/no_destructor.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_lifetime_manager.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "content/public/browser/browser_context.h"
#include "extensions/buildflags/buildflags.h"
// static
ChromeBrowsingDataLifetimeManagerFactory*
ChromeBrowsingDataLifetimeManagerFactory::GetInstance() {
static base::NoDestructor<ChromeBrowsingDataLifetimeManagerFactory> instance;
return instance.get();
}
// static
ChromeBrowsingDataLifetimeManager*
ChromeBrowsingDataLifetimeManagerFactory::GetForProfile(Profile* profile) {
return static_cast<ChromeBrowsingDataLifetimeManager*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
ChromeBrowsingDataLifetimeManagerFactory::
ChromeBrowsingDataLifetimeManagerFactory()
: ProfileKeyedServiceFactory(
"BrowsingDataLifetimeManager",
ProfileSelections::Builder()
.WithRegular(ProfileSelection::kOwnInstance)
.WithGuest(ProfileSelection::kOffTheRecordOnly)
// TODO(crbug.com/41488885): Check if this service is needed for
// Ash Internals.
.WithAshInternals(ProfileSelection::kOwnInstance)
.Build()) {
DependsOn(ChromeBrowsingDataRemoverDelegateFactory::GetInstance());
DependsOn(SyncServiceFactory::GetInstance());
}
ChromeBrowsingDataLifetimeManagerFactory::
~ChromeBrowsingDataLifetimeManagerFactory() = default;
std::unique_ptr<KeyedService>
ChromeBrowsingDataLifetimeManagerFactory::BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const {
#if BUILDFLAG(IS_CHROMEOS)
Profile* profile = Profile::FromBrowserContext(context);
// This condition still needs to be explicitly stated here despite having
// ProfileKeyedService logic implemented because `IsGuestSession()` and
// `IsRegularProfile()` are not yet mutually exclusive.
// TODO(rsult): remove this condition when `IsGuestSession() is fixed.
if (profile->IsGuestSession() && !profile->IsOffTheRecord())
return nullptr;
#endif // BUILDFLAG(IS_CHROMEOS)
return std::make_unique<ChromeBrowsingDataLifetimeManager>(context);
}
bool ChromeBrowsingDataLifetimeManagerFactory::
ServiceIsCreatedWithBrowserContext() const {
return true;
}
|