diff options
author | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-25 12:40:58 +0000 |
---|---|---|
committer | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-25 12:40:58 +0000 |
commit | a274a21ae4206a89fb333d8940357b530fc18436 (patch) | |
tree | 2e287373666f5b0e175485137078dc986d788ffd /components/keyed_service | |
parent | e0cfa4c690c8b0ae74c8168efa58354f6fb40e70 (diff) | |
download | chromium_src-a274a21ae4206a89fb333d8940357b530fc18436.zip chromium_src-a274a21ae4206a89fb333d8940357b530fc18436.tar.gz chromium_src-a274a21ae4206a89fb333d8940357b530fc18436.tar.bz2 |
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
Diffstat (limited to 'components/keyed_service')
6 files changed, 17 insertions, 1 deletions
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<BrowserContextKeyedBaseFactory*>(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: |