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

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

Bug: 925323
Change-Id: I6d51c8fbd37928409138127385aef57d3ce4c1dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4573565
Reviewed-by: Rainhard Findling <rainhard@chromium.org>
Commit-Queue: Rainhard Findling <rainhard@chromium.org>
Auto-Submit: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1150444}
  • Loading branch information
Mikel Astiz authored and Chromium LUCI CQ committed May 30, 2023
1 parent b4afc1d commit 37f9870
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "chrome/browser/privacy_sandbox/privacy_sandbox_service_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/browsing_topics/browsing_topics_service_factory.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
Expand All @@ -23,7 +23,8 @@
#endif

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

PrivacySandboxService* PrivacySandboxServiceFactory::GetForProfile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_PRIVACY_SANDBOX_PRIVACY_SANDBOX_SERVICE_FACTORY_H_
#define CHROME_BROWSER_PRIVACY_SANDBOX_PRIVACY_SANDBOX_SERVICE_FACTORY_H_

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

class PrivacySandboxService;
Expand All @@ -17,7 +17,7 @@ class PrivacySandboxServiceFactory : public ProfileKeyedServiceFactory {
static PrivacySandboxService* GetForProfile(Profile* profile);

private:
friend struct base::DefaultSingletonTraits<PrivacySandboxServiceFactory>;
friend base::NoDestructor<PrivacySandboxServiceFactory>;
PrivacySandboxServiceFactory();
~PrivacySandboxServiceFactory() override = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "chrome/browser/privacy_sandbox/privacy_sandbox_settings_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/privacy_sandbox/privacy_sandbox_settings_delegate.h"
Expand All @@ -14,7 +14,8 @@
#include "components/privacy_sandbox/privacy_sandbox_settings_impl.h"

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

privacy_sandbox::PrivacySandboxSettings*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_PRIVACY_SANDBOX_PRIVACY_SANDBOX_SETTINGS_FACTORY_H_
#define CHROME_BROWSER_PRIVACY_SANDBOX_PRIVACY_SANDBOX_SETTINGS_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 @@ -21,7 +21,7 @@ class PrivacySandboxSettingsFactory : public ProfileKeyedServiceFactory {
Profile* profile);

private:
friend struct base::DefaultSingletonTraits<PrivacySandboxSettingsFactory>;
friend base::NoDestructor<PrivacySandboxSettingsFactory>;
PrivacySandboxSettingsFactory();
~PrivacySandboxSettingsFactory() override = default;

Expand Down

0 comments on commit 37f9870

Please sign in to comment.