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"
12 #include "components/keyed_service/core/keyed_service.h"
16 namespace password_manager
{
20 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
21 // Local profile ids are used to associate resources stored outside the profile
22 // directory, like saved passwords in GNOME Keyring / KWallet, with a profile.
23 // With high probability, they are unique on the local machine. They are almost
24 // certainly not unique globally, by design. Do not send them over the network.
25 typedef int LocalProfileId
;
28 // A wrapper of PasswordStore so we can use it as a profiled keyed service.
29 class PasswordStoreService
: public KeyedService
{
31 // |password_store| needs to be not-NULL, and the constructor expects that
32 // Init() was already called successfully on it.
33 explicit PasswordStoreService(
34 scoped_refptr
<password_manager::PasswordStore
> password_store
);
35 virtual ~PasswordStoreService();
37 scoped_refptr
<password_manager::PasswordStore
> GetPasswordStore();
39 // KeyedService implementation.
40 virtual void Shutdown() override
;
43 scoped_refptr
<password_manager::PasswordStore
> password_store_
;
44 DISALLOW_COPY_AND_ASSIGN(PasswordStoreService
);
47 // Singleton that owns all PasswordStores and associates them with
49 class PasswordStoreFactory
: public BrowserContextKeyedServiceFactory
{
51 static scoped_refptr
<password_manager::PasswordStore
> GetForProfile(
53 Profile::ServiceAccessType set
);
55 static PasswordStoreFactory
* GetInstance();
58 friend struct DefaultSingletonTraits
<PasswordStoreFactory
>;
60 PasswordStoreFactory();
61 virtual ~PasswordStoreFactory();
63 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
64 LocalProfileId
GetLocalProfileId(PrefService
* prefs
) const;
67 // BrowserContextKeyedServiceFactory:
68 virtual KeyedService
* BuildServiceInstanceFor(
69 content::BrowserContext
* context
) const override
;
70 virtual void RegisterProfilePrefs(
71 user_prefs::PrefRegistrySyncable
* registry
) override
;
72 virtual content::BrowserContext
* GetBrowserContextToUse(
73 content::BrowserContext
* context
) const override
;
74 virtual bool ServiceIsNULLWhileTesting() const override
;
76 DISALLOW_COPY_AND_ASSIGN(PasswordStoreFactory
);
79 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_FACTORY_H_