From a274a21ae4206a89fb333d8940357b530fc18436 Mon Sep 17 00:00:00 2001 From: "grt@chromium.org" Date: Wed, 25 Jun 2014 12:40:58 +0000 Subject: Allow tests to provide a TestingFactoryFunction for NULLWhileTesting factories. TestingProfile provides a means by which tests may provide TestingFactoryFunctions. Previously, these were discaded by BrowserContextDependencyManager::DoCreateBrowserContextServices if ServiceIsNULLWhileTesting returned true. This made it impossible for tests to provide factory functions that were in place at the very beginning of the profile lifecycle since DoCreateBrowserContextServices would NULL them out. With this change, DoCreateBrowserContextServices will not override test-provided factory functions. R=erg@chromium.org BUG= Review URL: https://codereview.chromium.org/354653004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279691 0039d316-1c4b-4281-b951-d872f2087c98 --- .../keyed_service/content/browser_context_dependency_manager.cc | 3 ++- .../keyed_service/content/browser_context_keyed_base_factory.h | 3 +++ .../keyed_service/content/browser_context_keyed_service_factory.cc | 5 +++++ .../keyed_service/content/browser_context_keyed_service_factory.h | 1 + .../content/refcounted_browser_context_keyed_service_factory.cc | 5 +++++ .../content/refcounted_browser_context_keyed_service_factory.h | 1 + 6 files changed, 17 insertions(+), 1 deletion(-) (limited to 'components/keyed_service') diff --git a/components/keyed_service/content/browser_context_dependency_manager.cc b/components/keyed_service/content/browser_context_dependency_manager.cc index 98e4e29..a0538e7 100644 --- a/components/keyed_service/content/browser_context_dependency_manager.cc +++ b/components/keyed_service/content/browser_context_dependency_manager.cc @@ -91,7 +91,8 @@ void BrowserContextDependencyManager::DoCreateBrowserContextServices( for (size_t i = 0; i < construction_order.size(); i++) { BrowserContextKeyedBaseFactory* factory = static_cast(construction_order[i]); - if (is_testing_context && factory->ServiceIsNULLWhileTesting()) { + if (is_testing_context && factory->ServiceIsNULLWhileTesting() && + !factory->HasTestingFactory(context)) { factory->SetEmptyTestingFactory(context); } else if (factory->ServiceIsCreatedWithBrowserContext()) { // Create the service. diff --git a/components/keyed_service/content/browser_context_keyed_base_factory.h b/components/keyed_service/content/browser_context_keyed_base_factory.h index b1f2e5f..86e569d 100644 --- a/components/keyed_service/content/browser_context_keyed_base_factory.h +++ b/components/keyed_service/content/browser_context_keyed_base_factory.h @@ -133,6 +133,9 @@ class KEYED_SERVICE_EXPORT BrowserContextKeyedBaseFactory // subclasses that they should disable testing. virtual void SetEmptyTestingFactory(content::BrowserContext* context) = 0; + // Returns true if a testing factory function has been set for |context|. + virtual bool HasTestingFactory(content::BrowserContext* context) = 0; + // We also need a generalized, non-returning method that generates the object // now for when we're creating the context. virtual void CreateServiceNow(content::BrowserContext* context) = 0; diff --git a/components/keyed_service/content/browser_context_keyed_service_factory.cc b/components/keyed_service/content/browser_context_keyed_service_factory.cc index f2180a6..10be1bc 100644 --- a/components/keyed_service/content/browser_context_keyed_service_factory.cc +++ b/components/keyed_service/content/browser_context_keyed_service_factory.cc @@ -136,6 +136,11 @@ void BrowserContextKeyedServiceFactory::SetEmptyTestingFactory( SetTestingFactory(context, NULL); } +bool BrowserContextKeyedServiceFactory::HasTestingFactory( + content::BrowserContext* context) { + return testing_factories_.find(context) != testing_factories_.end(); +} + void BrowserContextKeyedServiceFactory::CreateServiceNow( content::BrowserContext* context) { GetServiceForBrowserContext(context, true); diff --git a/components/keyed_service/content/browser_context_keyed_service_factory.h b/components/keyed_service/content/browser_context_keyed_service_factory.h index 91370dd..2049ccf 100644 --- a/components/keyed_service/content/browser_context_keyed_service_factory.h +++ b/components/keyed_service/content/browser_context_keyed_service_factory.h @@ -99,6 +99,7 @@ class KEYED_SERVICE_EXPORT BrowserContextKeyedServiceFactory virtual void SetEmptyTestingFactory(content::BrowserContext* context) OVERRIDE; + virtual bool HasTestingFactory(content::BrowserContext* context) OVERRIDE; virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE; private: diff --git a/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.cc b/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.cc index 4f75d99..f3952bf 100644 --- a/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.cc +++ b/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.cc @@ -123,6 +123,11 @@ void RefcountedBrowserContextKeyedServiceFactory::SetEmptyTestingFactory( SetTestingFactory(context, NULL); } +bool RefcountedBrowserContextKeyedServiceFactory::HasTestingFactory( + content::BrowserContext* context) { + return testing_factories_.find(context) != testing_factories_.end(); +} + void RefcountedBrowserContextKeyedServiceFactory::CreateServiceNow( content::BrowserContext* context) { GetServiceForBrowserContext(context, true); diff --git a/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h b/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h index 71d98b1..15fd9d9 100644 --- a/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h +++ b/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h @@ -77,6 +77,7 @@ class KEYED_SERVICE_EXPORT RefcountedBrowserContextKeyedServiceFactory OVERRIDE; virtual void SetEmptyTestingFactory(content::BrowserContext* context) OVERRIDE; + virtual bool HasTestingFactory(content::BrowserContext* context) OVERRIDE; virtual void CreateServiceNow(content::BrowserContext* context) OVERRIDE; private: -- cgit v1.1