Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / password_manager / password_store_factory.h
blobd11d2b84dc6599b882faa76b6d0c30d0e8cef037
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"
14 #if defined(USE_X11)
15 #include "base/nix/xdg_util.h"
16 #endif
18 class Profile;
20 namespace password_manager {
21 class PasswordStore;
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;
30 #endif
32 // A wrapper of PasswordStore so we can use it as a profiled keyed service.
33 class PasswordStoreService : public KeyedService {
34 public:
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;
46 private:
47 scoped_refptr<password_manager::PasswordStore> password_store_;
48 DISALLOW_COPY_AND_ASSIGN(PasswordStoreService);
51 // Singleton that owns all PasswordStores and associates them with
52 // Profiles.
53 class PasswordStoreFactory : public BrowserContextKeyedServiceFactory {
54 public:
55 static scoped_refptr<password_manager::PasswordStore> GetForProfile(
56 Profile* profile,
57 ServiceAccessType set);
59 static PasswordStoreFactory* GetInstance();
61 private:
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;
69 #endif
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;
80 #if defined(USE_X11)
81 enum LinuxBackendUsage {
82 KDE_NOFLAG_PLAINTEXT,
83 KDE_NOFLAG_KWALLET,
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,
91 GNOME_NOFLAG_KEYRING,
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,
99 OTHER_PLAINTEXT,
100 OTHER_KWALLET,
101 OTHER_KEYRING,
102 OTHER_LIBSECRET,
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);
112 #endif
114 DISALLOW_COPY_AND_ASSIGN(PasswordStoreFactory);
117 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_FACTORY_H_