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

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

Bug: 925323
Change-Id: I344e8bc22fc18d79875b7904edc6982a035a218c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4573384
Auto-Submit: Mikel Astiz <mastiz@chromium.org>
Reviewed-by: Annie Sullivan <sullivan@chromium.org>
Commit-Queue: Annie Sullivan <sullivan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1150317}
  • Loading branch information
Mikel Astiz authored and Chromium LUCI CQ committed May 29, 2023
1 parent 55e1c77 commit 427df65
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "chrome/browser/page_load_metrics/observers/https_engagement_metrics/https_engagement_service_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "chrome/browser/page_load_metrics/observers/https_engagement_metrics/https_engagement_service.h"

// static
Expand All @@ -16,7 +16,8 @@ HttpsEngagementService* HttpsEngagementServiceFactory::GetForBrowserContext(

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

HttpsEngagementServiceFactory::HttpsEngagementServiceFactory()
Expand All @@ -29,7 +30,7 @@ HttpsEngagementServiceFactory::HttpsEngagementServiceFactory()
.WithGuest(ProfileSelection::kRedirectedToOriginal)
.Build()) {}

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

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

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

class HttpsEngagementService;
Expand All @@ -31,7 +31,7 @@ class HttpsEngagementServiceFactory : public ProfileKeyedServiceFactory {
const HttpsEngagementServiceFactory&) = delete;

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

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

#include "chrome/browser/page_load_metrics/page_load_metrics_memory_tracker_factory.h"

#include "base/memory/singleton.h"
#include "base/no_destructor.h"
#include "components/page_load_metrics/browser/page_load_metrics_memory_tracker.h"

namespace page_load_metrics {
Expand All @@ -18,7 +18,8 @@ PageLoadMetricsMemoryTrackerFactory::GetForBrowserContext(

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

PageLoadMetricsMemoryTrackerFactory::PageLoadMetricsMemoryTrackerFactory()
Expand Down

0 comments on commit 427df65

Please sign in to comment.