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