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 "components/keyed_service/content/browser_context_keyed_service_factory.h"
11 #include "components/keyed_service/core/keyed_service.h"
12 #include "components/keyed_service/core/service_access_type.h"
15 #include "base/nix/xdg_util.h"
20 namespace password_manager
{
24 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
25 // Local profile ids are used to associate resources stored outside the profile
26 // directory, like saved passwords in GNOME Keyring / KWallet, with a profile.
27 // With high probability, they are unique on the local machine. They are almost
28 // certainly not unique globally, by design. Do not send them over the network.
29 typedef int LocalProfileId
;
32 // A wrapper of PasswordStore so we can use it as a profiled keyed service.
33 class PasswordStoreService
: public KeyedService
{
35 // |password_store| needs to be not-NULL, and the constructor expects that
36 // Init() was already called successfully on it.
37 explicit PasswordStoreService(
38 scoped_refptr
<password_manager::PasswordStore
> password_store
);
39 ~PasswordStoreService() override
;
41 scoped_refptr
<password_manager::PasswordStore
> GetPasswordStore();
43 // KeyedService implementation.
44 void Shutdown() override
;
47 scoped_refptr
<password_manager::PasswordStore
> password_store_
;
48 DISALLOW_COPY_AND_ASSIGN(PasswordStoreService
);
51 // Singleton that owns all PasswordStores and associates them with
53 class PasswordStoreFactory
: public BrowserContextKeyedServiceFactory
{
55 static scoped_refptr
<password_manager::PasswordStore
> GetForProfile(
57 ServiceAccessType set
);
59 static PasswordStoreFactory
* GetInstance();
62 friend struct DefaultSingletonTraits
<PasswordStoreFactory
>;
64 PasswordStoreFactory();
65 ~PasswordStoreFactory() override
;
67 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
68 LocalProfileId
GetLocalProfileId(PrefService
* prefs
) const;
71 // BrowserContextKeyedServiceFactory:
72 KeyedService
* BuildServiceInstanceFor(
73 content::BrowserContext
* context
) const override
;
74 void RegisterProfilePrefs(
75 user_prefs::PrefRegistrySyncable
* registry
) override
;
76 content::BrowserContext
* GetBrowserContextToUse(
77 content::BrowserContext
* context
) const override
;
78 bool ServiceIsNULLWhileTesting() const override
;
81 enum LinuxBackendUsage
{
84 KDE_KWALLETFLAG_PLAINTEXT
,
85 KDE_KWALLETFLAG_KWALLET
,
86 KDE_GNOMEFLAG_PLAINTEXT
,
87 KDE_GNOMEFLAG_KEYRING
,
88 KDE_GNOMEFLAG_LIBSECRET
,
89 KDE_BASICFLAG_PLAINTEXT
,
90 GNOME_NOFLAG_PLAINTEXT
,
92 GNOME_NOFLAG_LIBSECRET
,
93 GNOME_GNOMEFLAG_PLAINTEXT
,
94 GNOME_GNOMEFLAG_KEYRING
,
95 GNOME_GNOMEFLAG_LIBSECRET
,
96 GNOME_KWALLETFLAG_PLAINTEXT
,
97 GNOME_KWALLETFLAG_KWALLET
,
98 GNOME_BASICFLAG_PLAINTEXT
,
103 MAX_BACKEND_USAGE_VALUE
106 enum LinuxBackendUsed
{ PLAINTEXT
, GNOME_KEYRING
, LIBSECRET
, KWALLET
};
108 static base::nix::DesktopEnvironment
GetDesktopEnvironment();
109 static void RecordBackendStatistics(base::nix::DesktopEnvironment desktop_env
,
110 const std::string
& command_line_flag
,
111 LinuxBackendUsed used_backend
);
114 DISALLOW_COPY_AND_ASSIGN(PasswordStoreFactory
);
117 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_FACTORY_H_