Commit ab030263 authored by Martin Sramek's avatar Martin Sramek Committed by Commit Bot

Fix the singleton in ConsentAuditorFactory

ConsentAuditorFactory used CR_DEFINE_STATIC_LOCAL to define a singleton.
In single-process tests, this results in the factory surviving between
subsequent test runs.

Instead, use base::Singleton which is destroyed and recreated with the
test fixture.

Bug: 781765
Change-Id: I46374d6c28ece58eec764db3ff4fa5cffd43216b
Reviewed-on: https://chromium-review.googlesource.com/897947Reviewed-by: default avatarBalazs Engedy <engedy@chromium.org>
Commit-Queue: Martin Šrámek <msramek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533885}
parent 8bbdbe2d
...@@ -15,8 +15,7 @@ ...@@ -15,8 +15,7 @@
// static // static
ConsentAuditorFactory* ConsentAuditorFactory::GetInstance() { ConsentAuditorFactory* ConsentAuditorFactory::GetInstance() {
CR_DEFINE_STATIC_LOCAL(ConsentAuditorFactory, factory, ()); return base::Singleton<ConsentAuditorFactory>::get();
return &factory;
} }
// static // static
......
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
#include "base/macros.h" #include "base/macros.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace base {
template <typename T>
struct DefaultSingletonTraits;
}
namespace consent_auditor { namespace consent_auditor {
class ConsentAuditor; class ConsentAuditor;
} }
...@@ -27,6 +32,8 @@ class ConsentAuditorFactory : public BrowserContextKeyedServiceFactory { ...@@ -27,6 +32,8 @@ class ConsentAuditorFactory : public BrowserContextKeyedServiceFactory {
static consent_auditor::ConsentAuditor* GetForProfile(Profile* profile); static consent_auditor::ConsentAuditor* GetForProfile(Profile* profile);
private: private:
friend struct base::DefaultSingletonTraits<ConsentAuditorFactory>;
ConsentAuditorFactory(); ConsentAuditorFactory();
~ConsentAuditorFactory() override; ~ConsentAuditorFactory() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment