Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / password_manager / password_store_factory.h
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.
4
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_FACTORY_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_FACTORY_H_
7
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"
13
14 class Profile;
15
16 namespace password_manager {
17 class PasswordStore;
18 }
19
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;
26 #endif
27
28 // A wrapper of PasswordStore so we can use it as a profiled keyed service.
29 class PasswordStoreService : public KeyedService {
30  public:
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   ~PasswordStoreService() override;
36
37   scoped_refptr<password_manager::PasswordStore> GetPasswordStore();
38
39   // KeyedService implementation.
40   void Shutdown() override;
41
42  private:
43   scoped_refptr<password_manager::PasswordStore> password_store_;
44   DISALLOW_COPY_AND_ASSIGN(PasswordStoreService);
45 };
46
47 // Singleton that owns all PasswordStores and associates them with
48 // Profiles.
49 class PasswordStoreFactory : public BrowserContextKeyedServiceFactory {
50  public:
51   static scoped_refptr<password_manager::PasswordStore> GetForProfile(
52       Profile* profile,
53       Profile::ServiceAccessType set);
54
55   static PasswordStoreFactory* GetInstance();
56
57  private:
58   friend struct DefaultSingletonTraits<PasswordStoreFactory>;
59
60   PasswordStoreFactory();
61   ~PasswordStoreFactory() override;
62
63 #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
64   LocalProfileId GetLocalProfileId(PrefService* prefs) const;
65 #endif
66
67   // BrowserContextKeyedServiceFactory:
68   KeyedService* BuildServiceInstanceFor(
69       content::BrowserContext* context) const override;
70   void RegisterProfilePrefs(
71       user_prefs::PrefRegistrySyncable* registry) override;
72   content::BrowserContext* GetBrowserContextToUse(
73       content::BrowserContext* context) const override;
74   bool ServiceIsNULLWhileTesting() const override;
75
76   DISALLOW_COPY_AND_ASSIGN(PasswordStoreFactory);
77 };
78
79 #endif  // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_FACTORY_H_