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

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

Bug: 925323
Change-Id: I268eabeeccd3d27b04b5ba322c2811e2500a28c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4568013
Reviewed-by: Chase Phillips <cmp@chromium.org>
Auto-Submit: Mikel Astiz <mastiz@chromium.org>
Commit-Queue: Chase Phillips <cmp@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1150321}
  • Loading branch information
Mikel Astiz authored and Chromium LUCI CQ committed May 29, 2023
1 parent 760b0c0 commit e182752
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions chrome/browser/badging/badge_manager_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/badging/badge_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/web_app_provider_factory.h"
Expand All @@ -24,7 +24,8 @@ BadgeManager* BadgeManagerFactory::GetForProfile(Profile* profile) {

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

BadgeManagerFactory::BadgeManagerFactory()
Expand All @@ -39,7 +40,7 @@ BadgeManagerFactory::BadgeManagerFactory()
DependsOn(web_app::WebAppProviderFactory::GetInstance());
}

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

KeyedService* BadgeManagerFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/badging/badge_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 @@ -32,7 +32,7 @@ class BadgeManagerFactory : public ProfileKeyedServiceFactory {
BadgeManagerFactory& operator=(const BadgeManagerFactory&) = delete;

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

BadgeManagerFactory();
~BadgeManagerFactory() override;
Expand Down

0 comments on commit e182752

Please sign in to comment.