refactor: prefer using base::NoDestructor to base::{Singleton,LazyInstance} (#41424)

refactor: prefer using base::NoDestructor to base::{Singleton,LazyInstance}

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2024-02-28 11:38:49 +09:00 committed by GitHub
parent a55f23979e
commit 7331e5dfb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 44 additions and 18 deletions

View file

@ -4,6 +4,7 @@
#include "shell/browser/usb/usb_chooser_context_factory.h"
#include "base/no_destructor.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "shell/browser/electron_browser_context.h"
#include "shell/browser/usb/usb_chooser_context.h"
@ -26,7 +27,8 @@ KeyedService* UsbChooserContextFactory::BuildServiceInstanceFor(
// static
UsbChooserContextFactory* UsbChooserContextFactory::GetInstance() {
return base::Singleton<UsbChooserContextFactory>::get();
static base::NoDestructor<UsbChooserContextFactory> instance;
return instance.get();
}
// static

View file

@ -5,9 +5,13 @@
#ifndef ELECTRON_SHELL_BROWSER_USB_USB_CHOOSER_CONTEXT_FACTORY_H_
#define ELECTRON_SHELL_BROWSER_USB_USB_CHOOSER_CONTEXT_FACTORY_H_
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace base {
template <typename T>
class NoDestructor;
} // namespace base
namespace electron {
class UsbChooserContext;
@ -24,7 +28,7 @@ class UsbChooserContextFactory : public BrowserContextKeyedServiceFactory {
UsbChooserContextFactory& operator=(const UsbChooserContextFactory&) = delete;
private:
friend struct base::DefaultSingletonTraits<UsbChooserContextFactory>;
friend base::NoDestructor<UsbChooserContextFactory>;
UsbChooserContextFactory();
~UsbChooserContextFactory() override;