Index: components/keyed_service/core/refcounted_keyed_service_factory.cc |
diff --git a/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.cc b/components/keyed_service/core/refcounted_keyed_service_factory.cc |
similarity index 53% |
copy from components/keyed_service/content/refcounted_browser_context_keyed_service_factory.cc |
copy to components/keyed_service/core/refcounted_keyed_service_factory.cc |
index ac0926e4e432b51a02db21e881bfadaaccfb0e08..d33340b2d530fe7fdc5c25570e7e7160d0286529 100644 |
--- a/components/keyed_service/content/refcounted_browser_context_keyed_service_factory.cc |
+++ b/components/keyed_service/core/refcounted_keyed_service_factory.cc |
@@ -2,16 +2,25 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h" |
+#include "components/keyed_service/core/refcounted_keyed_service_factory.h" |
#include "base/logging.h" |
#include "base/stl_util.h" |
-#include "components/keyed_service/core/keyed_service.h" |
+#include "components/keyed_service/core/dependency_manager.h" |
#include "components/keyed_service/core/refcounted_keyed_service.h" |
-#include "content/public/browser/browser_context.h" |
-void RefcountedBrowserContextKeyedServiceFactory::SetTestingFactory( |
- content::BrowserContext* context, |
+RefcountedKeyedServiceFactory::RefcountedKeyedServiceFactory( |
+ const char* name, |
+ DependencyManager* manager) |
+ : KeyedServiceBaseFactory(name, manager) { |
+} |
+ |
+RefcountedKeyedServiceFactory::~RefcountedKeyedServiceFactory() { |
+ DCHECK(mapping_.empty()); |
+} |
+ |
+void RefcountedKeyedServiceFactory::SetTestingFactory( |
+ base::SupportsUserData* context, |
TestingFactoryFunction testing_factory) { |
// Destroying the context may cause us to lose data about whether |context| |
// has our preferences registered on it (since the context object itself |
@@ -22,8 +31,8 @@ void RefcountedBrowserContextKeyedServiceFactory::SetTestingFactory( |
// We have to go through the shutdown and destroy mechanisms because there |
// are unit tests that create a service on a context and then change the |
// testing service mid-test. |
- BrowserContextShutdown(context); |
- BrowserContextDestroyed(context); |
+ ContextShutdown(context); |
+ ContextDestroyed(context); |
if (add_context) |
MarkPreferencesSetOn(context); |
@@ -32,53 +41,41 @@ void RefcountedBrowserContextKeyedServiceFactory::SetTestingFactory( |
} |
scoped_refptr<RefcountedKeyedService> |
-RefcountedBrowserContextKeyedServiceFactory::SetTestingFactoryAndUse( |
- content::BrowserContext* context, |
+RefcountedKeyedServiceFactory::SetTestingFactoryAndUse( |
+ base::SupportsUserData* context, |
TestingFactoryFunction testing_factory) { |
DCHECK(testing_factory); |
SetTestingFactory(context, testing_factory); |
- return GetServiceForBrowserContext(context, true); |
-} |
- |
-RefcountedBrowserContextKeyedServiceFactory:: |
- RefcountedBrowserContextKeyedServiceFactory( |
- const char* name, |
- BrowserContextDependencyManager* manager) |
- : BrowserContextKeyedBaseFactory(name, manager) {} |
- |
-RefcountedBrowserContextKeyedServiceFactory:: |
- ~RefcountedBrowserContextKeyedServiceFactory() { |
- DCHECK(mapping_.empty()); |
+ return GetServiceForContext(context, true); |
} |
scoped_refptr<RefcountedKeyedService> |
-RefcountedBrowserContextKeyedServiceFactory::GetServiceForBrowserContext( |
- content::BrowserContext* context, |
+RefcountedKeyedServiceFactory::GetServiceForContext( |
+ base::SupportsUserData* context, |
bool create) { |
- context = GetBrowserContextToUse(context); |
+ context = GetContextToUse(context); |
if (!context) |
- return NULL; |
+ return nullptr; |
// NOTE: If you modify any of the logic below, make sure to update the |
// non-refcounted version in context_keyed_service_factory.cc! |
- RefCountedStorage::const_iterator it = mapping_.find(context); |
+ const auto& it = mapping_.find(context); |
if (it != mapping_.end()) |
return it->second; |
// Object not found. |
if (!create) |
- return NULL; // And we're forbidden from creating one. |
+ return nullptr; // And we're forbidden from creating one. |
// Create new object. |
// Check to see if we have a per-BrowserContext testing factory that we should |
// use instead of default behavior. |
scoped_refptr<RefcountedKeyedService> service; |
- BrowserContextOverriddenTestingFunctions::const_iterator jt = |
- testing_factories_.find(context); |
+ const auto& jt = testing_factories_.find(context); |
if (jt != testing_factories_.end()) { |
if (jt->second) { |
- if (!context->IsOffTheRecord()) |
- RegisterUserPrefsOnBrowserContextForTest(context); |
+ if (!IsOffTheRecord(context)) |
+ RegisterUserPrefsOnContextForTest(context); |
service = jt->second(context); |
} |
} else { |
@@ -89,22 +86,22 @@ RefcountedBrowserContextKeyedServiceFactory::GetServiceForBrowserContext( |
return service; |
} |
-void RefcountedBrowserContextKeyedServiceFactory::Associate( |
- content::BrowserContext* context, |
+void RefcountedKeyedServiceFactory::Associate( |
+ base::SupportsUserData* context, |
const scoped_refptr<RefcountedKeyedService>& service) { |
DCHECK(!ContainsKey(mapping_, context)); |
mapping_.insert(std::make_pair(context, service)); |
} |
-void RefcountedBrowserContextKeyedServiceFactory::BrowserContextShutdown( |
- content::BrowserContext* context) { |
- RefCountedStorage::iterator it = mapping_.find(context); |
+void RefcountedKeyedServiceFactory::ContextShutdown( |
+ base::SupportsUserData* context) { |
+ const auto& it = mapping_.find(context); |
if (it != mapping_.end() && it->second.get()) |
it->second->ShutdownOnUIThread(); |
} |
-void RefcountedBrowserContextKeyedServiceFactory::BrowserContextDestroyed( |
- content::BrowserContext* context) { |
+void RefcountedKeyedServiceFactory::ContextDestroyed( |
+ base::SupportsUserData* context) { |
// We "merely" drop our reference to the service. Hopefully this will cause |
// the service to be destroyed. If not, oh well. |
mapping_.erase(context); |
@@ -115,20 +112,20 @@ void RefcountedBrowserContextKeyedServiceFactory::BrowserContextDestroyed( |
// in this file). |
testing_factories_.erase(context); |
- BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context); |
+ KeyedServiceBaseFactory::ContextDestroyed(context); |
} |
-void RefcountedBrowserContextKeyedServiceFactory::SetEmptyTestingFactory( |
- content::BrowserContext* context) { |
- SetTestingFactory(context, NULL); |
+void RefcountedKeyedServiceFactory::SetEmptyTestingFactory( |
+ base::SupportsUserData* context) { |
+ SetTestingFactory(context, nullptr); |
} |
-bool RefcountedBrowserContextKeyedServiceFactory::HasTestingFactory( |
- content::BrowserContext* context) { |
+bool RefcountedKeyedServiceFactory::HasTestingFactory( |
+ base::SupportsUserData* context) { |
return testing_factories_.find(context) != testing_factories_.end(); |
} |
-void RefcountedBrowserContextKeyedServiceFactory::CreateServiceNow( |
- content::BrowserContext* context) { |
- GetServiceForBrowserContext(context, true); |
+void RefcountedKeyedServiceFactory::CreateServiceNow( |
+ base::SupportsUserData* context) { |
+ GetServiceForContext(context, true); |
} |