Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / chrome / browser / signin / signin_manager_factory.h
blob3bfb2b763c9f57ce85f1d9c75785a7900e0c72dd
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"
13 namespace base {
14 template <typename T>
15 struct DefaultSingletonTraits;
16 } // namespace base
18 class SigninManagerFactoryObserver;
19 class SigninManager;
20 class PrefRegistrySimple;
22 namespace ios {
24 class ChromeBrowserState;
26 // Singleton that owns all SigninManagers and associates them with browser
27 // states.
28 class SigninManagerFactory : public BrowserStateKeyedServiceFactory {
29 public:
30 static SigninManager* GetForBrowserState(
31 ios::ChromeBrowserState* browser_state);
32 static SigninManager* GetForBrowserStateIfExists(
33 ios::ChromeBrowserState* browser_state);
35 // Returns an instance of the SigninManagerFactory singleton.
36 static SigninManagerFactory* GetInstance();
38 // Implementation of BrowserStateKeyedServiceFactory (public so tests
39 // can call it).
40 void RegisterBrowserStatePrefs(
41 user_prefs::PrefRegistrySyncable* registry) override;
43 // Registers the browser-global prefs used by SigninManager.
44 static void RegisterPrefs(PrefRegistrySimple* registry);
46 // Methods to register or remove observers of SigninManager creation/shutdown.
47 void AddObserver(SigninManagerFactoryObserver* observer);
48 void RemoveObserver(SigninManagerFactoryObserver* observer);
50 // Notifies observers of |manager|'s creation. Should be called only by test
51 // SigninManager subclasses whose construction does not occur in
52 // |BuildServiceInstanceFor()|.
53 void NotifyObserversOfSigninManagerCreationForTesting(SigninManager* manager);
55 private:
56 friend struct base::DefaultSingletonTraits<SigninManagerFactory>;
58 SigninManagerFactory();
59 ~SigninManagerFactory() override;
61 // List of observers. Checks that list is empty on destruction.
62 mutable base::ObserverList<SigninManagerFactoryObserver, true> observer_list_;
64 // BrowserStateKeyedServiceFactory:
65 scoped_ptr<KeyedService> BuildServiceInstanceFor(
66 web::BrowserState* context) const override;
67 void BrowserStateShutdown(web::BrowserState* context) override;
71 #endif // IOS_CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FACTORY_H_