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

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=dominickn@chromium.org, tsergeant@chromium.org

Bug: 925323
Change-Id: Id5113260c3463d5e36e36e8cfc5793bd1ecb6db8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4572886
Auto-Submit: Mikel Astiz <mastiz@chromium.org>
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Reviewed-by: Tim Sergeant <tsergeant@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1150884}
  • Loading branch information
Mikel Astiz authored and Chromium LUCI CQ committed May 30, 2023
1 parent 733b267 commit 9d2b6d7
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ AppDiscoveryService* AppDiscoveryServiceFactory::GetForProfile(

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

AppDiscoveryServiceFactory::AppDiscoveryServiceFactory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_APPS_APP_DISCOVERY_SERVICE_APP_DISCOVERY_SERVICE_FACTORY_H_
#define CHROME_BROWSER_APPS_APP_DISCOVERY_SERVICE_APP_DISCOVERY_SERVICE_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 @@ -26,7 +26,7 @@ class AppDiscoveryServiceFactory : public ProfileKeyedServiceFactory {
delete;

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

AppDiscoveryServiceFactory();
~AppDiscoveryServiceFactory() override;
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/apps/app_service/app_service_proxy_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ AppServiceProxy* AppServiceProxyFactory::GetForProfile(Profile* profile) {

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

AppServiceProxyFactory::AppServiceProxyFactory()
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/apps/app_service/app_service_proxy_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_APPS_APP_SERVICE_APP_SERVICE_PROXY_FACTORY_H_
#define CHROME_BROWSER_APPS_APP_SERVICE_APP_SERVICE_PROXY_FACTORY_H_

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/apps/app_service/app_service_proxy_forward.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
Expand Down Expand Up @@ -40,7 +40,7 @@ class AppServiceProxyFactory : public BrowserContextKeyedServiceFactory {
AppServiceProxyFactory& operator=(const AppServiceProxyFactory&) = delete;

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

AppServiceProxyFactory();
~AppServiceProxyFactory() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ ArcApps* ArcAppsFactory::GetForProfile(Profile* profile) {

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

// static
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/apps/app_service/publishers/arc_apps_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_APPS_APP_SERVICE_PUBLISHERS_ARC_APPS_FACTORY_H_
#define CHROME_BROWSER_APPS_APP_SERVICE_PUBLISHERS_ARC_APPS_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 @@ -23,7 +23,7 @@ class ArcAppsFactory : public ProfileKeyedServiceFactory {
static void ShutDownForTesting(content::BrowserContext* context);

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

ArcAppsFactory();
ArcAppsFactory(const ArcAppsFactory&) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ StandaloneBrowserExtensionAppsFactoryForApp::GetForProfile(Profile* profile) {
// static
StandaloneBrowserExtensionAppsFactoryForApp*
StandaloneBrowserExtensionAppsFactoryForApp::GetInstance() {
return base::Singleton<StandaloneBrowserExtensionAppsFactoryForApp>::get();
static base::NoDestructor<StandaloneBrowserExtensionAppsFactoryForApp>
instance;
return instance.get();
}

// static
Expand Down Expand Up @@ -69,8 +71,9 @@ StandaloneBrowserExtensionAppsFactoryForExtension::GetForProfile(
// static
StandaloneBrowserExtensionAppsFactoryForExtension*
StandaloneBrowserExtensionAppsFactoryForExtension::GetInstance() {
return base::Singleton<
StandaloneBrowserExtensionAppsFactoryForExtension>::get();
static base::NoDestructor<StandaloneBrowserExtensionAppsFactoryForExtension>
instance;
return instance.get();
}

// static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_APPS_APP_SERVICE_PUBLISHERS_STANDALONE_BROWSER_EXTENSION_APPS_FACTORY_H_
#define CHROME_BROWSER_APPS_APP_SERVICE_PUBLISHERS_STANDALONE_BROWSER_EXTENSION_APPS_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 @@ -26,8 +26,7 @@ class StandaloneBrowserExtensionAppsFactoryForApp
static void ShutDownForTesting(content::BrowserContext* context);

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

StandaloneBrowserExtensionAppsFactoryForApp();
StandaloneBrowserExtensionAppsFactoryForApp(
Expand All @@ -53,8 +52,7 @@ class StandaloneBrowserExtensionAppsFactoryForExtension
static void ShutDownForTesting(content::BrowserContext* context);

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

StandaloneBrowserExtensionAppsFactoryForExtension();
StandaloneBrowserExtensionAppsFactoryForExtension(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ WebAppsCrosapi* WebAppsCrosapiFactory::GetForProfile(Profile* profile) {

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

// static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_APPS_APP_SERVICE_PUBLISHERS_WEB_APPS_CROSAPI_FACTORY_H_
#define CHROME_BROWSER_APPS_APP_SERVICE_PUBLISHERS_WEB_APPS_CROSAPI_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 @@ -25,7 +25,7 @@ class WebAppsCrosapiFactory : public ProfileKeyedServiceFactory {
static void ShutDownForTesting(content::BrowserContext* context);

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

WebAppsCrosapiFactory();
WebAppsCrosapiFactory(const WebAppsCrosapiFactory&) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ SubscriberCrosapi* SubscriberCrosapiFactory::GetForProfile(Profile* profile) {

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

// static
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/apps/app_service/subscriber_crosapi_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_APPS_APP_SERVICE_SUBSCRIBER_CROSAPI_FACTORY_H_
#define CHROME_BROWSER_APPS_APP_SERVICE_SUBSCRIBER_CROSAPI_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 @@ -25,7 +25,7 @@ class SubscriberCrosapiFactory : public ProfileKeyedServiceFactory {
static void ShutDownForTesting(content::BrowserContext* context);

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

SubscriberCrosapiFactory();
SubscriberCrosapiFactory(const SubscriberCrosapiFactory&) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ SupportedLinksInfoBarPrefsServiceFactory::GetForProfile(Profile* profile) {
// static
SupportedLinksInfoBarPrefsServiceFactory*
SupportedLinksInfoBarPrefsServiceFactory::GetInstance() {
return base::Singleton<SupportedLinksInfoBarPrefsServiceFactory>::get();
static base::NoDestructor<SupportedLinksInfoBarPrefsServiceFactory> instance;
return instance.get();
}

SupportedLinksInfoBarPrefsServiceFactory::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#ifndef CHROME_BROWSER_APPS_INTENT_HELPER_SUPPORTED_LINKS_INFOBAR_PREFS_SERVICE_FACTORY_H_
#define CHROME_BROWSER_APPS_INTENT_HELPER_SUPPORTED_LINKS_INFOBAR_PREFS_SERVICE_FACTORY_H_

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"

class Profile;

namespace apps {

class SupportedLinksInfoBarPrefsService;
Expand All @@ -24,8 +26,7 @@ class SupportedLinksInfoBarPrefsServiceFactory
const SupportedLinksInfoBarPrefsServiceFactory&) = delete;

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

SupportedLinksInfoBarPrefsServiceFactory();
~SupportedLinksInfoBarPrefsServiceFactory() override;
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/apps/platform_apps/app_load_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ AppLoadService* AppLoadServiceFactory::GetForBrowserContext(
}

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

AppLoadServiceFactory::AppLoadServiceFactory()
Expand All @@ -43,7 +44,7 @@ AppLoadServiceFactory::AppLoadServiceFactory()
extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
}

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

KeyedService* AppLoadServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/apps/platform_apps/app_load_service_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_APPS_PLATFORM_APPS_APP_LOAD_SERVICE_FACTORY_H_
#define CHROME_BROWSER_APPS_PLATFORM_APPS_APP_LOAD_SERVICE_FACTORY_H_

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

namespace content {
Expand All @@ -23,7 +23,7 @@ class AppLoadServiceFactory : public ProfileKeyedServiceFactory {
static AppLoadServiceFactory* GetInstance();

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

AppLoadServiceFactory();
~AppLoadServiceFactory() override;
Expand Down
7 changes: 4 additions & 3 deletions chrome/browser/apps/platform_apps/shortcut_manager_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "chrome/browser/apps/platform_apps/shortcut_manager_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/apps/platform_apps/shortcut_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/extensions/web_app_extension_shortcut.h"
Expand All @@ -19,7 +19,8 @@ AppShortcutManager* AppShortcutManagerFactory::GetForProfile(Profile* profile) {
}

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

AppShortcutManagerFactory::AppShortcutManagerFactory()
Expand All @@ -35,7 +36,7 @@ AppShortcutManagerFactory::AppShortcutManagerFactory()
base::BindRepeating(&web_app::UpdateShortcutsForAllApps));
}

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

KeyedService* AppShortcutManagerFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/apps/platform_apps/shortcut_manager_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "chrome/browser/profiles/profile_keyed_service_factory.h"

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

class Profile;
Expand All @@ -27,7 +27,7 @@ class AppShortcutManagerFactory : public ProfileKeyedServiceFactory {
static AppShortcutManagerFactory* GetInstance();

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

AppShortcutManagerFactory();
~AppShortcutManagerFactory() override;
Expand Down

0 comments on commit 9d2b6d7

Please sign in to comment.