OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/keyed_service/content/browser_context_keyed_base_factory.h" | 5 #include "components/keyed_service/content/browser_context_keyed_base_factory.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 8 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
9 #include "components/pref_registry/pref_registry_syncable.h" | 9 #include "components/pref_registry/pref_registry_syncable.h" |
10 #include "components/user_prefs/user_prefs.h" | 10 #include "components/user_prefs/user_prefs.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 } | 49 } |
50 | 50 |
51 void BrowserContextKeyedBaseFactory::BrowserContextDestroyed( | 51 void BrowserContextKeyedBaseFactory::BrowserContextDestroyed( |
52 content::BrowserContext* context) { | 52 content::BrowserContext* context) { |
53 KeyedServiceBaseFactory::ContextDestroyed(context); | 53 KeyedServiceBaseFactory::ContextDestroyed(context); |
54 } | 54 } |
55 | 55 |
56 user_prefs::PrefRegistrySyncable* | 56 user_prefs::PrefRegistrySyncable* |
57 BrowserContextKeyedBaseFactory::GetAssociatedPrefRegistry( | 57 BrowserContextKeyedBaseFactory::GetAssociatedPrefRegistry( |
58 base::SupportsUserData* context) const { | 58 base::SupportsUserData* context) const { |
59 // Safe timing for pref registration is hard. Previously, we made | |
60 // BrowserContext responsible for all pref registration on every service | |
61 // that used BrowserContext. Now we don't and there are timing issues. | |
62 // | |
63 // With normal contexts, prefs can simply be registered at | |
64 // BrowserContextDependencyManager::RegisterProfilePrefsForServices time. | |
65 // With incognito contexts, we just never register since incognito contexts | |
66 // share the same pref services with their parent contexts. | |
67 // | |
68 // TestingBrowserContexts throw a wrench into the mix, in that some tests will | |
69 // swap out the PrefService after we've registered user prefs on the original | |
70 // PrefService. Test code that does this is responsible for either manually | |
71 // invoking RegisterProfilePrefs() on the appropriate | |
72 // BrowserContextKeyedServiceFactory associated with the prefs they need, | |
73 // or they can use SetTestingFactory() and create a service (since service | |
74 // creation with a factory method causes registration to happen at | |
75 // TestingProfile creation time). | |
76 // | |
77 // Now that services are responsible for declaring their preferences, we have | |
78 // to enforce a uniquenes check here because some tests create one context and | |
79 // multiple services of the same type attached to that context (serially, not | |
80 // parallel) and we don't want to register multiple times on the same context. | |
81 // This is the purpose of RegisterProfilePrefsIfNecessary() which could be | |
82 // replaced directly by RegisterProfilePrefs() if this method is ever phased | |
83 // out. | |
84 PrefService* prefs = user_prefs::UserPrefs::Get( | 59 PrefService* prefs = user_prefs::UserPrefs::Get( |
85 static_cast<content::BrowserContext*>(context)); | 60 static_cast<content::BrowserContext*>(context)); |
86 user_prefs::PrefRegistrySyncable* registry = | 61 user_prefs::PrefRegistrySyncable* registry = |
87 static_cast<user_prefs::PrefRegistrySyncable*>( | 62 static_cast<user_prefs::PrefRegistrySyncable*>( |
88 prefs->DeprecatedGetPrefRegistry()); | 63 prefs->DeprecatedGetPrefRegistry()); |
89 return registry; | 64 return registry; |
90 } | 65 } |
91 | 66 |
92 base::SupportsUserData* BrowserContextKeyedBaseFactory::GetContextToUse( | 67 base::SupportsUserData* BrowserContextKeyedBaseFactory::GetContextToUse( |
93 base::SupportsUserData* context) const { | 68 base::SupportsUserData* context) const { |
(...skipping 26 matching lines...) Expand all Loading... |
120 | 95 |
121 bool BrowserContextKeyedBaseFactory::HasTestingFactory( | 96 bool BrowserContextKeyedBaseFactory::HasTestingFactory( |
122 base::SupportsUserData* context) { | 97 base::SupportsUserData* context) { |
123 return HasTestingFactory(static_cast<content::BrowserContext*>(context)); | 98 return HasTestingFactory(static_cast<content::BrowserContext*>(context)); |
124 } | 99 } |
125 | 100 |
126 void BrowserContextKeyedBaseFactory::CreateServiceNow( | 101 void BrowserContextKeyedBaseFactory::CreateServiceNow( |
127 base::SupportsUserData* context) { | 102 base::SupportsUserData* context) { |
128 CreateServiceNow(static_cast<content::BrowserContext*>(context)); | 103 CreateServiceNow(static_cast<content::BrowserContext*>(context)); |
129 } | 104 } |
OLD | NEW |