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:
parent
a55f23979e
commit
7331e5dfb1
12 changed files with 44 additions and 18 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "shell/browser/serial/serial_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/serial/serial_chooser_context.h"
|
||||
|
@ -26,7 +27,8 @@ KeyedService* SerialChooserContextFactory::BuildServiceInstanceFor(
|
|||
|
||||
// static
|
||||
SerialChooserContextFactory* SerialChooserContextFactory::GetInstance() {
|
||||
return base::Singleton<SerialChooserContextFactory>::get();
|
||||
static base::NoDestructor<SerialChooserContextFactory> instance;
|
||||
return instance.get();
|
||||
}
|
||||
|
||||
// static
|
||||
|
|
|
@ -5,10 +5,14 @@
|
|||
#ifndef ELECTRON_SHELL_BROWSER_SERIAL_SERIAL_CHOOSER_CONTEXT_FACTORY_H_
|
||||
#define ELECTRON_SHELL_BROWSER_SERIAL_SERIAL_CHOOSER_CONTEXT_FACTORY_H_
|
||||
|
||||
#include "base/memory/singleton.h"
|
||||
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
|
||||
#include "shell/browser/serial/serial_chooser_context.h"
|
||||
|
||||
namespace base {
|
||||
template <typename T>
|
||||
class NoDestructor;
|
||||
} // namespace base
|
||||
|
||||
namespace electron {
|
||||
|
||||
class SerialChooserContext;
|
||||
|
@ -20,7 +24,7 @@ class SerialChooserContextFactory : public BrowserContextKeyedServiceFactory {
|
|||
static SerialChooserContextFactory* GetInstance();
|
||||
|
||||
private:
|
||||
friend struct base::DefaultSingletonTraits<SerialChooserContextFactory>;
|
||||
friend base::NoDestructor<SerialChooserContextFactory>;
|
||||
|
||||
SerialChooserContextFactory();
|
||||
~SerialChooserContextFactory() override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue