Home | History | Annotate | Download | only in password_manager
      1 // Copyright (c) 2011 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_MAC_H_
      6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_
      7 #pragma once
      8 
      9 #include <vector>
     10 
     11 #include "base/memory/scoped_ptr.h"
     12 #include "base/threading/thread.h"
     13 #include "chrome/browser/password_manager/login_database.h"
     14 #include "chrome/browser/password_manager/password_store.h"
     15 
     16 class MacKeychain;
     17 class NotificationService;
     18 
     19 // Implements PasswordStore on top of the OS X Keychain, with an internal
     20 // database for extra metadata. For an overview of the interactions with the
     21 // Keychain, as well as the rationale for some of the behaviors, see the
     22 // Keychain integration design doc:
     23 // http://dev.chromium.org/developers/design-documents/os-x-password-manager-keychain-integration
     24 class PasswordStoreMac : public PasswordStore {
     25  public:
     26   // Takes ownership of |keychain| and |login_db|, both of which must be
     27   // non-NULL.
     28   PasswordStoreMac(MacKeychain* keychain, LoginDatabase* login_db);
     29 
     30   // Initializes |thread_| and |notification_service_|.
     31   virtual bool Init();
     32 
     33  protected:
     34   virtual ~PasswordStoreMac();
     35 
     36   // Schedules tasks on |thread_|.
     37   virtual void ScheduleTask(Task* task);
     38 
     39  private:
     40   virtual void ReportMetricsImpl();
     41   virtual void AddLoginImpl(const webkit_glue::PasswordForm& form);
     42   virtual void UpdateLoginImpl(const webkit_glue::PasswordForm& form);
     43   virtual void RemoveLoginImpl(const webkit_glue::PasswordForm& form);
     44   virtual void RemoveLoginsCreatedBetweenImpl(const base::Time& delete_begin,
     45                                               const base::Time& delete_end);
     46   virtual void GetLoginsImpl(GetLoginsRequest* request,
     47                              const webkit_glue::PasswordForm& form);
     48   virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request);
     49   virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request);
     50   virtual bool FillAutofillableLogins(
     51       std::vector<webkit_glue::PasswordForm*>* forms);
     52   virtual bool FillBlacklistLogins(
     53       std::vector<webkit_glue::PasswordForm*>* forms);
     54 
     55   // Adds the given form to the Keychain if it's something we want to store
     56   // there (i.e., not a blacklist entry). Returns true if the operation
     57   // succeeded (either we added successfully, or we didn't need to).
     58   bool AddToKeychainIfNecessary(const webkit_glue::PasswordForm& form);
     59 
     60   // Returns true if our database contains a form that exactly matches the given
     61   // keychain form.
     62   bool DatabaseHasFormMatchingKeychainForm(
     63       const webkit_glue::PasswordForm& form);
     64 
     65   // Returns all the Keychain entries that we own but no longer have
     66   // corresponding metadata for in our database.
     67   // Caller is responsible for deleting the forms.
     68   std::vector<webkit_glue::PasswordForm*> GetUnusedKeychainForms();
     69 
     70   // Removes the given forms from the database.
     71   void RemoveDatabaseForms(
     72       const std::vector<webkit_glue::PasswordForm*>& forms);
     73 
     74   // Removes the given forms from the Keychain.
     75   void RemoveKeychainForms(
     76       const std::vector<webkit_glue::PasswordForm*>& forms);
     77 
     78   // Allows the creation of |notification_service_| to be scheduled on the right
     79   // thread.
     80   void CreateNotificationService();
     81 
     82   scoped_ptr<MacKeychain> keychain_;
     83   scoped_ptr<LoginDatabase> login_metadata_db_;
     84 
     85   // Thread that the synchronous methods are run on.
     86   scoped_ptr<base::Thread> thread_;
     87 
     88   // Since we aren't running on a well-known thread but still want to send out
     89   // notifications, we need to run our own service.
     90   scoped_ptr<NotificationService> notification_service_;
     91 
     92   DISALLOW_COPY_AND_ASSIGN(PasswordStoreMac);
     93 };
     94 
     95 #endif  // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_
     96