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/core/keyed_service_base_factory.h" | 5 #include "components/keyed_service/core/keyed_service_base_factory.h" |
6 | 6 |
7 #include "base/supports_user_data.h" | 7 #include "base/supports_user_data.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "components/keyed_service/core/dependency_manager.h" | 9 #include "components/keyed_service/core/dependency_manager.h" |
10 #include "components/pref_registry/pref_registry_syncable.h" | 10 #include "components/pref_registry/pref_registry_syncable.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 user_prefs::PrefRegistrySyncable* | 72 user_prefs::PrefRegistrySyncable* |
73 KeyedServiceBaseFactory::GetAssociatedPrefRegistry( | 73 KeyedServiceBaseFactory::GetAssociatedPrefRegistry( |
74 base::SupportsUserData* context) const { | 74 base::SupportsUserData* context) const { |
75 PrefService* prefs = user_prefs::UserPrefs::Get(context); | 75 PrefService* prefs = user_prefs::UserPrefs::Get(context); |
76 user_prefs::PrefRegistrySyncable* registry = | 76 user_prefs::PrefRegistrySyncable* registry = |
77 static_cast<user_prefs::PrefRegistrySyncable*>( | 77 static_cast<user_prefs::PrefRegistrySyncable*>( |
78 prefs->DeprecatedGetPrefRegistry()); | 78 prefs->DeprecatedGetPrefRegistry()); |
79 return registry; | 79 return registry; |
80 } | 80 } |
81 | 81 |
82 #ifndef NDEBUG | |
83 void KeyedServiceBaseFactory::AssertContextWasntDestroyed( | 82 void KeyedServiceBaseFactory::AssertContextWasntDestroyed( |
84 base::SupportsUserData* context) const { | 83 base::SupportsUserData* context) const { |
85 DCHECK(CalledOnValidThread()); | 84 // TODO(crbug.com/701326): We should DCHECK(CalledOnValidThread()) here, but |
| 85 // currently some code doesn't do service getting on the main thread. |
| 86 // This needs to be fixed and DCHECK should be restored here. |
86 dependency_manager_->AssertContextWasntDestroyed(context); | 87 dependency_manager_->AssertContextWasntDestroyed(context); |
87 } | 88 } |
88 | 89 |
89 void KeyedServiceBaseFactory::MarkContextLiveForTesting( | 90 void KeyedServiceBaseFactory::MarkContextLive(base::SupportsUserData* context) { |
90 base::SupportsUserData* context) { | |
91 DCHECK(CalledOnValidThread()); | 91 DCHECK(CalledOnValidThread()); |
92 dependency_manager_->MarkContextLiveForTesting(context); | 92 dependency_manager_->MarkContextLive(context); |
93 } | 93 } |
94 #endif | |
95 | 94 |
96 bool KeyedServiceBaseFactory::ServiceIsCreatedWithContext() const { | 95 bool KeyedServiceBaseFactory::ServiceIsCreatedWithContext() const { |
97 return false; | 96 return false; |
98 } | 97 } |
99 | 98 |
100 bool KeyedServiceBaseFactory::ServiceIsNULLWhileTesting() const { | 99 bool KeyedServiceBaseFactory::ServiceIsNULLWhileTesting() const { |
101 return false; | 100 return false; |
102 } | 101 } |
103 | 102 |
104 void KeyedServiceBaseFactory::ContextDestroyed( | 103 void KeyedServiceBaseFactory::ContextDestroyed( |
105 base::SupportsUserData* context) { | 104 base::SupportsUserData* context) { |
106 // While object destruction can be customized in ways where the object is | 105 // While object destruction can be customized in ways where the object is |
107 // only dereferenced, this still must run on the UI thread. | 106 // only dereferenced, this still must run on the UI thread. |
108 DCHECK(CalledOnValidThread()); | 107 DCHECK(CalledOnValidThread()); |
109 registered_preferences_.erase(context); | 108 registered_preferences_.erase(context); |
110 } | 109 } |
111 | 110 |
112 bool KeyedServiceBaseFactory::ArePreferencesSetOn( | 111 bool KeyedServiceBaseFactory::ArePreferencesSetOn( |
113 base::SupportsUserData* context) const { | 112 base::SupportsUserData* context) const { |
114 return registered_preferences_.find(context) != registered_preferences_.end(); | 113 return registered_preferences_.find(context) != registered_preferences_.end(); |
115 } | 114 } |
116 | 115 |
117 void KeyedServiceBaseFactory::MarkPreferencesSetOn( | 116 void KeyedServiceBaseFactory::MarkPreferencesSetOn( |
118 base::SupportsUserData* context) { | 117 base::SupportsUserData* context) { |
119 DCHECK(!ArePreferencesSetOn(context)); | 118 DCHECK(!ArePreferencesSetOn(context)); |
120 registered_preferences_.insert(context); | 119 registered_preferences_.insert(context); |
121 } | 120 } |
OLD | NEW |