| 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_factory.h" | 5 #include "components/keyed_service/core/keyed_service_factory.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 void KeyedServiceFactory::SetTestingFactory( | 24 void KeyedServiceFactory::SetTestingFactory( |
| 25 base::SupportsUserData* context, | 25 base::SupportsUserData* context, |
| 26 TestingFactoryFunction testing_factory) { | 26 TestingFactoryFunction testing_factory) { |
| 27 // Destroying the context may cause us to lose data about whether |context| | 27 // Destroying the context may cause us to lose data about whether |context| |
| 28 // has our preferences registered on it (since the context object itself | 28 // has our preferences registered on it (since the context object itself |
| 29 // isn't dead). See if we need to readd it once we've gone through normal | 29 // isn't dead). See if we need to readd it once we've gone through normal |
| 30 // destruction. | 30 // destruction. |
| 31 bool add_context = ArePreferencesSetOn(context); | 31 bool add_context = ArePreferencesSetOn(context); |
| 32 | 32 |
| 33 #ifndef NDEBUG | |
| 34 // Ensure that |context| is not marked as stale (e.g., due to it aliasing an | 33 // Ensure that |context| is not marked as stale (e.g., due to it aliasing an |
| 35 // instance that was destroyed in an earlier test) in order to avoid accesses | 34 // instance that was destroyed in an earlier test) in order to avoid accesses |
| 36 // to |context| in |BrowserContextShutdown| from causing | 35 // to |context| in |BrowserContextShutdown| from causing |
| 37 // |AssertBrowserContextWasntDestroyed| to raise an error. | 36 // |AssertBrowserContextWasntDestroyed| to raise an error. |
| 38 MarkContextLiveForTesting(context); | 37 MarkContextLive(context); |
| 39 #endif | |
| 40 | 38 |
| 41 // We have to go through the shutdown and destroy mechanisms because there | 39 // We have to go through the shutdown and destroy mechanisms because there |
| 42 // are unit tests that create a service on a context and then change the | 40 // are unit tests that create a service on a context and then change the |
| 43 // testing service mid-test. | 41 // testing service mid-test. |
| 44 ContextShutdown(context); | 42 ContextShutdown(context); |
| 45 ContextDestroyed(context); | 43 ContextDestroyed(context); |
| 46 | 44 |
| 47 if (add_context) | 45 if (add_context) |
| 48 MarkPreferencesSetOn(context); | 46 MarkPreferencesSetOn(context); |
| 49 | 47 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 SetTestingFactory(context, nullptr); | 130 SetTestingFactory(context, nullptr); |
| 133 } | 131 } |
| 134 | 132 |
| 135 bool KeyedServiceFactory::HasTestingFactory(base::SupportsUserData* context) { | 133 bool KeyedServiceFactory::HasTestingFactory(base::SupportsUserData* context) { |
| 136 return testing_factories_.find(context) != testing_factories_.end(); | 134 return testing_factories_.find(context) != testing_factories_.end(); |
| 137 } | 135 } |
| 138 | 136 |
| 139 void KeyedServiceFactory::CreateServiceNow(base::SupportsUserData* context) { | 137 void KeyedServiceFactory::CreateServiceNow(base::SupportsUserData* context) { |
| 140 GetServiceForContext(context, true); | 138 GetServiceForContext(context, true); |
| 141 } | 139 } |
| OLD | NEW |