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/profiles

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=droger@chromium.org

Bug: 925323
Change-Id: I4fcfc6e86ca9f68cf56eaa51d8b15f963bd7d4d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4572805
Auto-Submit: Mikel Astiz <mastiz@chromium.org>
Commit-Queue: David Roger <droger@chromium.org>
Reviewed-by: David Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1150437}
  • Loading branch information
Mikel Astiz authored and Chromium LUCI CQ committed May 30, 2023
1 parent 18a306e commit 46b43cb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
5 changes: 3 additions & 2 deletions chrome/browser/profiles/gaia_info_update_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ GAIAInfoUpdateServiceFactory::GAIAInfoUpdateServiceFactory()
DependsOn(IdentityManagerFactory::GetInstance());
}

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

// static
GAIAInfoUpdateService* GAIAInfoUpdateServiceFactory::GetForProfile(
Expand All @@ -36,7 +36,8 @@ GAIAInfoUpdateService* GAIAInfoUpdateServiceFactory::GetForProfile(

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

KeyedService* GAIAInfoUpdateServiceFactory::BuildServiceInstanceFor(
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/profiles/gaia_info_update_service_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_FACTORY_H_
#define CHROME_BROWSER_PROFILES_GAIA_INFO_UPDATE_SERVICE_FACTORY_H_

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

class GAIAInfoUpdateService;
Expand All @@ -29,7 +29,7 @@ class GAIAInfoUpdateServiceFactory : public ProfileKeyedServiceFactory {
delete;

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

GAIAInfoUpdateServiceFactory();
~GAIAInfoUpdateServiceFactory() override;
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/profiles/profile_statistics_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "chrome/browser/profiles/profile_statistics_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_statistics.h"
#include "content/public/browser/browser_thread.h"
Expand All @@ -17,7 +17,8 @@ ProfileStatistics* ProfileStatisticsFactory::GetForProfile(Profile* profile) {

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

ProfileStatisticsFactory::ProfileStatisticsFactory()
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/profiles/profile_statistics_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include "chrome/browser/profiles/profile_keyed_service_factory.h"

namespace base {
template <typename T> struct DefaultSingletonTraits;
template <typename T>
class NoDestructor;
}

class Profile;
Expand All @@ -24,7 +25,7 @@ class ProfileStatisticsFactory : public ProfileKeyedServiceFactory {
static ProfileStatisticsFactory* GetInstance();

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

ProfileStatisticsFactory();

Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/profiles/renderer_updater_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ RendererUpdaterFactory::RendererUpdaterFactory()
#endif // BUILDFLAG(ENABLE_BOUND_SESSION_CREDENTIALS)
}

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

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

// static
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/profiles/renderer_updater_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_PROFILES_RENDERER_UPDATER_FACTORY_H_
#define CHROME_BROWSER_PROFILES_RENDERER_UPDATER_FACTORY_H_

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

class Profile;
Expand All @@ -31,7 +31,7 @@ class RendererUpdaterFactory : public ProfileKeyedServiceFactory {
bool ServiceIsCreatedWithBrowserContext() const override;

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

RendererUpdaterFactory();
~RendererUpdaterFactory() override;
Expand Down

0 comments on commit 46b43cb

Please sign in to comment.