Commit f5bfe410 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Convert ProfileInvalidationProviderFactory to TestingFactory

TestingFactory is a base::Callback<> while TestingFactoryFunction
is a function pointer. Convert ProfileInvalidationProviderFactory
to the callback based type.

Bug: 809610
Change-Id: Id6ddc4e75960f5fd1ed952877d4bebdca515b706
Reviewed-on: https://chromium-review.googlesource.com/c/1246166Reviewed-by: default avatarBartosz Fabianowski <bartfab@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarPavel Yatsuk <pavely@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597058}
parent 56dd83c9
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "base/bind.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
...@@ -212,7 +213,8 @@ void AffiliatedInvalidationServiceProviderImplTest::SetUp() { ...@@ -212,7 +213,8 @@ void AffiliatedInvalidationServiceProviderImplTest::SetUp() {
TestingBrowserProcess::GetGlobal()->local_state()); TestingBrowserProcess::GetGlobal()->local_state());
invalidation::DeprecatedProfileInvalidationProviderFactory::GetInstance() invalidation::DeprecatedProfileInvalidationProviderFactory::GetInstance()
->RegisterTestingFactory(BuildProfileInvalidationProvider); ->RegisterTestingFactory(
base::BindRepeating(&BuildProfileInvalidationProvider));
provider_ = std::make_unique<AffiliatedInvalidationServiceProviderImpl>(); provider_ = std::make_unique<AffiliatedInvalidationServiceProviderImpl>();
} }
...@@ -224,7 +226,8 @@ void AffiliatedInvalidationServiceProviderImplTest::TearDown() { ...@@ -224,7 +226,8 @@ void AffiliatedInvalidationServiceProviderImplTest::TearDown() {
test_shared_loader_factory_->Detach(); test_shared_loader_factory_->Detach();
invalidation::DeprecatedProfileInvalidationProviderFactory::GetInstance() invalidation::DeprecatedProfileInvalidationProviderFactory::GetInstance()
->RegisterTestingFactory(nullptr); ->RegisterTestingFactory(
BrowserContextKeyedServiceFactory::TestingFactory());
chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); chromeos::DeviceOAuth2TokenServiceFactory::Shutdown();
chromeos::DBusThreadManager::Shutdown(); chromeos::DBusThreadManager::Shutdown();
chromeos::SystemSaltGetter::Shutdown(); chromeos::SystemSaltGetter::Shutdown();
......
...@@ -82,8 +82,7 @@ DeprecatedProfileInvalidationProviderFactory:: ...@@ -82,8 +82,7 @@ DeprecatedProfileInvalidationProviderFactory::
DeprecatedProfileInvalidationProviderFactory() DeprecatedProfileInvalidationProviderFactory()
: BrowserContextKeyedServiceFactory( : BrowserContextKeyedServiceFactory(
"InvalidationService", "InvalidationService",
BrowserContextDependencyManager::GetInstance()), BrowserContextDependencyManager::GetInstance()) {
testing_factory_(NULL) {
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
DependsOn(IdentityManagerFactory::GetInstance()); DependsOn(IdentityManagerFactory::GetInstance());
DependsOn(gcm::GCMProfileServiceFactory::GetInstance()); DependsOn(gcm::GCMProfileServiceFactory::GetInstance());
...@@ -94,15 +93,15 @@ DeprecatedProfileInvalidationProviderFactory:: ...@@ -94,15 +93,15 @@ DeprecatedProfileInvalidationProviderFactory::
~DeprecatedProfileInvalidationProviderFactory() {} ~DeprecatedProfileInvalidationProviderFactory() {}
void DeprecatedProfileInvalidationProviderFactory::RegisterTestingFactory( void DeprecatedProfileInvalidationProviderFactory::RegisterTestingFactory(
TestingFactoryFunction testing_factory) { TestingFactory testing_factory) {
testing_factory_ = testing_factory; testing_factory_ = std::move(testing_factory);
} }
KeyedService* KeyedService*
DeprecatedProfileInvalidationProviderFactory::BuildServiceInstanceFor( DeprecatedProfileInvalidationProviderFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
if (testing_factory_) if (testing_factory_)
return testing_factory_(context).release(); return testing_factory_.Run(context).release();
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Android does not need an IdentityProvider, because it gets the account // Android does not need an IdentityProvider, because it gets the account
......
...@@ -40,7 +40,7 @@ class DeprecatedProfileInvalidationProviderFactory ...@@ -40,7 +40,7 @@ class DeprecatedProfileInvalidationProviderFactory
// Switches service creation to go through |testing_factory| for all browser // Switches service creation to go through |testing_factory| for all browser
// contexts. // contexts.
void RegisterTestingFactory(TestingFactoryFunction testing_factory); void RegisterTestingFactory(TestingFactory testing_factory);
private: private:
friend class DeprecatedProfileInvalidationProviderFactoryTestBase; friend class DeprecatedProfileInvalidationProviderFactoryTestBase;
...@@ -57,7 +57,7 @@ class DeprecatedProfileInvalidationProviderFactory ...@@ -57,7 +57,7 @@ class DeprecatedProfileInvalidationProviderFactory
void RegisterProfilePrefs( void RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) override; user_prefs::PrefRegistrySyncable* registry) override;
TestingFactoryFunction testing_factory_; TestingFactory testing_factory_;
DISALLOW_COPY_AND_ASSIGN(DeprecatedProfileInvalidationProviderFactory); DISALLOW_COPY_AND_ASSIGN(DeprecatedProfileInvalidationProviderFactory);
}; };
......
...@@ -80,8 +80,7 @@ ProfileInvalidationProviderFactory::GetInstance() { ...@@ -80,8 +80,7 @@ ProfileInvalidationProviderFactory::GetInstance() {
ProfileInvalidationProviderFactory::ProfileInvalidationProviderFactory() ProfileInvalidationProviderFactory::ProfileInvalidationProviderFactory()
: BrowserContextKeyedServiceFactory( : BrowserContextKeyedServiceFactory(
"InvalidationService", "InvalidationService",
BrowserContextDependencyManager::GetInstance()), BrowserContextDependencyManager::GetInstance()) {
testing_factory_(NULL) {
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
DependsOn(IdentityManagerFactory::GetInstance()); DependsOn(IdentityManagerFactory::GetInstance());
DependsOn(gcm::GCMProfileServiceFactory::GetInstance()); DependsOn(gcm::GCMProfileServiceFactory::GetInstance());
...@@ -92,14 +91,14 @@ ProfileInvalidationProviderFactory::~ProfileInvalidationProviderFactory() = ...@@ -92,14 +91,14 @@ ProfileInvalidationProviderFactory::~ProfileInvalidationProviderFactory() =
default; default;
void ProfileInvalidationProviderFactory::RegisterTestingFactory( void ProfileInvalidationProviderFactory::RegisterTestingFactory(
TestingFactoryFunction testing_factory) { TestingFactory testing_factory) {
testing_factory_ = testing_factory; testing_factory_ = std::move(testing_factory);
} }
KeyedService* ProfileInvalidationProviderFactory::BuildServiceInstanceFor( KeyedService* ProfileInvalidationProviderFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
if (testing_factory_) if (testing_factory_)
return testing_factory_(context).release(); return testing_factory_.Run(context).release();
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Android does not need an IdentityProvider, because it gets the account // Android does not need an IdentityProvider, because it gets the account
......
...@@ -36,7 +36,7 @@ class ProfileInvalidationProviderFactory ...@@ -36,7 +36,7 @@ class ProfileInvalidationProviderFactory
// Switches service creation to go through |testing_factory| for all browser // Switches service creation to go through |testing_factory| for all browser
// contexts. // contexts.
void RegisterTestingFactory(TestingFactoryFunction testing_factory); void RegisterTestingFactory(TestingFactory testing_factory);
private: private:
friend class ProfileInvalidationProviderFactoryTestBase; friend class ProfileInvalidationProviderFactoryTestBase;
...@@ -51,7 +51,7 @@ class ProfileInvalidationProviderFactory ...@@ -51,7 +51,7 @@ class ProfileInvalidationProviderFactory
KeyedService* BuildServiceInstanceFor( KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override; content::BrowserContext* context) const override;
TestingFactoryFunction testing_factory_; TestingFactory testing_factory_;
DISALLOW_COPY_AND_ASSIGN(ProfileInvalidationProviderFactory); DISALLOW_COPY_AND_ASSIGN(ProfileInvalidationProviderFactory);
}; };
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <memory> #include <memory>
#include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
...@@ -202,7 +203,8 @@ class CloudPolicyTest : public InProcessBrowserTest, ...@@ -202,7 +203,8 @@ class CloudPolicyTest : public InProcessBrowserTest,
command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url); command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, url);
invalidation::DeprecatedProfileInvalidationProviderFactory::GetInstance() invalidation::DeprecatedProfileInvalidationProviderFactory::GetInstance()
->RegisterTestingFactory(BuildFakeProfileInvalidationProvider); ->RegisterTestingFactory(
base::BindRepeating(&BuildFakeProfileInvalidationProvider));
} }
void SetUpOnMainThread() override { void SetUpOnMainThread() 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