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();
61 // Called by the PasswordDataTypeController whenever there is a possibility
62 // that syncing passwords has just started or ended for |profile|.
63 static void OnPasswordsSyncedStatePotentiallyChanged(Profile
* profile
);
65 // Trims the affiliation cache for |profile| if affiliation-based matching is
66 // enabled, and completely deletes it otherwise.
67 static void TrimOrDeleteAffiliationCache(Profile
* profile
);
70 friend struct DefaultSingletonTraits
<PasswordStoreFactory
>;
72 PasswordStoreFactory();
73 ~PasswordStoreFactory() override
;
75 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
76 LocalProfileId
GetLocalProfileId(PrefService
* prefs
) const;
79 // BrowserContextKeyedServiceFactory:
80 KeyedService
* BuildServiceInstanceFor(
81 content::BrowserContext
* context
) const override
;
82 void RegisterProfilePrefs(
83 user_prefs::PrefRegistrySyncable
* registry
) override
;
84 content::BrowserContext
* GetBrowserContextToUse(
85 content::BrowserContext
* context
) const override
;
86 bool ServiceIsNULLWhileTesting() const override
;
89 enum LinuxBackendUsage
{
92 KDE_KWALLETFLAG_PLAINTEXT
,
93 KDE_KWALLETFLAG_KWALLET
,
94 KDE_GNOMEFLAG_PLAINTEXT
,
95 KDE_GNOMEFLAG_KEYRING
,
96 KDE_GNOMEFLAG_LIBSECRET
,
97 KDE_BASICFLAG_PLAINTEXT
,
98 GNOME_NOFLAG_PLAINTEXT
,
100 GNOME_NOFLAG_LIBSECRET
,
101 GNOME_GNOMEFLAG_PLAINTEXT
,
102 GNOME_GNOMEFLAG_KEYRING
,
103 GNOME_GNOMEFLAG_LIBSECRET
,
104 GNOME_KWALLETFLAG_PLAINTEXT
,
105 GNOME_KWALLETFLAG_KWALLET
,
106 GNOME_BASICFLAG_PLAINTEXT
,
111 MAX_BACKEND_USAGE_VALUE
114 enum LinuxBackendUsed
{ PLAINTEXT
, GNOME_KEYRING
, LIBSECRET
, KWALLET
};
116 static base::nix::DesktopEnvironment
GetDesktopEnvironment();
117 static void RecordBackendStatistics(base::nix::DesktopEnvironment desktop_env
,
118 const std::string
& command_line_flag
,
119 LinuxBackendUsed used_backend
);
122 DISALLOW_COPY_AND_ASSIGN(PasswordStoreFactory
);
125 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_FACTORY_H_