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

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

Bug: 925323
Change-Id: Id285df999e7af5e53e06f6a892c6705ac39bc994
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4573382
Reviewed-by: Maxim Kolosovskiy <kolos@chromium.org>
Auto-Submit: Mikel Astiz <mastiz@chromium.org>
Commit-Queue: Maxim Kolosovskiy <kolos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1150401}
  • Loading branch information
Mikel Astiz authored and Chromium LUCI CQ committed May 30, 2023
1 parent 16281c1 commit 77b19d7
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "chrome/browser/autofill/autocomplete_history_manager_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_data_service_factory.h"
#include "components/autofill/core/browser/autocomplete_history_manager.h"
Expand All @@ -22,7 +22,8 @@ AutocompleteHistoryManager* AutocompleteHistoryManagerFactory::GetForProfile(
// static
AutocompleteHistoryManagerFactory*
AutocompleteHistoryManagerFactory::GetInstance() {
return base::Singleton<AutocompleteHistoryManagerFactory>::get();
static base::NoDestructor<AutocompleteHistoryManagerFactory> instance;
return instance.get();
}

AutocompleteHistoryManagerFactory::AutocompleteHistoryManagerFactory()
Expand All @@ -37,7 +38,8 @@ AutocompleteHistoryManagerFactory::AutocompleteHistoryManagerFactory()
DependsOn(WebDataServiceFactory::GetInstance());
}

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

KeyedService* AutocompleteHistoryManagerFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

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

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

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

#include "chrome/browser/autofill/autofill_offer_manager_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "build/build_config.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "components/autofill/core/browser/payments/autofill_offer_manager.h"
Expand All @@ -25,7 +25,8 @@ AutofillOfferManager* AutofillOfferManagerFactory::GetForBrowserContext(

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

AutofillOfferManagerFactory::AutofillOfferManagerFactory()
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/autofill/autofill_offer_manager_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

namespace autofill {
Expand All @@ -31,7 +31,7 @@ class AutofillOfferManagerFactory : public ProfileKeyedServiceFactory {
static AutofillOfferManagerFactory* GetInstance();

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

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

#include "chrome/browser/autofill/autofill_optimization_guide_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/profiles/profile.h"
Expand All @@ -24,7 +24,8 @@ AutofillOptimizationGuide* AutofillOptimizationGuideFactory::GetForProfile(
// static
AutofillOptimizationGuideFactory*
AutofillOptimizationGuideFactory::GetInstance() {
return base::Singleton<AutofillOptimizationGuideFactory>::get();
static base::NoDestructor<AutofillOptimizationGuideFactory> instance;
return instance.get();
}

AutofillOptimizationGuideFactory::AutofillOptimizationGuideFactory()
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/autofill/autofill_optimization_guide_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

class KeyedService;
Expand All @@ -32,7 +32,7 @@ class AutofillOptimizationGuideFactory : public ProfileKeyedServiceFactory {
static AutofillOptimizationGuideFactory* GetInstance();

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

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

#include "chrome/browser/autofill/iban_manager_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/autofill/core/browser/iban_manager.h"
Expand All @@ -19,7 +19,8 @@ IBANManager* IBANManagerFactory::GetForProfile(Profile* profile) {

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

IBANManagerFactory::IBANManagerFactory()
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/autofill/iban_manager_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

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

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

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

#include "chrome/browser/autofill/merchant_promo_code_manager_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/autofill/core/browser/merchant_promo_code_manager.h"
Expand All @@ -21,7 +21,8 @@ MerchantPromoCodeManager* MerchantPromoCodeManagerFactory::GetForProfile(
// static
MerchantPromoCodeManagerFactory*
MerchantPromoCodeManagerFactory::GetInstance() {
return base::Singleton<MerchantPromoCodeManagerFactory>::get();
static base::NoDestructor<MerchantPromoCodeManagerFactory> instance;
return instance.get();
}

MerchantPromoCodeManagerFactory::MerchantPromoCodeManagerFactory()
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/autofill/merchant_promo_code_manager_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

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

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

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

#include "chrome/browser/autofill/personal_data_manager_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/autofill/autofill_image_fetcher_factory.h"
#include "chrome/browser/autofill/strike_database_factory.h"
#include "chrome/browser/browser_process.h"
Expand Down Expand Up @@ -52,7 +52,8 @@ PersonalDataManager* PersonalDataManagerFactory::GetForBrowserContext(

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

PersonalDataManagerFactory::PersonalDataManagerFactory()
Expand Down
5 changes: 3 additions & 2 deletions chrome/browser/autofill/personal_data_manager_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 KeyedService;
Expand Down Expand Up @@ -39,7 +40,7 @@ class PersonalDataManagerFactory : public ProfileKeyedServiceFactory {
content::BrowserContext* context);

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

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

#include "chrome/browser/autofill/strike_database_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/profiles/profile.h"
#include "components/autofill/core/browser/strike_databases/strike_database.h"
#include "content/public/browser/storage_partition.h"
Expand All @@ -19,7 +19,8 @@ StrikeDatabase* StrikeDatabaseFactory::GetForProfile(Profile* profile) {

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

StrikeDatabaseFactory::StrikeDatabaseFactory()
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/autofill/strike_database_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

class Profile;
Expand All @@ -32,7 +32,7 @@ class StrikeDatabaseFactory : public ProfileKeyedServiceFactory {
StrikeDatabaseFactory& operator=(const StrikeDatabaseFactory&) = delete;

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

StrikeDatabaseFactory();
~StrikeDatabaseFactory() override;
Expand Down

0 comments on commit 77b19d7

Please sign in to comment.