OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef IOS_CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FACTORY_H_ |
| 6 #define IOS_CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FACTORY_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/observer_list.h" |
| 11 #include "components/keyed_service/ios/browser_state_keyed_service_factory.h" |
| 12 |
| 13 template <typename T> |
| 14 struct DefaultSingletonTraits; |
| 15 |
| 16 class SigninManagerFactoryObserver; |
| 17 class SigninManager; |
| 18 class PrefRegistrySimple; |
| 19 |
| 20 namespace ios { |
| 21 |
| 22 class ChromeBrowserState; |
| 23 |
| 24 // Singleton that owns all SigninManagers and associates them with browser |
| 25 // states. |
| 26 class SigninManagerFactory : public BrowserStateKeyedServiceFactory { |
| 27 public: |
| 28 static SigninManager* GetForBrowserState( |
| 29 ios::ChromeBrowserState* browser_state); |
| 30 static SigninManager* GetForBrowserStateIfExists( |
| 31 ios::ChromeBrowserState* browser_state); |
| 32 |
| 33 // Returns an instance of the SigninManagerFactory singleton. |
| 34 static SigninManagerFactory* GetInstance(); |
| 35 |
| 36 // Implementation of BrowserStateKeyedServiceFactory (public so tests |
| 37 // can call it). |
| 38 void RegisterBrowserStatePrefs( |
| 39 user_prefs::PrefRegistrySyncable* registry) override; |
| 40 |
| 41 // Registers the browser-global prefs used by SigninManager. |
| 42 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 43 |
| 44 // Methods to register or remove observers of SigninManager creation/shutdown. |
| 45 void AddObserver(SigninManagerFactoryObserver* observer); |
| 46 void RemoveObserver(SigninManagerFactoryObserver* observer); |
| 47 |
| 48 // Notifies observers of |manager|'s creation. Should be called only by test |
| 49 // SigninManager subclasses whose construction does not occur in |
| 50 // |BuildServiceInstanceFor()|. |
| 51 void NotifyObserversOfSigninManagerCreationForTesting(SigninManager* manager); |
| 52 |
| 53 private: |
| 54 friend struct DefaultSingletonTraits<SigninManagerFactory>; |
| 55 |
| 56 SigninManagerFactory(); |
| 57 ~SigninManagerFactory() override; |
| 58 |
| 59 // List of observers. Checks that list is empty on destruction. |
| 60 mutable base::ObserverList<SigninManagerFactoryObserver, true> observer_list_; |
| 61 |
| 62 // BrowserStateKeyedServiceFactory: |
| 63 scoped_ptr<KeyedService> BuildServiceInstanceFor( |
| 64 web::BrowserState* context) const override; |
| 65 void BrowserStateShutdown(web::BrowserState* context) override; |
| 66 }; |
| 67 } |
| 68 |
| 69 #endif // IOS_CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FACTORY_H_ |
OLD | NEW |