Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / signin / signin_manager_factory.h
blob03f17f928a3b11314d97a08a27f0738589acfaf3
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FACTORY_H_
6 #define CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FACTORY_H_
8 #include "base/memory/singleton.h"
9 #include "base/observer_list.h"
10 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
12 class SigninManager;
13 class SigninManagerBase;
14 class PrefRegistrySimple;
15 class Profile;
17 // Singleton that owns all SigninManagers and associates them with
18 // Profiles. Listens for the Profile's destruction notification and cleans up
19 // the associated SigninManager.
20 class SigninManagerFactory : public BrowserContextKeyedServiceFactory {
21 public:
22 class Observer {
23 public:
24 // Called when a SigninManager(Base) instance is created.
25 virtual void SigninManagerCreated(SigninManagerBase* manager) {}
27 // Called when a SigninManager(Base) instance is being shut down. Observers
28 // of |manager| should remove themselves at this point.
29 virtual void SigninManagerShutdown(SigninManagerBase* manager) {}
31 protected:
32 virtual ~Observer() {}
35 #if defined(OS_CHROMEOS)
36 // Returns the instance of SigninManager associated with this profile
37 // (creating one if none exists). Returns NULL if this profile cannot have a
38 // SigninManager (for example, if |profile| is incognito).
39 static SigninManagerBase* GetForProfile(Profile* profile);
41 // Returns the instance of SigninManager associated with this profile. Returns
42 // null if no SigninManager instance currently exists (will not create a new
43 // instance).
44 static SigninManagerBase* GetForProfileIfExists(Profile* profile);
45 #else
46 // On non-ChromeOS platforms, the SigninManager the factory creates will be
47 // an instance of the extended SigninManager class.
48 static SigninManager* GetForProfile(Profile* profile);
49 static SigninManager* GetForProfileIfExists(Profile* profile);
50 #endif
52 // Returns an instance of the SigninManagerFactory singleton.
53 static SigninManagerFactory* GetInstance();
55 // Implementation of BrowserContextKeyedServiceFactory (public so tests
56 // can call it).
57 virtual void RegisterProfilePrefs(
58 user_prefs::PrefRegistrySyncable* registry) OVERRIDE;
60 // Registers the browser-global prefs used by SigninManager.
61 static void RegisterPrefs(PrefRegistrySimple* registry);
63 // Methods to register or remove observers of SigninManager creation/shutdown.
64 void AddObserver(Observer* observer);
65 void RemoveObserver(Observer* observer);
67 // Notifies observers of |manager|'s creation. Should be called only by test
68 // SigninManager subclasses whose construction does not occur in
69 // |BuildServiceInstanceFor()|.
70 void NotifyObserversOfSigninManagerCreationForTesting(
71 SigninManagerBase* manager);
73 private:
74 friend struct DefaultSingletonTraits<SigninManagerFactory>;
76 SigninManagerFactory();
77 virtual ~SigninManagerFactory();
79 #if defined(OS_MACOSX)
80 // List of observers. Does not check that list is empty on destruction, as
81 // there are some leaky singletons that observe the SigninManagerFactory.
82 mutable ObserverList<Observer> observer_list_;
83 #else
84 // List of observers. Checks that list is empty on destruction.
85 mutable ObserverList<Observer, true> observer_list_;
86 #endif
88 // BrowserContextKeyedServiceFactory:
89 virtual KeyedService* BuildServiceInstanceFor(
90 content::BrowserContext* profile) const OVERRIDE;
91 virtual void BrowserContextShutdown(content::BrowserContext* context)
92 OVERRIDE;
95 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_FACTORY_H_