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