Skip to content

Commit

Permalink
Adopt base::NoDestructor for KeyedService factories
Browse files Browse the repository at this point in the history
For changes under /chrome/browser/supervised_user

It replaces base::Singleton, following the latest recommendation
in base/ and browser_context_keyed_service_factory.h.

For factories with a trivial destructor, it makes no difference.

LSC doc:
https://docs.google.com/document/d/1x1LqRQyfBOmpMkNQBYs7QBPSxLtuiImvmgcJYI_kaS4/edit?usp=sharing

This CL was uploaded by git cl split.

R=tju@google.com

Bug: 925323
Change-Id: I2e7b030485aa435f7a5f70dac97a8f0ddfe66ead
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4573532
Reviewed-by: Tomek Jurkiewicz <tju@google.com>
Commit-Queue: Tomek Jurkiewicz <tju@google.com>
Auto-Submit: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1150338}
  • Loading branch information
Mikel Astiz authored and Chromium LUCI CQ committed May 29, 2023
1 parent 292358a commit da1277d
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ ChildAccountService* ChildAccountServiceFactory::GetForProfile(

// static
ChildAccountServiceFactory* ChildAccountServiceFactory::GetInstance() {
return base::Singleton<ChildAccountServiceFactory>::get();
static base::NoDestructor<ChildAccountServiceFactory> instance;
return instance.get();
}

ChildAccountServiceFactory::ChildAccountServiceFactory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_CHILD_ACCOUNT_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_CHILD_ACCOUNT_SERVICE_FACTORY_H_

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"
#include "chrome/browser/supervised_user/child_accounts/child_account_service.h"

Expand All @@ -22,7 +22,7 @@ class ChildAccountServiceFactory : public ProfileKeyedServiceFactory {
delete;

private:
friend struct base::DefaultSingletonTraits<ChildAccountServiceFactory>;
friend base::NoDestructor<ChildAccountServiceFactory>;

ChildAccountServiceFactory();
~ChildAccountServiceFactory() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "chrome/browser/supervised_user/child_accounts/family_preferences_service_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/supervised_user/supervised_user_browser_utils.h"
#include "chrome/browser/sync/sync_service_factory.h"
Expand All @@ -23,7 +23,8 @@ FamilyPreferencesService* FamilyPreferencesServiceFactory::GetForProfile(
// static
FamilyPreferencesServiceFactory*
FamilyPreferencesServiceFactory::GetInstance() {
return base::Singleton<FamilyPreferencesServiceFactory>::get();
static base::NoDestructor<FamilyPreferencesServiceFactory> instance;
return instance.get();
}

FamilyPreferencesServiceFactory::FamilyPreferencesServiceFactory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_FAMILY_PREFERENCES_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_FAMILY_PREFERENCES_SERVICE_FACTORY_H_

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h"
Expand All @@ -26,7 +26,7 @@ class FamilyPreferencesServiceFactory : public ProfileKeyedServiceFactory {
const FamilyPreferencesServiceFactory&) = delete;

private:
friend struct base::DefaultSingletonTraits<FamilyPreferencesServiceFactory>;
friend base::NoDestructor<FamilyPreferencesServiceFactory>;

FamilyPreferencesServiceFactory();
~FamilyPreferencesServiceFactory() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "chrome/browser/supervised_user/child_accounts/list_family_members_service_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/supervised_user/supervised_user_browser_utils.h"
Expand All @@ -23,7 +23,8 @@ ListFamilyMembersService* ListFamilyMembersServiceFactory::GetForProfile(
// static
ListFamilyMembersServiceFactory*
ListFamilyMembersServiceFactory::GetInstance() {
return base::Singleton<ListFamilyMembersServiceFactory>::get();
static base::NoDestructor<ListFamilyMembersServiceFactory> instance;
return instance.get();
}

ListFamilyMembersServiceFactory::ListFamilyMembersServiceFactory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_LIST_FAMILY_MEMBERS_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_LIST_FAMILY_MEMBERS_SERVICE_FACTORY_H_

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"
#include "components/keyed_service/core/keyed_service.h"
Expand All @@ -26,7 +26,7 @@ class ListFamilyMembersServiceFactory : public ProfileKeyedServiceFactory {
const ListFamilyMembersServiceFactory&) = delete;

private:
friend struct base::DefaultSingletonTraits<ListFamilyMembersServiceFactory>;
friend base::NoDestructor<ListFamilyMembersServiceFactory>;

ListFamilyMembersServiceFactory();
~ListFamilyMembersServiceFactory() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ SupervisedUserServiceFactory::GetForProfileIfExists(Profile* profile) {

// static
SupervisedUserServiceFactory* SupervisedUserServiceFactory::GetInstance() {
return base::Singleton<SupervisedUserServiceFactory>::get();
static base::NoDestructor<SupervisedUserServiceFactory> instance;
return instance.get();
}

// static
Expand Down Expand Up @@ -102,7 +103,7 @@ SupervisedUserServiceFactory::SupervisedUserServiceFactory()
DependsOn(SupervisedUserSettingsServiceFactory::GetInstance());
}

SupervisedUserServiceFactory::~SupervisedUserServiceFactory() {}
SupervisedUserServiceFactory::~SupervisedUserServiceFactory() = default;

KeyedService* SupervisedUserServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* profile) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SUPERVISED_USER_SUPERVISED_USER_SERVICE_FACTORY_H_

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"
#include "components/supervised_user/core/common/supervised_users.h"

Expand Down Expand Up @@ -35,7 +35,7 @@ class SupervisedUserServiceFactory : public ProfileKeyedServiceFactory {
static KeyedService* BuildInstanceFor(Profile* profile);

private:
friend struct base::DefaultSingletonTraits<SupervisedUserServiceFactory>;
friend base::NoDestructor<SupervisedUserServiceFactory>;

SupervisedUserServiceFactory();
~SupervisedUserServiceFactory() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ SupervisedUserSettingsServiceFactory::GetForKey(SimpleFactoryKey* key) {
// static
SupervisedUserSettingsServiceFactory*
SupervisedUserSettingsServiceFactory::GetInstance() {
return base::Singleton<SupervisedUserSettingsServiceFactory>::get();
static base::NoDestructor<SupervisedUserSettingsServiceFactory> instance;
return instance.get();
}

SupervisedUserSettingsServiceFactory::SupervisedUserSettingsServiceFactory()
: SimpleKeyedServiceFactory("SupervisedUserSettingsService",
SimpleDependencyManager::GetInstance()) {}

SupervisedUserSettingsServiceFactory::
~SupervisedUserSettingsServiceFactory() {}
SupervisedUserSettingsServiceFactory::~SupervisedUserSettingsServiceFactory() =
default;

std::unique_ptr<KeyedService>
SupervisedUserSettingsServiceFactory::BuildServiceInstanceFor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <memory>

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "components/keyed_service/core/simple_keyed_service_factory.h"
#include "components/supervised_user/core/common/supervised_users.h"

Expand All @@ -25,8 +25,7 @@ class SupervisedUserSettingsServiceFactory : public SimpleKeyedServiceFactory {
static SupervisedUserSettingsServiceFactory* GetInstance();

private:
friend struct base::DefaultSingletonTraits<
SupervisedUserSettingsServiceFactory>;
friend base::NoDestructor<SupervisedUserSettingsServiceFactory>;

SupervisedUserSettingsServiceFactory();
~SupervisedUserSettingsServiceFactory() override;
Expand Down

0 comments on commit da1277d

Please sign in to comment.