password_store_mac.h revision effb81e5f8246d0db0270817048dc992db66e9fb
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_MAC_H_ 6#define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_ 7 8#include <vector> 9 10#include "base/callback_forward.h" 11#include "base/memory/scoped_ptr.h" 12#include "base/threading/thread.h" 13#include "components/password_manager/core/browser/login_database.h" 14#include "components/password_manager/core/browser/password_store.h" 15 16namespace crypto { 17class AppleKeychain; 18} 19 20// Implements PasswordStore on top of the OS X Keychain, with an internal 21// database for extra metadata. For an overview of the interactions with the 22// Keychain, as well as the rationale for some of the behaviors, see the 23// Keychain integration design doc: 24// http://dev.chromium.org/developers/design-documents/os-x-password-manager-keychain-integration 25class PasswordStoreMac : public PasswordStore { 26 public: 27 // Takes ownership of |keychain| and |login_db|, both of which must be 28 // non-NULL. 29 PasswordStoreMac( 30 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, 31 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, 32 crypto::AppleKeychain* keychain, 33 LoginDatabase* login_db); 34 35 // Initializes |thread_|. 36 virtual bool Init( 37 const syncer::SyncableService::StartSyncFlare& flare) OVERRIDE; 38 39 // Stops |thread_|. 40 virtual void Shutdown() OVERRIDE; 41 42 protected: 43 virtual ~PasswordStoreMac(); 44 45 virtual scoped_refptr<base::SingleThreadTaskRunner> 46 GetBackgroundTaskRunner() OVERRIDE; 47 48 private: 49 virtual void ReportMetricsImpl() OVERRIDE; 50 virtual PasswordStoreChangeList AddLoginImpl( 51 const autofill::PasswordForm& form) OVERRIDE; 52 virtual PasswordStoreChangeList UpdateLoginImpl( 53 const autofill::PasswordForm& form) OVERRIDE; 54 virtual PasswordStoreChangeList RemoveLoginImpl( 55 const autofill::PasswordForm& form) OVERRIDE; 56 virtual PasswordStoreChangeList RemoveLoginsCreatedBetweenImpl( 57 const base::Time& delete_begin, const base::Time& delete_end) OVERRIDE; 58 virtual void GetLoginsImpl( 59 const autofill::PasswordForm& form, 60 AuthorizationPromptPolicy prompt_policy, 61 const ConsumerCallbackRunner& callback_runner) OVERRIDE; 62 virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request) OVERRIDE; 63 virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) OVERRIDE; 64 virtual bool FillAutofillableLogins( 65 std::vector<autofill::PasswordForm*>* forms) OVERRIDE; 66 virtual bool FillBlacklistLogins( 67 std::vector<autofill::PasswordForm*>* forms) OVERRIDE; 68 69 // Adds the given form to the Keychain if it's something we want to store 70 // there (i.e., not a blacklist entry). Returns true if the operation 71 // succeeded (either we added successfully, or we didn't need to). 72 bool AddToKeychainIfNecessary(const autofill::PasswordForm& form); 73 74 // Returns true if our database contains a form that exactly matches the given 75 // keychain form. 76 bool DatabaseHasFormMatchingKeychainForm( 77 const autofill::PasswordForm& form); 78 79 // Returns all the Keychain entries that we own but no longer have 80 // corresponding metadata for in our database. 81 // Caller is responsible for deleting the forms. 82 std::vector<autofill::PasswordForm*> GetUnusedKeychainForms(); 83 84 // Removes the given forms from the database. 85 void RemoveDatabaseForms( 86 const std::vector<autofill::PasswordForm*>& forms); 87 88 // Removes the given forms from the Keychain. 89 void RemoveKeychainForms( 90 const std::vector<autofill::PasswordForm*>& forms); 91 92 scoped_ptr<crypto::AppleKeychain> keychain_; 93 scoped_ptr<LoginDatabase> login_metadata_db_; 94 95 // Thread that the synchronous methods are run on. 96 scoped_ptr<base::Thread> thread_; 97 98 DISALLOW_COPY_AND_ASSIGN(PasswordStoreMac); 99}; 100 101#endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_ 102