| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_KEYED_SERVICE_F
ACTORY_H_ | 5 #ifndef COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_KEYED_SERVICE_F
ACTORY_H_ |
| 6 #define COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_KEYED_SERVICE_F
ACTORY_H_ | 6 #define COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_KEYED_SERVICE_F
ACTORY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 typedef BrowserContextKeyedService* | 32 typedef BrowserContextKeyedService* |
| 33 (*FactoryFunction)(content::BrowserContext* context); | 33 (*FactoryFunction)(content::BrowserContext* context); |
| 34 | 34 |
| 35 // Associates |factory| with |context| so that |factory| is used to create | 35 // Associates |factory| with |context| so that |factory| is used to create |
| 36 // the BrowserContextKeyedService when requested. |factory| can be NULL | 36 // the BrowserContextKeyedService when requested. |factory| can be NULL |
| 37 // to signal that BrowserContextKeyedService should be NULL. Multiple calls to | 37 // to signal that BrowserContextKeyedService should be NULL. Multiple calls to |
| 38 // SetTestingFactory() are allowed; previous services will be shut down. | 38 // SetTestingFactory() are allowed; previous services will be shut down. |
| 39 void SetTestingFactory(content::BrowserContext* context, | 39 void SetTestingFactory(content::BrowserContext* context, |
| 40 FactoryFunction factory); | 40 FactoryFunction factory); |
| 41 | 41 |
| 42 // Like SetTestingFactory(), but takes effect for all contexts. This is useful |
| 43 // for injecting services that are created as part of context initialization. |
| 44 // Callers should be sure to call ResetGlobalTestingFactory() at the end of |
| 45 // their test to avoid polluting the singletons for future tests. |
| 46 void SetGlobalTestingFactory(FactoryFunction factory); |
| 47 |
| 48 // Clears a global testing factory that was previously set. |
| 49 void ResetGlobalTestingFactory(); |
| 50 |
| 42 // Associates |factory| with |context| and immediately returns the created | 51 // Associates |factory| with |context| and immediately returns the created |
| 43 // BrowserContextKeyedService. Since the factory will be used immediately, | 52 // BrowserContextKeyedService. Since the factory will be used immediately, |
| 44 // it may not be NULL. | 53 // it may not be NULL. |
| 45 BrowserContextKeyedService* SetTestingFactoryAndUse( | 54 BrowserContextKeyedService* SetTestingFactoryAndUse( |
| 46 content::BrowserContext* context, | 55 content::BrowserContext* context, |
| 47 FactoryFunction factory); | 56 FactoryFunction factory); |
| 48 | 57 |
| 49 protected: | 58 protected: |
| 50 // BrowserContextKeyedServiceFactories must communicate with a | 59 // BrowserContextKeyedServiceFactories must communicate with a |
| 51 // BrowserContextDependencyManager. For all non-test code, write your subclass | 60 // BrowserContextDependencyManager. For all non-test code, write your subclass |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 112 |
| 104 private: | 113 private: |
| 105 friend class BrowserContextDependencyManager; | 114 friend class BrowserContextDependencyManager; |
| 106 friend class BrowserContextDependencyManagerUnittests; | 115 friend class BrowserContextDependencyManagerUnittests; |
| 107 | 116 |
| 108 typedef std::map<content::BrowserContext*, BrowserContextKeyedService*> | 117 typedef std::map<content::BrowserContext*, BrowserContextKeyedService*> |
| 109 BrowserContextKeyedServices; | 118 BrowserContextKeyedServices; |
| 110 typedef std::map<content::BrowserContext*, FactoryFunction> | 119 typedef std::map<content::BrowserContext*, FactoryFunction> |
| 111 BrowserContextOverriddenFunctions; | 120 BrowserContextOverriddenFunctions; |
| 112 | 121 |
| 122 void CleanupExistingServices(content::BrowserContext* context); |
| 123 |
| 113 // The mapping between a BrowserContext and its service. | 124 // The mapping between a BrowserContext and its service. |
| 114 std::map<content::BrowserContext*, BrowserContextKeyedService*> mapping_; | 125 std::map<content::BrowserContext*, BrowserContextKeyedService*> mapping_; |
| 115 | 126 |
| 116 // The mapping between a BrowserContext and its overridden FactoryFunction. | 127 // The mapping between a BrowserContext and its overridden FactoryFunction. |
| 117 std::map<content::BrowserContext*, FactoryFunction> factories_; | 128 std::map<content::BrowserContext*, FactoryFunction> factories_; |
| 118 | 129 |
| 130 FactoryFunction global_factory_; |
| 131 bool have_global_factory_; |
| 132 |
| 119 DISALLOW_COPY_AND_ASSIGN(BrowserContextKeyedServiceFactory); | 133 DISALLOW_COPY_AND_ASSIGN(BrowserContextKeyedServiceFactory); |
| 120 }; | 134 }; |
| 121 | 135 |
| 122 #endif // COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_KEYED_SERVIC
E_FACTORY_H_ | 136 #endif // COMPONENTS_BROWSER_CONTEXT_KEYED_SERVICE_BROWSER_CONTEXT_KEYED_SERVIC
E_FACTORY_H_ |
| OLD | NEW |