Commit 8c1791c6 authored by sdefresne's avatar sdefresne Committed by Commit bot

Allow cross dependencies between BCKSF and BSKSF

For incremental conversion of iOS code from BrowserContextKeyedServiceFactories
to BrowserStateKeyedServiceFactories, iOS uses cross-dependencies between both
types of factories.

This CL had two virtual methods to KeyedServiceBaseFactory to convert a context
to the correct type (content::BrowserContext or web::BrowserState) and back so
that we can have BrowserStateKeyedServiceFactories registered into a
BrowserContextDependencyManager (temporary).

Implement the method in all derived classes and refactor the implementation
of GetAssociatedPrefRegistry that no longer needs to be virtual.

BUG=459020,478763

Review URL: https://codereview.chromium.org/1090373003

Cr-Commit-Position: refs/heads/master@{#326782}
parent 3371ab09
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
'msvs_disabled_warnings': [ 4267, ], 'msvs_disabled_warnings': [ 4267, ],
'dependencies': [ 'dependencies': [
'../base/base.gyp:base', '../base/base.gyp:base',
'../base/base.gyp:base_prefs',
'user_prefs',
], ],
'sources': [ 'sources': [
'keyed_service/core/dependency_graph.cc', 'keyed_service/core/dependency_graph.cc',
...@@ -55,12 +57,10 @@ ...@@ -55,12 +57,10 @@
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations. # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
'msvs_disabled_warnings': [ 4267, ], 'msvs_disabled_warnings': [ 4267, ],
'dependencies': [ 'dependencies': [
'keyed_service_core',
'../base/base.gyp:base', '../base/base.gyp:base',
'../base/base.gyp:base_prefs',
'../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'../content/content.gyp:content_common', '../content/content.gyp:content_common',
'user_prefs', 'keyed_service_core',
], ],
'include_dirs': [ 'include_dirs': [
'..', '..',
...@@ -89,7 +89,6 @@ ...@@ -89,7 +89,6 @@
], ],
'dependencies': [ 'dependencies': [
'../base/base.gyp:base', '../base/base.gyp:base',
'../base/base.gyp:base_prefs',
'../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'../ios/web/ios_web.gyp:ios_web', '../ios/web/ios_web.gyp:ios_web',
'keyed_service_core', 'keyed_service_core',
...@@ -98,10 +97,10 @@ ...@@ -98,10 +97,10 @@
'..', '..',
], ],
'sources': [ 'sources': [
'keyed_service/ios/browser_state_context_converter.cc',
'keyed_service/ios/browser_state_context_converter.h',
'keyed_service/ios/browser_state_dependency_manager.cc', 'keyed_service/ios/browser_state_dependency_manager.cc',
'keyed_service/ios/browser_state_dependency_manager.h', 'keyed_service/ios/browser_state_dependency_manager.h',
'keyed_service/ios/browser_state_helper.cc',
'keyed_service/ios/browser_state_helper.h',
'keyed_service/ios/browser_state_keyed_service_factory.cc', 'keyed_service/ios/browser_state_keyed_service_factory.cc',
'keyed_service/ios/browser_state_keyed_service_factory.h', 'keyed_service/ios/browser_state_keyed_service_factory.h',
'keyed_service/ios/refcounted_browser_state_keyed_service_factory.cc', 'keyed_service/ios/refcounted_browser_state_keyed_service_factory.cc',
......
...@@ -26,10 +26,8 @@ component("content") { ...@@ -26,10 +26,8 @@ component("content") {
deps = [ deps = [
"//base", "//base",
"//base:prefs",
"//base/third_party/dynamic_annotations", "//base/third_party/dynamic_annotations",
"//content/public/common",
"//components/keyed_service/core", "//components/keyed_service/core",
"//components/user_prefs", "//content/public/common",
] ]
} }
...@@ -19,7 +19,7 @@ const char kDumpBrowserContextDependencyGraphFlag[] = ...@@ -19,7 +19,7 @@ const char kDumpBrowserContextDependencyGraphFlag[] =
#endif // NDEBUG #endif // NDEBUG
void BrowserContextDependencyManager::RegisterProfilePrefsForServices( void BrowserContextDependencyManager::RegisterProfilePrefsForServices(
const content::BrowserContext* context, content::BrowserContext* context,
user_prefs::PrefRegistrySyncable* pref_registry) { user_prefs::PrefRegistrySyncable* pref_registry) {
TRACE_EVENT0( TRACE_EVENT0(
"browser", "browser",
...@@ -77,13 +77,15 @@ BrowserContextDependencyManager::GetInstance() { ...@@ -77,13 +77,15 @@ BrowserContextDependencyManager::GetInstance() {
return Singleton<BrowserContextDependencyManager>::get(); return Singleton<BrowserContextDependencyManager>::get();
} }
BrowserContextDependencyManager::BrowserContextDependencyManager() {} BrowserContextDependencyManager::BrowserContextDependencyManager() {
}
BrowserContextDependencyManager::~BrowserContextDependencyManager() {} BrowserContextDependencyManager::~BrowserContextDependencyManager() {
}
#ifndef NDEBUG #ifndef NDEBUG
void BrowserContextDependencyManager::DumpContextDependencies( void BrowserContextDependencyManager::DumpContextDependencies(
const base::SupportsUserData* context) const { base::SupportsUserData* context) const {
// Whenever we try to build a destruction ordering, we should also dump a // Whenever we try to build a destruction ordering, we should also dump a
// dependency graph to "/path/to/context/context-dependencies.dot". // dependency graph to "/path/to/context/context-dependencies.dot".
if (base::CommandLine::ForCurrentProcess()->HasSwitch( if (base::CommandLine::ForCurrentProcess()->HasSwitch(
......
...@@ -33,7 +33,7 @@ class KEYED_SERVICE_EXPORT BrowserContextDependencyManager ...@@ -33,7 +33,7 @@ class KEYED_SERVICE_EXPORT BrowserContextDependencyManager
// a key to prevent multiple registrations on the same BrowserContext in // a key to prevent multiple registrations on the same BrowserContext in
// tests. // tests.
void RegisterProfilePrefsForServices( void RegisterProfilePrefsForServices(
const content::BrowserContext* context, content::BrowserContext* context,
user_prefs::PrefRegistrySyncable* registry); user_prefs::PrefRegistrySyncable* registry);
// Called by each BrowserContext to alert us of its creation. Several // Called by each BrowserContext to alert us of its creation. Several
...@@ -91,8 +91,7 @@ class KEYED_SERVICE_EXPORT BrowserContextDependencyManager ...@@ -91,8 +91,7 @@ class KEYED_SERVICE_EXPORT BrowserContextDependencyManager
#ifndef NDEBUG #ifndef NDEBUG
// DependencyManager: // DependencyManager:
void DumpContextDependencies( void DumpContextDependencies(base::SupportsUserData* context) const final;
const base::SupportsUserData* context) const final;
#endif // NDEBUG #endif // NDEBUG
// A list of callbacks to call just before executing // A list of callbacks to call just before executing
......
...@@ -4,10 +4,7 @@ ...@@ -4,10 +4,7 @@
#include "components/keyed_service/content/browser_context_keyed_base_factory.h" #include "components/keyed_service/content/browser_context_keyed_base_factory.h"
#include "base/prefs/pref_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
BrowserContextKeyedBaseFactory::BrowserContextKeyedBaseFactory( BrowserContextKeyedBaseFactory::BrowserContextKeyedBaseFactory(
...@@ -53,16 +50,6 @@ void BrowserContextKeyedBaseFactory::BrowserContextDestroyed( ...@@ -53,16 +50,6 @@ void BrowserContextKeyedBaseFactory::BrowserContextDestroyed(
KeyedServiceBaseFactory::ContextDestroyed(context); KeyedServiceBaseFactory::ContextDestroyed(context);
} }
user_prefs::PrefRegistrySyncable*
BrowserContextKeyedBaseFactory::GetAssociatedPrefRegistry(
base::SupportsUserData* context) const {
PrefService* prefs = user_prefs::UserPrefs::Get(context);
user_prefs::PrefRegistrySyncable* registry =
static_cast<user_prefs::PrefRegistrySyncable*>(
prefs->DeprecatedGetPrefRegistry());
return registry;
}
base::SupportsUserData* BrowserContextKeyedBaseFactory::GetContextToUse( base::SupportsUserData* BrowserContextKeyedBaseFactory::GetContextToUse(
base::SupportsUserData* context) const { base::SupportsUserData* context) const {
return GetBrowserContextToUse(static_cast<content::BrowserContext*>(context)); return GetBrowserContextToUse(static_cast<content::BrowserContext*>(context));
......
...@@ -90,7 +90,7 @@ class KEYED_SERVICE_EXPORT BrowserContextKeyedBaseFactory ...@@ -90,7 +90,7 @@ class KEYED_SERVICE_EXPORT BrowserContextKeyedBaseFactory
private: private:
// Registers any user preferences on this service. This is called by // Registers any user preferences on this service. This is called by
// RegisterProfilePrefsIfNecessary() and should be overriden by any service // RegisterPrefsIfNecessaryForContext() and should be overriden by any service
// that wants to register profile-specific preferences. // that wants to register profile-specific preferences.
virtual void RegisterProfilePrefs( virtual void RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {} user_prefs::PrefRegistrySyncable* registry) {}
...@@ -107,8 +107,6 @@ class KEYED_SERVICE_EXPORT BrowserContextKeyedBaseFactory ...@@ -107,8 +107,6 @@ class KEYED_SERVICE_EXPORT BrowserContextKeyedBaseFactory
virtual void CreateServiceNow(content::BrowserContext* context) = 0; virtual void CreateServiceNow(content::BrowserContext* context) = 0;
// KeyedServiceBaseFactory: // KeyedServiceBaseFactory:
user_prefs::PrefRegistrySyncable* GetAssociatedPrefRegistry(
base::SupportsUserData* context) const final;
base::SupportsUserData* GetContextToUse( base::SupportsUserData* GetContextToUse(
base::SupportsUserData* context) const final; base::SupportsUserData* context) const final;
bool ServiceIsCreatedWithContext() const final; bool ServiceIsCreatedWithContext() const final;
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "components/keyed_service/content/browser_context_keyed_service_factory.h" #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
...@@ -97,16 +96,6 @@ bool BrowserContextKeyedServiceFactory::IsOffTheRecord( ...@@ -97,16 +96,6 @@ bool BrowserContextKeyedServiceFactory::IsOffTheRecord(
return static_cast<content::BrowserContext*>(context)->IsOffTheRecord(); return static_cast<content::BrowserContext*>(context)->IsOffTheRecord();
} }
user_prefs::PrefRegistrySyncable*
BrowserContextKeyedServiceFactory::GetAssociatedPrefRegistry(
base::SupportsUserData* context) const {
PrefService* prefs = user_prefs::UserPrefs::Get(context);
user_prefs::PrefRegistrySyncable* registry =
static_cast<user_prefs::PrefRegistrySyncable*>(
prefs->DeprecatedGetPrefRegistry());
return registry;
}
base::SupportsUserData* BrowserContextKeyedServiceFactory::GetContextToUse( base::SupportsUserData* BrowserContextKeyedServiceFactory::GetContextToUse(
base::SupportsUserData* context) const { base::SupportsUserData* context) const {
return GetBrowserContextToUse(static_cast<content::BrowserContext*>(context)); return GetBrowserContextToUse(static_cast<content::BrowserContext*>(context));
......
...@@ -124,7 +124,7 @@ class KEYED_SERVICE_EXPORT BrowserContextKeyedServiceFactory ...@@ -124,7 +124,7 @@ class KEYED_SERVICE_EXPORT BrowserContextKeyedServiceFactory
friend class BrowserContextDependencyManagerUnittests; friend class BrowserContextDependencyManagerUnittests;
// Registers any user preferences on this service. This is called by // Registers any user preferences on this service. This is called by
// RegisterProfilePrefsIfNecessary() and should be overriden by any service // RegisterPrefsIfNecessaryForContext() and should be overriden by any service
// that wants to register profile-specific preferences. // that wants to register profile-specific preferences.
virtual void RegisterProfilePrefs( virtual void RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {} user_prefs::PrefRegistrySyncable* registry) {}
...@@ -135,8 +135,6 @@ class KEYED_SERVICE_EXPORT BrowserContextKeyedServiceFactory ...@@ -135,8 +135,6 @@ class KEYED_SERVICE_EXPORT BrowserContextKeyedServiceFactory
bool IsOffTheRecord(base::SupportsUserData* context) const final; bool IsOffTheRecord(base::SupportsUserData* context) const final;
// KeyedServiceBaseFactory: // KeyedServiceBaseFactory:
user_prefs::PrefRegistrySyncable* GetAssociatedPrefRegistry(
base::SupportsUserData* context) const final;
base::SupportsUserData* GetContextToUse( base::SupportsUserData* GetContextToUse(
base::SupportsUserData* context) const final; base::SupportsUserData* context) const final;
bool ServiceIsCreatedWithContext() const final; bool ServiceIsCreatedWithContext() const final;
......
...@@ -5,11 +5,8 @@ ...@@ -5,11 +5,8 @@
#include "components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h" #include "components/keyed_service/content/refcounted_browser_context_keyed_service_factory.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/core/refcounted_keyed_service.h" #include "components/keyed_service/core/refcounted_keyed_service.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
void RefcountedBrowserContextKeyedServiceFactory::SetTestingFactory( void RefcountedBrowserContextKeyedServiceFactory::SetTestingFactory(
...@@ -102,16 +99,6 @@ bool RefcountedBrowserContextKeyedServiceFactory::IsOffTheRecord( ...@@ -102,16 +99,6 @@ bool RefcountedBrowserContextKeyedServiceFactory::IsOffTheRecord(
return static_cast<content::BrowserContext*>(context)->IsOffTheRecord(); return static_cast<content::BrowserContext*>(context)->IsOffTheRecord();
} }
user_prefs::PrefRegistrySyncable*
RefcountedBrowserContextKeyedServiceFactory::GetAssociatedPrefRegistry(
base::SupportsUserData* context) const {
PrefService* prefs = user_prefs::UserPrefs::Get(context);
user_prefs::PrefRegistrySyncable* registry =
static_cast<user_prefs::PrefRegistrySyncable*>(
prefs->DeprecatedGetPrefRegistry());
return registry;
}
base::SupportsUserData* base::SupportsUserData*
RefcountedBrowserContextKeyedServiceFactory::GetContextToUse( RefcountedBrowserContextKeyedServiceFactory::GetContextToUse(
base::SupportsUserData* context) const { base::SupportsUserData* context) const {
......
...@@ -130,7 +130,7 @@ class KEYED_SERVICE_EXPORT RefcountedBrowserContextKeyedServiceFactory ...@@ -130,7 +130,7 @@ class KEYED_SERVICE_EXPORT RefcountedBrowserContextKeyedServiceFactory
friend class BrowserContextDependencyManagerUnittests; friend class BrowserContextDependencyManagerUnittests;
// Registers any user preferences on this service. This is called by // Registers any user preferences on this service. This is called by
// RegisterProfilePrefsIfNecessary() and should be overriden by any service // RegisterPrefsIfNecessaryForContext() and should be overriden by any service
// that wants to register profile-specific preferences. // that wants to register profile-specific preferences.
virtual void RegisterProfilePrefs( virtual void RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {} user_prefs::PrefRegistrySyncable* registry) {}
...@@ -141,8 +141,6 @@ class KEYED_SERVICE_EXPORT RefcountedBrowserContextKeyedServiceFactory ...@@ -141,8 +141,6 @@ class KEYED_SERVICE_EXPORT RefcountedBrowserContextKeyedServiceFactory
bool IsOffTheRecord(base::SupportsUserData* context) const final; bool IsOffTheRecord(base::SupportsUserData* context) const final;
// KeyedServiceBaseFactory: // KeyedServiceBaseFactory:
user_prefs::PrefRegistrySyncable* GetAssociatedPrefRegistry(
base::SupportsUserData* context) const final;
base::SupportsUserData* GetContextToUse( base::SupportsUserData* GetContextToUse(
base::SupportsUserData* context) const final; base::SupportsUserData* context) const final;
bool ServiceIsCreatedWithContext() const final; bool ServiceIsCreatedWithContext() const final;
......
...@@ -32,5 +32,7 @@ component("core") { ...@@ -32,5 +32,7 @@ component("core") {
deps = [ deps = [
"//base", "//base",
"//base:prefs",
"//components/user_prefs",
] ]
} }
...@@ -34,7 +34,7 @@ void DependencyManager::AddEdge(KeyedServiceBaseFactory* depended, ...@@ -34,7 +34,7 @@ void DependencyManager::AddEdge(KeyedServiceBaseFactory* depended,
} }
void DependencyManager::RegisterPrefsForServices( void DependencyManager::RegisterPrefsForServices(
const base::SupportsUserData* context, base::SupportsUserData* context,
user_prefs::PrefRegistrySyncable* pref_registry) { user_prefs::PrefRegistrySyncable* pref_registry) {
std::vector<DependencyNode*> construction_order; std::vector<DependencyNode*> construction_order;
if (!dependency_graph_.GetConstructionOrder(&construction_order)) { if (!dependency_graph_.GetConstructionOrder(&construction_order)) {
...@@ -44,7 +44,8 @@ void DependencyManager::RegisterPrefsForServices( ...@@ -44,7 +44,8 @@ void DependencyManager::RegisterPrefsForServices(
for (const auto& dependency_node : construction_order) { for (const auto& dependency_node : construction_order) {
KeyedServiceBaseFactory* factory = KeyedServiceBaseFactory* factory =
static_cast<KeyedServiceBaseFactory*>(dependency_node); static_cast<KeyedServiceBaseFactory*>(dependency_node);
factory->RegisterPrefsIfNecessaryForContext(context, pref_registry); base::SupportsUserData* typed_context = factory->GetTypedContext(context);
factory->RegisterPrefsIfNecessaryForContext(typed_context, pref_registry);
} }
} }
...@@ -66,11 +67,12 @@ void DependencyManager::CreateContextServices(base::SupportsUserData* context, ...@@ -66,11 +67,12 @@ void DependencyManager::CreateContextServices(base::SupportsUserData* context,
for (const auto& dependency_node : construction_order) { for (const auto& dependency_node : construction_order) {
KeyedServiceBaseFactory* factory = KeyedServiceBaseFactory* factory =
static_cast<KeyedServiceBaseFactory*>(dependency_node); static_cast<KeyedServiceBaseFactory*>(dependency_node);
base::SupportsUserData* typed_context = factory->GetTypedContext(context);
if (is_testing_context && factory->ServiceIsNULLWhileTesting() && if (is_testing_context && factory->ServiceIsNULLWhileTesting() &&
!factory->HasTestingFactory(context)) { !factory->HasTestingFactory(typed_context)) {
factory->SetEmptyTestingFactory(context); factory->SetEmptyTestingFactory(typed_context);
} else if (factory->ServiceIsCreatedWithContext()) { } else if (factory->ServiceIsCreatedWithContext()) {
factory->CreateServiceNow(context); factory->CreateServiceNow(typed_context);
} }
} }
} }
...@@ -89,7 +91,8 @@ void DependencyManager::DestroyContextServices( ...@@ -89,7 +91,8 @@ void DependencyManager::DestroyContextServices(
for (const auto& dependency_node : destruction_order) { for (const auto& dependency_node : destruction_order) {
KeyedServiceBaseFactory* factory = KeyedServiceBaseFactory* factory =
static_cast<KeyedServiceBaseFactory*>(dependency_node); static_cast<KeyedServiceBaseFactory*>(dependency_node);
factory->ContextShutdown(context); base::SupportsUserData* typed_context = factory->GetTypedContext(context);
factory->ContextShutdown(typed_context);
} }
#ifndef NDEBUG #ifndef NDEBUG
...@@ -100,13 +103,14 @@ void DependencyManager::DestroyContextServices( ...@@ -100,13 +103,14 @@ void DependencyManager::DestroyContextServices(
for (const auto& dependency_node : destruction_order) { for (const auto& dependency_node : destruction_order) {
KeyedServiceBaseFactory* factory = KeyedServiceBaseFactory* factory =
static_cast<KeyedServiceBaseFactory*>(dependency_node); static_cast<KeyedServiceBaseFactory*>(dependency_node);
factory->ContextDestroyed(context); base::SupportsUserData* typed_context = factory->GetTypedContext(context);
factory->ContextDestroyed(typed_context);
} }
} }
#ifndef NDEBUG #ifndef NDEBUG
void DependencyManager::AssertContextWasntDestroyed( void DependencyManager::AssertContextWasntDestroyed(
const base::SupportsUserData* context) { base::SupportsUserData* context) {
if (dead_context_pointers_.find(context) != dead_context_pointers_.end()) { if (dead_context_pointers_.find(context) != dead_context_pointers_.end()) {
NOTREACHED() << "Attempted to access a context that was ShutDown(). " NOTREACHED() << "Attempted to access a context that was ShutDown(). "
<< "This is most likely a heap smasher in progress. After " << "This is most likely a heap smasher in progress. After "
...@@ -116,7 +120,7 @@ void DependencyManager::AssertContextWasntDestroyed( ...@@ -116,7 +120,7 @@ void DependencyManager::AssertContextWasntDestroyed(
} }
void DependencyManager::MarkContextLiveForTesting( void DependencyManager::MarkContextLiveForTesting(
const base::SupportsUserData* context) { base::SupportsUserData* context) {
dead_context_pointers_.erase(context); dead_context_pointers_.erase(context);
} }
......
...@@ -45,7 +45,7 @@ class KEYED_SERVICE_EXPORT DependencyManager { ...@@ -45,7 +45,7 @@ class KEYED_SERVICE_EXPORT DependencyManager {
// Registers preferences for all services via |registry| associated with // Registers preferences for all services via |registry| associated with
// |context| (the association is managed by the embedder). The |context| // |context| (the association is managed by the embedder). The |context|
// is used as a key to prevent multiple registration during tests. // is used as a key to prevent multiple registration during tests.
void RegisterPrefsForServices(const base::SupportsUserData* context, void RegisterPrefsForServices(base::SupportsUserData* context,
user_prefs::PrefRegistrySyncable* registry); user_prefs::PrefRegistrySyncable* registry);
// Called upon creation of |context| to create services that want to be // Called upon creation of |context| to create services that want to be
...@@ -68,14 +68,14 @@ class KEYED_SERVICE_EXPORT DependencyManager { ...@@ -68,14 +68,14 @@ class KEYED_SERVICE_EXPORT DependencyManager {
#ifndef NDEBUG #ifndef NDEBUG
// Debugging assertion called as part of GetServiceForContext() in debug // Debugging assertion called as part of GetServiceForContext() in debug
// mode. This will NOTREACHED() whenever the |context| is considered stale. // mode. This will NOTREACHED() whenever the |context| is considered stale.
void AssertContextWasntDestroyed(const base::SupportsUserData* context); void AssertContextWasntDestroyed(base::SupportsUserData* context);
// Marks |context| as live (i.e., not stale). This method can be called as a // Marks |context| as live (i.e., not stale). This method can be called as a
// safeguard against |AssertContextWasntDestroyed()| checks going off due to // safeguard against |AssertContextWasntDestroyed()| checks going off due to
// |context| aliasing am instance from a prior test (i.e., 0xWhatever might // |context| aliasing am instance from a prior test (i.e., 0xWhatever might
// be created, be destroyed, and then a new object might be created at // be created, be destroyed, and then a new object might be created at
// 0xWhatever). // 0xWhatever).
void MarkContextLiveForTesting(const base::SupportsUserData* context); void MarkContextLiveForTesting(base::SupportsUserData* context);
// Dumps service dependency graph as a Graphviz dot file |dot_file| with a // Dumps service dependency graph as a Graphviz dot file |dot_file| with a
// title |top_level_name|. Helper for |DumpContextDependencies|. // title |top_level_name|. Helper for |DumpContextDependencies|.
...@@ -89,7 +89,7 @@ class KEYED_SERVICE_EXPORT DependencyManager { ...@@ -89,7 +89,7 @@ class KEYED_SERVICE_EXPORT DependencyManager {
#ifndef NDEBUG #ifndef NDEBUG
// Hook for subclass to dump the dependency graph of service for |context|. // Hook for subclass to dump the dependency graph of service for |context|.
virtual void DumpContextDependencies( virtual void DumpContextDependencies(
const base::SupportsUserData* context) const = 0; base::SupportsUserData* context) const = 0;
#endif // NDEBUG #endif // NDEBUG
DependencyGraph dependency_graph_; DependencyGraph dependency_graph_;
...@@ -99,7 +99,7 @@ class KEYED_SERVICE_EXPORT DependencyManager { ...@@ -99,7 +99,7 @@ class KEYED_SERVICE_EXPORT DependencyManager {
// These pointers are most likely invalid, but we keep track of their // These pointers are most likely invalid, but we keep track of their
// locations in memory so we can nicely assert if we're asked to do anything // locations in memory so we can nicely assert if we're asked to do anything
// with them. // with them.
std::set<const base::SupportsUserData*> dead_context_pointers_; std::set<base::SupportsUserData*> dead_context_pointers_;
#endif // NDEBUG #endif // NDEBUG
}; };
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "base/supports_user_data.h" #include "base/supports_user_data.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "components/keyed_service/core/dependency_manager.h" #include "components/keyed_service/core/dependency_manager.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/user_prefs/user_prefs.h"
void KeyedServiceBaseFactory::RegisterUserPrefsOnContextForTest( void KeyedServiceBaseFactory::RegisterUserPrefsOnContextForTest(
base::SupportsUserData* context) { base::SupportsUserData* context) {
...@@ -35,9 +37,8 @@ void KeyedServiceBaseFactory::RegisterUserPrefsOnContextForTest( ...@@ -35,9 +37,8 @@ void KeyedServiceBaseFactory::RegisterUserPrefsOnContextForTest(
// to enforce a uniquenes check here because some tests create one context and // to enforce a uniquenes check here because some tests create one context and
// multiple services of the same type attached to that context (serially, not // multiple services of the same type attached to that context (serially, not
// parallel) and we don't want to register multiple times on the same context. // parallel) and we don't want to register multiple times on the same context.
// This is the purpose of RegisterProfilePrefsIfNecessary() which could be // This is the purpose of RegisterPrefsIfNecessaryForContext() which could be
// replaced directly by RegisterProfilePrefs() if this method is ever phased // replaced directly by RegisterPrefs() if this method is ever phased out.
// out.
RegisterPrefsIfNecessaryForContext(context, RegisterPrefsIfNecessaryForContext(context,
GetAssociatedPrefRegistry(context)); GetAssociatedPrefRegistry(context));
} }
...@@ -60,7 +61,7 @@ void KeyedServiceBaseFactory::DependsOn(KeyedServiceBaseFactory* rhs) { ...@@ -60,7 +61,7 @@ void KeyedServiceBaseFactory::DependsOn(KeyedServiceBaseFactory* rhs) {
} }
void KeyedServiceBaseFactory::RegisterPrefsIfNecessaryForContext( void KeyedServiceBaseFactory::RegisterPrefsIfNecessaryForContext(
const base::SupportsUserData* context, base::SupportsUserData* context,
user_prefs::PrefRegistrySyncable* registry) { user_prefs::PrefRegistrySyncable* registry) {
if (!ArePreferencesSetOn(context)) { if (!ArePreferencesSetOn(context)) {
RegisterPrefs(registry); RegisterPrefs(registry);
...@@ -68,16 +69,29 @@ void KeyedServiceBaseFactory::RegisterPrefsIfNecessaryForContext( ...@@ -68,16 +69,29 @@ void KeyedServiceBaseFactory::RegisterPrefsIfNecessaryForContext(
} }
} }
user_prefs::PrefRegistrySyncable*
KeyedServiceBaseFactory::GetAssociatedPrefRegistry(
base::SupportsUserData* context) const {
PrefService* prefs =
user_prefs::UserPrefs::Get(GetContextForDependencyManager(context));
user_prefs::PrefRegistrySyncable* registry =
static_cast<user_prefs::PrefRegistrySyncable*>(
prefs->DeprecatedGetPrefRegistry());
return registry;
}
#ifndef NDEBUG #ifndef NDEBUG
void KeyedServiceBaseFactory::AssertContextWasntDestroyed( void KeyedServiceBaseFactory::AssertContextWasntDestroyed(
const base::SupportsUserData* context) const { base::SupportsUserData* context) const {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
context = GetContextForDependencyManager(context);
dependency_manager_->AssertContextWasntDestroyed(context); dependency_manager_->AssertContextWasntDestroyed(context);
} }
void KeyedServiceBaseFactory::MarkContextLiveForTesting( void KeyedServiceBaseFactory::MarkContextLiveForTesting(
const base::SupportsUserData* context) { base::SupportsUserData* context) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
context = GetContextForDependencyManager(context);
dependency_manager_->MarkContextLiveForTesting(context); dependency_manager_->MarkContextLiveForTesting(context);
} }
#endif #endif
...@@ -95,17 +109,28 @@ void KeyedServiceBaseFactory::ContextDestroyed( ...@@ -95,17 +109,28 @@ void KeyedServiceBaseFactory::ContextDestroyed(
// While object destruction can be customized in ways where the object is // While object destruction can be customized in ways where the object is
// only dereferenced, this still must run on the UI thread. // only dereferenced, this still must run on the UI thread.
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
registered_preferences_.erase(context); registered_preferences_.erase(context);
} }
bool KeyedServiceBaseFactory::ArePreferencesSetOn( bool KeyedServiceBaseFactory::ArePreferencesSetOn(
const base::SupportsUserData* context) const { base::SupportsUserData* context) const {
return registered_preferences_.find(context) != registered_preferences_.end(); return registered_preferences_.find(context) != registered_preferences_.end();
} }
void KeyedServiceBaseFactory::MarkPreferencesSetOn( void KeyedServiceBaseFactory::MarkPreferencesSetOn(
const base::SupportsUserData* context) { base::SupportsUserData* context) {
DCHECK(!ArePreferencesSetOn(context)); DCHECK(!ArePreferencesSetOn(context));
registered_preferences_.insert(context); registered_preferences_.insert(context);
} }
#if defined(OS_IOS)
base::SupportsUserData* KeyedServiceBaseFactory::GetTypedContext(
base::SupportsUserData* context) const {
return context;
}
base::SupportsUserData* KeyedServiceBaseFactory::GetContextForDependencyManager(
base::SupportsUserData* context) const {
return context;
}
#endif // defined(OS_IOS)
...@@ -57,14 +57,14 @@ class KEYED_SERVICE_EXPORT KeyedServiceBaseFactory ...@@ -57,14 +57,14 @@ class KEYED_SERVICE_EXPORT KeyedServiceBaseFactory
#ifndef NDEBUG #ifndef NDEBUG
// Debugging assertion that will NOTREACHED() is |context| is considered // Debugging assertion that will NOTREACHED() is |context| is considered
// stale. Should be used by subclasses when accessing |context|. // stale. Should be used by subclasses when accessing |context|.
void AssertContextWasntDestroyed(const base::SupportsUserData* context) const; void AssertContextWasntDestroyed(base::SupportsUserData* context) const;
// Marks |context| as live (i.e., not stale). This method can be called as a // Marks |context| as live (i.e., not stale). This method can be called as a
// safeguard against |AssertContextWasntDestroyed()| checks going off due to // safeguard against |AssertContextWasntDestroyed()| checks going off due to
// |context| aliasing am instance from a prior test (i.e., 0xWhatever might // |context| aliasing am instance from a prior test (i.e., 0xWhatever might
// be created, be destroyed, and then a new object might be created at // be created, be destroyed, and then a new object might be created at
// 0xWhatever). // 0xWhatever).
void MarkContextLiveForTesting(const base::SupportsUserData* context); void MarkContextLiveForTesting(base::SupportsUserData* context);
#endif #endif
// Calls RegisterProfilePrefs() after doing house keeping required to work // Calls RegisterProfilePrefs() after doing house keeping required to work
...@@ -72,13 +72,13 @@ class KEYED_SERVICE_EXPORT KeyedServiceBaseFactory ...@@ -72,13 +72,13 @@ class KEYED_SERVICE_EXPORT KeyedServiceBaseFactory
// TODO(gab): This method can be replaced by RegisterProfilePrefs() directly // TODO(gab): This method can be replaced by RegisterProfilePrefs() directly
// once RegisterUserPrefsOnContextForTest() is phased out. // once RegisterUserPrefsOnContextForTest() is phased out.
void RegisterPrefsIfNecessaryForContext( void RegisterPrefsIfNecessaryForContext(
const base::SupportsUserData* context, base::SupportsUserData* context,
user_prefs::PrefRegistrySyncable* registry); user_prefs::PrefRegistrySyncable* registry);
// Returns the |user_pref::PrefRegistrySyncable| associated with |context|. // Returns the |user_pref::PrefRegistrySyncable| associated with |context|.
// The way they are associated is controlled by the embedder. // The way they are associated is controlled by the embedder.
virtual user_prefs::PrefRegistrySyncable* GetAssociatedPrefRegistry( user_prefs::PrefRegistrySyncable* GetAssociatedPrefRegistry(
base::SupportsUserData* context) const = 0; base::SupportsUserData* context) const;
// Finds which context (if any) to use. // Finds which context (if any) to use.
virtual base::SupportsUserData* GetContextToUse( virtual base::SupportsUserData* GetContextToUse(
...@@ -109,10 +109,59 @@ class KEYED_SERVICE_EXPORT KeyedServiceBaseFactory ...@@ -109,10 +109,59 @@ class KEYED_SERVICE_EXPORT KeyedServiceBaseFactory
virtual void ContextDestroyed(base::SupportsUserData* context); virtual void ContextDestroyed(base::SupportsUserData* context);
// Returns whether the preferences have been registered on this context. // Returns whether the preferences have been registered on this context.
bool ArePreferencesSetOn(const base::SupportsUserData* context) const; bool ArePreferencesSetOn(base::SupportsUserData* context) const;
// Mark context has having preferences registered. // Mark context has having preferences registered.
void MarkPreferencesSetOn(const base::SupportsUserData* context); void MarkPreferencesSetOn(base::SupportsUserData* context);
// The iOS code downstream used BrowserContextKeyedServiceFactories. The code
// is currently ported to use BrowserStateKeyedServiceFactories instead but
// has to support mixed dependencies to ease the migration — which can then
// be done incrementally. This means that on iOS the DependencyManager can
// reference both type of factories and the context need to be converted to
// the correct typed context.
//
// GetTypedContext()/GetContextForDependencyManager() are there to supports
// the mixed dependencies. On all platform except iOS they are pass-through
// and returns the original object. On iOS, they convert the context to resp.
// web::BrowserState/content::BrowserContext casted as base::SupportsUserData.
//
// TODO(ios): migration is tracked by http://crbug.com/478763 and those two
// methods (and their *Internal implementation) must be removed once migration
// is complete.
// Returns the correctly typed context for the KeyedServiceFactory (either a
// content::BrowserContext for BrowserContextKeyedServiceFactory or a
// web::BrowserState for a BrowserStateKeyedServiceFactory) when using mixed
// dependency (iOS). Simple pass-through on all other platforms.
//
// TODO(ios): remove this method and its call-sites once iOS only uses
// BrowserStateKeyedServiceFactories, http://crbug.com/478763
#if defined(OS_IOS)
virtual base::SupportsUserData* GetTypedContext(
base::SupportsUserData* context) const;
#else
base::SupportsUserData* GetTypedContext(
base::SupportsUserData* context) const {
return context;
}
#endif // defined(OS_IOS)
// Returns the content::BrowserContext associated to |context| for interaction
// with the DependencyManager when using mixed dependency (iOS). Simple pass-
// through on all other platforms.
//
// TODO(ios): remove this method and its call-sites once iOS only uses
// BrowserStateKeyedServiceFactories, http://crbug.com/478763
#if defined(OS_IOS)
virtual base::SupportsUserData* GetContextForDependencyManager(
base::SupportsUserData* context) const;
#else
base::SupportsUserData* GetContextForDependencyManager(
base::SupportsUserData* context) const {
return context;
}
#endif // defined(OS_IOS)
private: private:
friend class DependencyManager; friend class DependencyManager;
...@@ -135,7 +184,7 @@ class KEYED_SERVICE_EXPORT KeyedServiceBaseFactory ...@@ -135,7 +184,7 @@ class KEYED_SERVICE_EXPORT KeyedServiceBaseFactory
virtual void CreateServiceNow(base::SupportsUserData* context) = 0; virtual void CreateServiceNow(base::SupportsUserData* context) = 0;
// Contexts that have this service's preferences registered on them. // Contexts that have this service's preferences registered on them.
std::set<const base::SupportsUserData*> registered_preferences_; std::set<base::SupportsUserData*> registered_preferences_;
#if !defined(NDEBUG) #if !defined(NDEBUG)
// A static string passed in to the constructor. Should be unique across all // A static string passed in to the constructor. Should be unique across all
......
include_rules = [ include_rules = [
"+components/pref_registry",
"+ios/web/public", "+ios/web/public",
] ]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/keyed_service/ios/browser_state_context_converter.h"
namespace {
// Global BrowserStateContextConverter* instance, may be null.
BrowserStateContextConverter* g_browser_state_context_converter = nullptr;
} // namespace
// static
void BrowserStateContextConverter::SetInstance(
BrowserStateContextConverter* instance) {
g_browser_state_context_converter = instance;
}
BrowserStateContextConverter* BrowserStateContextConverter::GetInstance() {
return g_browser_state_context_converter;
}
BrowserStateContextConverter::BrowserStateContextConverter() {
}
BrowserStateContextConverter::~BrowserStateContextConverter() {
}
...@@ -2,14 +2,20 @@ ...@@ -2,14 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "components/keyed_service/ios/browser_state_helper.h" #ifndef COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_CONTEXT_CONVERTER_H_
#define COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_CONTEXT_CONVERTER_H_
#include "base/logging.h" #include "base/macros.h"
#include "base/supports_user_data.h"
#include "ios/web/public/browser_state.h"
namespace base {
class SupportsUserData;
}
// BrowserStateContextConverter does safe conversion of base::SupportsUserData*
// to web::BrowserState* or content::BrowserContext*.
//
// iOS code is still using BrowserContextKeyedServiceFactory and until the // iOS code is still using BrowserContextKeyedServiceFactory and until the
// upstreaming is complete (http://crbug.com/419366) there is need to have // conversion is complete — http://crbug.com/478763 — there is need to have
// mixed dependency between BCKSF and BSKSF. // mixed dependency between BCKSF and BSKSF.
// //
// The implementation has BrowserStateKeyedServiceFactory supporting a // The implementation has BrowserStateKeyedServiceFactory supporting a
...@@ -23,28 +29,27 @@ ...@@ -23,28 +29,27 @@
// public method receive web::BrowserState for context object), so only // public method receive web::BrowserState for context object), so only
// methods that take a base::SupportsUserData need to discriminate // methods that take a base::SupportsUserData need to discriminate
// between the two objects. // between the two objects.
// class BrowserStateContextConverter {
// If the base::SupportsUserData is a web::BrowserState then the public public:
// method web::BrowserState::FromSupportsUserData can do the conversion // Sets/Gets the global BrowserStateContextConverter instance. May return null
// safely. If this method fails then context is content::BrowserContext // when mixed dependencies are disabled.
// and the methods defined below allow the embedder to provides helper static void SetInstance(BrowserStateContextConverter* instance);
// to find the associated web::BrowserState (there is a 1:1 mapping). static BrowserStateContextConverter* GetInstance();
namespace {
BrowserStateFromContextFn g_browser_state_from_context = nullptr;
} // namespace
void SetBrowserStateFromContextHelper(BrowserStateFromContextFn helper) {
g_browser_state_from_context = helper;
}
web::BrowserState* BrowserStateFromContext(base::SupportsUserData* context) { // Converts |context| to a web::BrowserState* and returns it casted as a
web::BrowserState* state = nullptr; // base::SupportsUserData*.
if (context) { virtual base::SupportsUserData* GetBrowserStateForContext(
state = web::BrowserState::FromSupportsUserData(context); base::SupportsUserData* context) = 0;
if (!state && g_browser_state_from_context) // Converts |context| to a content::BrowserContext* and returns it casted as a
state = g_browser_state_from_context(context); // base::SupportsUserData*.
DCHECK(state) << "cannot convert context to web::BrowserState"; virtual base::SupportsUserData* GetBrowserContextForContext(
} base::SupportsUserData* context) = 0;
return state;
} protected:
BrowserStateContextConverter();
virtual ~BrowserStateContextConverter();
DISALLOW_COPY_AND_ASSIGN(BrowserStateContextConverter);
};
#endif // COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_CONTEXT_CONVERTER_H_
...@@ -13,8 +13,8 @@ BrowserStateDependencyManager* BrowserStateDependencyManager::GetInstance() { ...@@ -13,8 +13,8 @@ BrowserStateDependencyManager* BrowserStateDependencyManager::GetInstance() {
return Singleton<BrowserStateDependencyManager>::get(); return Singleton<BrowserStateDependencyManager>::get();
} }
void BrowserStateDependencyManager::RegisterProfilePrefsForServices( void BrowserStateDependencyManager::RegisterBrowserStatePrefsForServices(
const web::BrowserState* context, web::BrowserState* context,
user_prefs::PrefRegistrySyncable* pref_registry) { user_prefs::PrefRegistrySyncable* pref_registry) {
RegisterPrefsForServices(context, pref_registry); RegisterPrefsForServices(context, pref_registry);
} }
...@@ -62,6 +62,6 @@ void BrowserStateDependencyManager::DoCreateBrowserStateServices( ...@@ -62,6 +62,6 @@ void BrowserStateDependencyManager::DoCreateBrowserStateServices(
#ifndef NDEBUG #ifndef NDEBUG
void BrowserStateDependencyManager::DumpContextDependencies( void BrowserStateDependencyManager::DumpContextDependencies(
const base::SupportsUserData* context) const { base::SupportsUserData* context) const {
} }
#endif // NDEBUG #endif // NDEBUG
...@@ -34,8 +34,8 @@ class KEYED_SERVICE_EXPORT BrowserStateDependencyManager ...@@ -34,8 +34,8 @@ class KEYED_SERVICE_EXPORT BrowserStateDependencyManager
// |context| should be the BrowserState containing |registry| and is used as // |context| should be the BrowserState containing |registry| and is used as
// a key to prevent multiple registrations on the same BrowserState in // a key to prevent multiple registrations on the same BrowserState in
// tests. // tests.
void RegisterProfilePrefsForServices( void RegisterBrowserStatePrefsForServices(
const web::BrowserState* context, web::BrowserState* context,
user_prefs::PrefRegistrySyncable* registry); user_prefs::PrefRegistrySyncable* registry);
// Called by each BrowserState to alert us of its creation. Service that // Called by each BrowserState to alert us of its creation. Service that
...@@ -80,8 +80,7 @@ class KEYED_SERVICE_EXPORT BrowserStateDependencyManager ...@@ -80,8 +80,7 @@ class KEYED_SERVICE_EXPORT BrowserStateDependencyManager
#ifndef NDEBUG #ifndef NDEBUG
// DependencyManager: // DependencyManager:
void DumpContextDependencies( void DumpContextDependencies(base::SupportsUserData* context) const final;
const base::SupportsUserData* context) const final;
#endif // NDEBUG #endif // NDEBUG
DISALLOW_COPY_AND_ASSIGN(BrowserStateDependencyManager); DISALLOW_COPY_AND_ASSIGN(BrowserStateDependencyManager);
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_HELPER_H_
#define COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_HELPER_H_
namespace base {
class SupportsUserData;
}
namespace web {
class BrowserState;
}
// TODO(sdefresne): remove this file and all usage of the methods once iOS code
// only use BrowserStateKeyedServiceFactory, http://crbug.com/419366
// |BrowserStateFromContextFn| converts from a base::SupportsUserData as passed
// to a (Refcounted)?BrowserStateKeyedServiceFactory to a web::BrowserState.
using BrowserStateFromContextFn =
web::BrowserState* (*)(base::SupportsUserData*);
// Registers an helper function to convert a |context| to a web::BrowserState
// to allow the embedder to overrides how the BSKSF does the conversion.
void SetBrowserStateFromContextHelper(BrowserStateFromContextFn helper);
// Converts a |context| to a web::BrowserState using the helper registered by
// the embedder if any. Usage is restricted to //components/keyed_service/ios.
web::BrowserState* BrowserStateFromContext(base::SupportsUserData* context);
#endif // COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_HELPER_H_
...@@ -5,12 +5,9 @@ ...@@ -5,12 +5,9 @@
#include "components/keyed_service/ios/browser_state_keyed_service_factory.h" #include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/prefs/pref_service.h"
#include "components/keyed_service/core/keyed_service.h" #include "components/keyed_service/core/keyed_service.h"
#include "components/keyed_service/ios/browser_state_context_converter.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h" #include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/keyed_service/ios/browser_state_helper.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/user_prefs/user_prefs.h"
#include "ios/web/public/browser_state.h" #include "ios/web/public/browser_state.h"
void BrowserStateKeyedServiceFactory::SetTestingFactory( void BrowserStateKeyedServiceFactory::SetTestingFactory(
...@@ -79,30 +76,46 @@ void BrowserStateKeyedServiceFactory::BrowserStateDestroyed( ...@@ -79,30 +76,46 @@ void BrowserStateKeyedServiceFactory::BrowserStateDestroyed(
KeyedService* BrowserStateKeyedServiceFactory::BuildServiceInstanceFor( KeyedService* BrowserStateKeyedServiceFactory::BuildServiceInstanceFor(
base::SupportsUserData* context) const { base::SupportsUserData* context) const {
return BuildServiceInstanceFor(BrowserStateFromContext(context)); return BuildServiceInstanceFor(static_cast<web::BrowserState*>(context));
} }
bool BrowserStateKeyedServiceFactory::IsOffTheRecord( bool BrowserStateKeyedServiceFactory::IsOffTheRecord(
base::SupportsUserData* context) const { base::SupportsUserData* context) const {
return BrowserStateFromContext(context)->IsOffTheRecord(); return static_cast<web::BrowserState*>(context)->IsOffTheRecord();
} }
user_prefs::PrefRegistrySyncable* #if defined(OS_IOS)
BrowserStateKeyedServiceFactory::GetAssociatedPrefRegistry( base::SupportsUserData* BrowserStateKeyedServiceFactory::GetTypedContext(
base::SupportsUserData* context) const { base::SupportsUserData* context) const {
// TODO(droger): Move this code to KeyedServiceFactory and share it with the if (context) {
// other platforms once iOS no longer needs BrowserStateFromContext(). BrowserStateContextConverter* context_converter =
PrefService* prefs = BrowserStateContextConverter::GetInstance();
user_prefs::UserPrefs::Get(BrowserStateFromContext(context)); if (context_converter) {
user_prefs::PrefRegistrySyncable* registry = context = context_converter->GetBrowserStateForContext(context);
static_cast<user_prefs::PrefRegistrySyncable*>( DCHECK(context);
prefs->DeprecatedGetPrefRegistry()); }
return registry; }
return context;
}
base::SupportsUserData*
BrowserStateKeyedServiceFactory::GetContextForDependencyManager(
base::SupportsUserData* context) const {
if (context) {
BrowserStateContextConverter* context_converter =
BrowserStateContextConverter::GetInstance();
if (context_converter) {
context = context_converter->GetBrowserContextForContext(context);
DCHECK(context);
}
}
return context;
} }
#endif // defined(OS_IOS)
base::SupportsUserData* BrowserStateKeyedServiceFactory::GetContextToUse( base::SupportsUserData* BrowserStateKeyedServiceFactory::GetContextToUse(
base::SupportsUserData* context) const { base::SupportsUserData* context) const {
return GetBrowserStateToUse(BrowserStateFromContext(context)); return GetBrowserStateToUse(static_cast<web::BrowserState*>(context));
} }
bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() const { bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() const {
...@@ -111,15 +124,15 @@ bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() const { ...@@ -111,15 +124,15 @@ bool BrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() const {
void BrowserStateKeyedServiceFactory::ContextShutdown( void BrowserStateKeyedServiceFactory::ContextShutdown(
base::SupportsUserData* context) { base::SupportsUserData* context) {
BrowserStateShutdown(BrowserStateFromContext(context)); BrowserStateShutdown(static_cast<web::BrowserState*>(context));
} }
void BrowserStateKeyedServiceFactory::ContextDestroyed( void BrowserStateKeyedServiceFactory::ContextDestroyed(
base::SupportsUserData* context) { base::SupportsUserData* context) {
BrowserStateDestroyed(BrowserStateFromContext(context)); BrowserStateDestroyed(static_cast<web::BrowserState*>(context));
} }
void BrowserStateKeyedServiceFactory::RegisterPrefs( void BrowserStateKeyedServiceFactory::RegisterPrefs(
user_prefs::PrefRegistrySyncable* registry) { user_prefs::PrefRegistrySyncable* registry) {
RegisterProfilePrefs(registry); RegisterBrowserStatePrefs(registry);
} }
...@@ -108,9 +108,9 @@ class KEYED_SERVICE_EXPORT BrowserStateKeyedServiceFactory ...@@ -108,9 +108,9 @@ class KEYED_SERVICE_EXPORT BrowserStateKeyedServiceFactory
private: private:
// Registers any user preferences on this service. This is called by // Registers any user preferences on this service. This is called by
// RegisterProfilePrefsIfNecessary() and should be overriden by any service // RegisterPrefsIfNecessaryForContext() and should be overriden by any service
// that wants to register profile-specific preferences. // that wants to register profile-specific preferences.
virtual void RegisterProfilePrefs( virtual void RegisterBrowserStatePrefs(
user_prefs::PrefRegistrySyncable* registry) {} user_prefs::PrefRegistrySyncable* registry) {}
// KeyedServiceFactory: // KeyedServiceFactory:
...@@ -119,8 +119,12 @@ class KEYED_SERVICE_EXPORT BrowserStateKeyedServiceFactory ...@@ -119,8 +119,12 @@ class KEYED_SERVICE_EXPORT BrowserStateKeyedServiceFactory
bool IsOffTheRecord(base::SupportsUserData* context) const final; bool IsOffTheRecord(base::SupportsUserData* context) const final;
// KeyedServiceBaseFactory: // KeyedServiceBaseFactory:
user_prefs::PrefRegistrySyncable* GetAssociatedPrefRegistry( #if defined(OS_IOS)
base::SupportsUserData* context) const final; base::SupportsUserData* GetTypedContext(
base::SupportsUserData* context) const override;
base::SupportsUserData* GetContextForDependencyManager(
base::SupportsUserData* context) const override;
#endif // defined(OS_IOS)
base::SupportsUserData* GetContextToUse( base::SupportsUserData* GetContextToUse(
base::SupportsUserData* context) const final; base::SupportsUserData* context) const final;
bool ServiceIsCreatedWithContext() const final; bool ServiceIsCreatedWithContext() const final;
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "base/logging.h" #include "base/logging.h"
#include "components/keyed_service/core/refcounted_keyed_service.h" #include "components/keyed_service/core/refcounted_keyed_service.h"
#include "components/keyed_service/ios/browser_state_context_converter.h"
#include "components/keyed_service/ios/browser_state_dependency_manager.h" #include "components/keyed_service/ios/browser_state_dependency_manager.h"
#include "components/keyed_service/ios/browser_state_helper.h"
#include "ios/web/public/browser_state.h" #include "ios/web/public/browser_state.h"
void RefcountedBrowserStateKeyedServiceFactory::SetTestingFactory( void RefcountedBrowserStateKeyedServiceFactory::SetTestingFactory(
...@@ -86,25 +86,48 @@ void RefcountedBrowserStateKeyedServiceFactory::BrowserStateDestroyed( ...@@ -86,25 +86,48 @@ void RefcountedBrowserStateKeyedServiceFactory::BrowserStateDestroyed(
scoped_refptr<RefcountedKeyedService> scoped_refptr<RefcountedKeyedService>
RefcountedBrowserStateKeyedServiceFactory::BuildServiceInstanceFor( RefcountedBrowserStateKeyedServiceFactory::BuildServiceInstanceFor(
base::SupportsUserData* context) const { base::SupportsUserData* context) const {
return BuildServiceInstanceFor(BrowserStateFromContext(context)); return BuildServiceInstanceFor(static_cast<web::BrowserState*>(context));
} }
bool RefcountedBrowserStateKeyedServiceFactory::IsOffTheRecord( bool RefcountedBrowserStateKeyedServiceFactory::IsOffTheRecord(
base::SupportsUserData* context) const { base::SupportsUserData* context) const {
return BrowserStateFromContext(context)->IsOffTheRecord(); return static_cast<web::BrowserState*>(context)->IsOffTheRecord();
} }
user_prefs::PrefRegistrySyncable* #if defined(OS_IOS)
RefcountedBrowserStateKeyedServiceFactory::GetAssociatedPrefRegistry( base::SupportsUserData*
RefcountedBrowserStateKeyedServiceFactory::GetTypedContext(
base::SupportsUserData* context) const { base::SupportsUserData* context) const {
NOTREACHED(); if (context) {
return nullptr; BrowserStateContextConverter* context_converter =
BrowserStateContextConverter::GetInstance();
if (context_converter) {
context = context_converter->GetBrowserStateForContext(context);
DCHECK(context);
}
}
return context;
}
base::SupportsUserData*
RefcountedBrowserStateKeyedServiceFactory::GetContextForDependencyManager(
base::SupportsUserData* context) const {
if (context) {
BrowserStateContextConverter* context_converter =
BrowserStateContextConverter::GetInstance();
if (context_converter) {
context = context_converter->GetBrowserContextForContext(context);
DCHECK(context);
}
}
return context;
} }
#endif // defined(OS_IOS)
base::SupportsUserData* base::SupportsUserData*
RefcountedBrowserStateKeyedServiceFactory::GetContextToUse( RefcountedBrowserStateKeyedServiceFactory::GetContextToUse(
base::SupportsUserData* context) const { base::SupportsUserData* context) const {
return GetBrowserStateToUse(BrowserStateFromContext(context)); return GetBrowserStateToUse(static_cast<web::BrowserState*>(context));
} }
bool RefcountedBrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() bool RefcountedBrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext()
...@@ -114,15 +137,15 @@ bool RefcountedBrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext() ...@@ -114,15 +137,15 @@ bool RefcountedBrowserStateKeyedServiceFactory::ServiceIsCreatedWithContext()
void RefcountedBrowserStateKeyedServiceFactory::ContextShutdown( void RefcountedBrowserStateKeyedServiceFactory::ContextShutdown(
base::SupportsUserData* context) { base::SupportsUserData* context) {
BrowserStateShutdown(BrowserStateFromContext(context)); BrowserStateShutdown(static_cast<web::BrowserState*>(context));
} }
void RefcountedBrowserStateKeyedServiceFactory::ContextDestroyed( void RefcountedBrowserStateKeyedServiceFactory::ContextDestroyed(
base::SupportsUserData* context) { base::SupportsUserData* context) {
BrowserStateDestroyed(BrowserStateFromContext(context)); BrowserStateDestroyed(static_cast<web::BrowserState*>(context));
} }
void RefcountedBrowserStateKeyedServiceFactory::RegisterPrefs( void RefcountedBrowserStateKeyedServiceFactory::RegisterPrefs(
user_prefs::PrefRegistrySyncable* registry) { user_prefs::PrefRegistrySyncable* registry) {
RegisterProfilePrefs(registry); RegisterBrowserStatePrefs(registry);
} }
...@@ -115,9 +115,9 @@ class KEYED_SERVICE_EXPORT RefcountedBrowserStateKeyedServiceFactory ...@@ -115,9 +115,9 @@ class KEYED_SERVICE_EXPORT RefcountedBrowserStateKeyedServiceFactory
private: private:
// Registers any user preferences on this service. This is called by // Registers any user preferences on this service. This is called by
// RegisterProfilePrefsIfNecessary() and should be overriden by any service // RegisterPrefsIfNecessaryForContext() and should be overriden by any service
// that wants to register profile-specific preferences. // that wants to register profile-specific preferences.
virtual void RegisterProfilePrefs( virtual void RegisterBrowserStatePrefs(
user_prefs::PrefRegistrySyncable* registry) {} user_prefs::PrefRegistrySyncable* registry) {}
// RefcountedKeyedServiceFactory: // RefcountedKeyedServiceFactory:
...@@ -126,8 +126,12 @@ class KEYED_SERVICE_EXPORT RefcountedBrowserStateKeyedServiceFactory ...@@ -126,8 +126,12 @@ class KEYED_SERVICE_EXPORT RefcountedBrowserStateKeyedServiceFactory
bool IsOffTheRecord(base::SupportsUserData* context) const final; bool IsOffTheRecord(base::SupportsUserData* context) const final;
// KeyedServiceBaseFactory: // KeyedServiceBaseFactory:
user_prefs::PrefRegistrySyncable* GetAssociatedPrefRegistry( #if defined(OS_IOS)
base::SupportsUserData* context) const final; base::SupportsUserData* GetTypedContext(
base::SupportsUserData* context) const override;
base::SupportsUserData* GetContextForDependencyManager(
base::SupportsUserData* context) const override;
#endif // defined(OS_IOS)
base::SupportsUserData* GetContextToUse( base::SupportsUserData* GetContextToUse(
base::SupportsUserData* context) const final; base::SupportsUserData* context) const final;
bool ServiceIsCreatedWithContext() const final; bool ServiceIsCreatedWithContext() const final;
......
...@@ -38,7 +38,7 @@ class SuggestionsServiceFactory : public BrowserStateKeyedServiceFactory { ...@@ -38,7 +38,7 @@ class SuggestionsServiceFactory : public BrowserStateKeyedServiceFactory {
// BrowserStateKeyedServiceFactory: // BrowserStateKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor( KeyedService* BuildServiceInstanceFor(
web::BrowserState* browser_state) const override; web::BrowserState* browser_state) const override;
void RegisterProfilePrefs( void RegisterBrowserStatePrefs(
user_prefs::PrefRegistrySyncable* registry) override; user_prefs::PrefRegistrySyncable* registry) override;
DISALLOW_COPY_AND_ASSIGN(SuggestionsServiceFactory); DISALLOW_COPY_AND_ASSIGN(SuggestionsServiceFactory);
......
...@@ -75,7 +75,7 @@ KeyedService* SuggestionsServiceFactory::BuildServiceInstanceFor( ...@@ -75,7 +75,7 @@ KeyedService* SuggestionsServiceFactory::BuildServiceInstanceFor(
thumbnail_manager.Pass(), blacklist_store.Pass()); thumbnail_manager.Pass(), blacklist_store.Pass());
} }
void SuggestionsServiceFactory::RegisterProfilePrefs( void SuggestionsServiceFactory::RegisterBrowserStatePrefs(
user_prefs::PrefRegistrySyncable* registry) { user_prefs::PrefRegistrySyncable* registry) {
SuggestionsService::RegisterProfilePrefs(registry); SuggestionsService::RegisterProfilePrefs(registry);
} }
......
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