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

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

Bug: 925323
Change-Id: Ibbd06d36ac23eeb0118dc566edb1a31550971b39
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4572806
Auto-Submit: Mikel Astiz <mastiz@chromium.org>
Reviewed-by: Daniel Rubery <drubery@chromium.org>
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1150662}
  • Loading branch information
Mikel Astiz authored and Chromium LUCI CQ committed May 30, 2023
1 parent 54b1f02 commit 366c580
Show file tree
Hide file tree
Showing 28 changed files with 61 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ AdvancedProtectionStatusManagerFactory::GetForProfile(Profile* profile) {
// static
AdvancedProtectionStatusManagerFactory*
AdvancedProtectionStatusManagerFactory::GetInstance() {
return base::Singleton<AdvancedProtectionStatusManagerFactory>::get();
static base::NoDestructor<AdvancedProtectionStatusManagerFactory> instance;
return instance.get();
}

// static
Expand All @@ -53,7 +54,7 @@ AdvancedProtectionStatusManagerFactory::AdvancedProtectionStatusManagerFactory()
}

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

KeyedService* AdvancedProtectionStatusManagerFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_SAFE_BROWSING_ADVANCED_PROTECTION_STATUS_MANAGER_FACTORY_H_
#define CHROME_BROWSER_SAFE_BROWSING_ADVANCED_PROTECTION_STATUS_MANAGER_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 @@ -32,8 +32,7 @@ class AdvancedProtectionStatusManagerFactory
const AdvancedProtectionStatusManagerFactory&) = delete;

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

AdvancedProtectionStatusManagerFactory();
~AdvancedProtectionStatusManagerFactory() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const size_t kMaxReportCountInQueue = 5;
// static
CertificateReportingServiceFactory*
CertificateReportingServiceFactory::GetInstance() {
return base::Singleton<CertificateReportingServiceFactory>::get();
static base::NoDestructor<CertificateReportingServiceFactory> instance;
return instance.get();
}

// static
Expand Down Expand Up @@ -90,7 +91,8 @@ CertificateReportingServiceFactory::CertificateReportingServiceFactory()
max_queued_report_count_(kMaxReportCountInQueue),
service_reset_callback_(base::DoNothing()) {}

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

KeyedService* CertificateReportingServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* browser_context) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define CHROME_BROWSER_SAFE_BROWSING_CERTIFICATE_REPORTING_SERVICE_FACTORY_H_

#include "base/memory/raw_ptr.h"
#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "base/time/time.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
Expand Down Expand Up @@ -47,8 +47,7 @@ class CertificateReportingServiceFactory : public ProfileKeyedServiceFactory {
scoped_refptr<network::SharedURLLoaderFactory> factory);

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

CertificateReportingServiceFactory();
~CertificateReportingServiceFactory() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ ChromeEnterpriseRealTimeUrlLookupServiceFactory::GetForProfile(
// static
ChromeEnterpriseRealTimeUrlLookupServiceFactory*
ChromeEnterpriseRealTimeUrlLookupServiceFactory::GetInstance() {
return base::Singleton<
ChromeEnterpriseRealTimeUrlLookupServiceFactory>::get();
static base::NoDestructor<ChromeEnterpriseRealTimeUrlLookupServiceFactory>
instance;
return instance.get();
}

ChromeEnterpriseRealTimeUrlLookupServiceFactory::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_SAFE_BROWSING_CHROME_ENTERPRISE_URL_LOOKUP_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SAFE_BROWSING_CHROME_ENTERPRISE_URL_LOOKUP_SERVICE_FACTORY_H_

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

class KeyedService;
Expand Down Expand Up @@ -40,8 +40,7 @@ class ChromeEnterpriseRealTimeUrlLookupServiceFactory
const ChromeEnterpriseRealTimeUrlLookupServiceFactory&) = delete;

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

ChromeEnterpriseRealTimeUrlLookupServiceFactory();
~ChromeEnterpriseRealTimeUrlLookupServiceFactory() override = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ ChromePasswordProtectionServiceFactory::GetForProfile(Profile* profile) {
// static
ChromePasswordProtectionServiceFactory*
ChromePasswordProtectionServiceFactory::GetInstance() {
return base::Singleton<ChromePasswordProtectionServiceFactory>::get();
static base::NoDestructor<ChromePasswordProtectionServiceFactory> instance;
return instance.get();
}

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

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

class KeyedService;
Expand Down Expand Up @@ -39,8 +39,7 @@ class ChromePasswordProtectionServiceFactory
const ChromePasswordProtectionServiceFactory&) = delete;

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

ChromePasswordProtectionServiceFactory();
~ChromePasswordProtectionServiceFactory() override = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ ClientSideDetectionService* ClientSideDetectionServiceFactory::GetForProfile(
// static
ClientSideDetectionServiceFactory*
ClientSideDetectionServiceFactory::GetInstance() {
return base::Singleton<ClientSideDetectionServiceFactory>::get();
static base::NoDestructor<ClientSideDetectionServiceFactory> instance;
return instance.get();
}

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

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

class KeyedService;
Expand Down Expand Up @@ -33,7 +33,7 @@ class ClientSideDetectionServiceFactory : public ProfileKeyedServiceFactory {
const ClientSideDetectionServiceFactory&) = delete;

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

ClientSideDetectionServiceFactory();
~ClientSideDetectionServiceFactory() override = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ BinaryUploadService* CloudBinaryUploadServiceFactory::GetForProfile(
// static
CloudBinaryUploadServiceFactory*
CloudBinaryUploadServiceFactory::GetInstance() {
return base::Singleton<CloudBinaryUploadServiceFactory>::get();
static base::NoDestructor<CloudBinaryUploadServiceFactory> instance;
return instance.get();
}

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

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

class KeyedService;
Expand Down Expand Up @@ -33,7 +33,7 @@ class CloudBinaryUploadServiceFactory : public ProfileKeyedServiceFactory {
const CloudBinaryUploadServiceFactory&) = delete;

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

CloudBinaryUploadServiceFactory();
~CloudBinaryUploadServiceFactory() override = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ HashRealTimeService* HashRealTimeServiceFactory::GetForProfile(

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

HashRealTimeServiceFactory::HashRealTimeServiceFactory()
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/safe_browsing/hash_realtime_service_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_SAFE_BROWSING_HASH_REALTIME_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SAFE_BROWSING_HASH_REALTIME_SERVICE_FACTORY_H_

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"
#include "services/network/public/mojom/network_context.mojom.h"

Expand Down Expand Up @@ -37,7 +37,7 @@ class HashRealTimeServiceFactory : public ProfileKeyedServiceFactory {
delete;

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

HashRealTimeServiceFactory();
~HashRealTimeServiceFactory() override = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace safe_browsing {

// static
NetworkContextServiceFactory* NetworkContextServiceFactory::GetInstance() {
return base::Singleton<NetworkContextServiceFactory>::get();
static base::NoDestructor<NetworkContextServiceFactory> 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_SAFE_BROWSING_NETWORK_CONTEXT_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SAFE_BROWSING_NETWORK_CONTEXT_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 @@ -27,7 +27,7 @@ class NetworkContextServiceFactory : public ProfileKeyedServiceFactory {
content::BrowserContext* context);

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

NetworkContextServiceFactory();
~NetworkContextServiceFactory() override;
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/safe_browsing/ohttp_key_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ OhttpKeyService* OhttpKeyServiceFactory::GetForProfile(Profile* profile) {

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

OhttpKeyServiceFactory::OhttpKeyServiceFactory()
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/safe_browsing/ohttp_key_service_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_SAFE_BROWSING_OHTTP_KEY_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SAFE_BROWSING_OHTTP_KEY_SERVICE_FACTORY_H_

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

class KeyedService;
Expand Down Expand Up @@ -36,7 +36,7 @@ class OhttpKeyServiceFactory : public ProfileKeyedServiceFactory {
OhttpKeyServiceFactory& operator=(const OhttpKeyServiceFactory&) = delete;

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

OhttpKeyServiceFactory();
~OhttpKeyServiceFactory() override = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ SafeBrowsingMetricsCollectorFactory::GetForProfile(Profile* profile) {
// static
SafeBrowsingMetricsCollectorFactory*
SafeBrowsingMetricsCollectorFactory::GetInstance() {
return base::Singleton<SafeBrowsingMetricsCollectorFactory>::get();
static base::NoDestructor<SafeBrowsingMetricsCollectorFactory> instance;
return instance.get();
}

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

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

class KeyedService;
Expand Down Expand Up @@ -37,8 +37,7 @@ class SafeBrowsingMetricsCollectorFactory : public ProfileKeyedServiceFactory {
const SafeBrowsingMetricsCollectorFactory&) = delete;

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

SafeBrowsingMetricsCollectorFactory();
~SafeBrowsingMetricsCollectorFactory() override = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ SafeBrowsingNavigationObserverManagerFactory::GetForBrowserContext(
// static
SafeBrowsingNavigationObserverManagerFactory*
SafeBrowsingNavigationObserverManagerFactory::GetInstance() {
return base::Singleton<SafeBrowsingNavigationObserverManagerFactory>::get();
static base::NoDestructor<SafeBrowsingNavigationObserverManagerFactory>
instance;
return instance.get();
}

SafeBrowsingNavigationObserverManagerFactory::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGER_FACTORY_H_
#define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGER_FACTORY_H_

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

class KeyedService;
Expand Down Expand Up @@ -35,8 +35,7 @@ class SafeBrowsingNavigationObserverManagerFactory
static SafeBrowsingNavigationObserverManagerFactory* GetInstance();

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

SafeBrowsingNavigationObserverManagerFactory();
~SafeBrowsingNavigationObserverManagerFactory() override = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ TailoredSecurityService* TailoredSecurityServiceFactory::GetForProfile(

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

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

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

class KeyedService;
Expand Down Expand Up @@ -35,7 +35,7 @@ class TailoredSecurityServiceFactory : public ProfileKeyedServiceFactory {
content::BrowserContext* context) const override;

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

// BrowserContextKeyedServiceFactory:
bool ServiceIsCreatedWithBrowserContext() const override;
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/safe_browsing/url_lookup_service_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ RealTimeUrlLookupService* RealTimeUrlLookupServiceFactory::GetForProfile(
// static
RealTimeUrlLookupServiceFactory*
RealTimeUrlLookupServiceFactory::GetInstance() {
return base::Singleton<RealTimeUrlLookupServiceFactory>::get();
static base::NoDestructor<RealTimeUrlLookupServiceFactory> instance;
return instance.get();
}

RealTimeUrlLookupServiceFactory::RealTimeUrlLookupServiceFactory()
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/safe_browsing/url_lookup_service_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_SAFE_BROWSING_URL_LOOKUP_SERVICE_FACTORY_H_
#define CHROME_BROWSER_SAFE_BROWSING_URL_LOOKUP_SERVICE_FACTORY_H_

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

class KeyedService;
Expand Down Expand Up @@ -37,7 +37,7 @@ class RealTimeUrlLookupServiceFactory : public ProfileKeyedServiceFactory {
const RealTimeUrlLookupServiceFactory&) = delete;

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

RealTimeUrlLookupServiceFactory();
~RealTimeUrlLookupServiceFactory() override = default;
Expand Down

0 comments on commit 366c580

Please sign in to comment.