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_PASSWORD_MANAGER_PASSWORD_STORE_FACTORY_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_FACTORY_H_
8 #include "base/basictypes.h"
9 #include "base/memory/singleton.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "components/keyed_service/content/browser_context_keyed_service_factory.h"
15 namespace password_manager
{
19 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
20 // Local profile ids are used to associate resources stored outside the profile
21 // directory, like saved passwords in GNOME Keyring / KWallet, with a profile.
22 // With high probability, they are unique on the local machine. They are almost
23 // certainly not unique globally, by design. Do not send them over the network.
24 typedef int LocalProfileId
;
27 // A wrapper of PasswordStore so we can use it as a profiled keyed service.
28 class PasswordStoreService
: public KeyedService
{
30 // |password_store| needs to be not-NULL, and the constructor expects that
31 // Init() was already called successfully on it.
32 explicit PasswordStoreService(
33 scoped_refptr
<password_manager::PasswordStore
> password_store
);
34 virtual ~PasswordStoreService();
36 scoped_refptr
<password_manager::PasswordStore
> GetPasswordStore();
38 // KeyedService implementation.
39 virtual void Shutdown() OVERRIDE
;
42 scoped_refptr
<password_manager::PasswordStore
> password_store_
;
43 DISALLOW_COPY_AND_ASSIGN(PasswordStoreService
);
46 // Singleton that owns all PasswordStores and associates them with
48 class PasswordStoreFactory
: public BrowserContextKeyedServiceFactory
{
50 static scoped_refptr
<password_manager::PasswordStore
> GetForProfile(
52 Profile::ServiceAccessType set
);
54 static PasswordStoreFactory
* GetInstance();
57 friend struct DefaultSingletonTraits
<PasswordStoreFactory
>;
59 PasswordStoreFactory();
60 virtual ~PasswordStoreFactory();
62 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
63 LocalProfileId
GetLocalProfileId(PrefService
* prefs
) const;
66 // BrowserContextKeyedServiceFactory:
67 virtual KeyedService
* BuildServiceInstanceFor(
68 content::BrowserContext
* context
) const OVERRIDE
;
69 virtual void RegisterProfilePrefs(
70 user_prefs::PrefRegistrySyncable
* registry
) OVERRIDE
;
71 virtual content::BrowserContext
* GetBrowserContextToUse(
72 content::BrowserContext
* context
) const OVERRIDE
;
73 virtual bool ServiceIsNULLWhileTesting() const OVERRIDE
;
75 DISALLOW_COPY_AND_ASSIGN(PasswordStoreFactory
);
78 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_FACTORY_H_