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.
5 #ifndef IOS_CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FACTORY_H_
6 #define IOS_CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FACTORY_H_
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"
14 struct DefaultSingletonTraits
;
16 class SigninManagerFactoryObserver
;
18 class PrefRegistrySimple
;
22 class ChromeBrowserState
;
24 // Singleton that owns all SigninManagers and associates them with browser
26 class SigninManagerFactory
: public BrowserStateKeyedServiceFactory
{
28 static SigninManager
* GetForBrowserState(
29 ios::ChromeBrowserState
* browser_state
);
30 static SigninManager
* GetForBrowserStateIfExists(
31 ios::ChromeBrowserState
* browser_state
);
33 // Returns an instance of the SigninManagerFactory singleton.
34 static SigninManagerFactory
* GetInstance();
36 // Implementation of BrowserStateKeyedServiceFactory (public so tests
38 void RegisterBrowserStatePrefs(
39 user_prefs::PrefRegistrySyncable
* registry
) override
;
41 // Registers the browser-global prefs used by SigninManager.
42 static void RegisterPrefs(PrefRegistrySimple
* registry
);
44 // Methods to register or remove observers of SigninManager creation/shutdown.
45 void AddObserver(SigninManagerFactoryObserver
* observer
);
46 void RemoveObserver(SigninManagerFactoryObserver
* observer
);
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
);
54 friend struct DefaultSingletonTraits
<SigninManagerFactory
>;
56 SigninManagerFactory();
57 ~SigninManagerFactory() override
;
59 // List of observers. Checks that list is empty on destruction.
60 mutable base::ObserverList
<SigninManagerFactoryObserver
, true> observer_list_
;
62 // BrowserStateKeyedServiceFactory:
63 scoped_ptr
<KeyedService
> BuildServiceInstanceFor(
64 web::BrowserState
* context
) const override
;
65 void BrowserStateShutdown(web::BrowserState
* context
) override
;
69 #endif // IOS_CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FACTORY_H_