password_store_mac.h revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood// Copyright (c) 2012 The Chromium Authors. All rights reserved. 294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood// Use of this source code is governed by a BSD-style license that can be 394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood// found in the LICENSE file. 4d93707342a61e66bc3eb2145628158452f577f42Dave Allison 5d93707342a61e66bc3eb2145628158452f577f42Dave Allison#ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_ 6d93707342a61e66bc3eb2145628158452f577f42Dave Allison#define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_ 794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 8d93707342a61e66bc3eb2145628158452f577f42Dave Allison#include <vector> 994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 10d93707342a61e66bc3eb2145628158452f577f42Dave Allison#include "base/callback_forward.h" 11d93707342a61e66bc3eb2145628158452f577f42Dave Allison#include "base/memory/scoped_ptr.h" 12d93707342a61e66bc3eb2145628158452f577f42Dave Allison#include "base/threading/thread.h" 13d93707342a61e66bc3eb2145628158452f577f42Dave Allison#include "components/password_manager/core/browser/login_database.h" 1494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood#include "components/password_manager/core/browser/password_store.h" 1594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 1694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodnamespace crypto { 1794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodclass AppleKeychain; 1894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood} 1994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 2094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodnamespace password_manager { 2194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodclass LoginDatabase; 2294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood} 2394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 2494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood// Implements PasswordStore on top of the OS X Keychain, with an internal 2594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood// database for extra metadata. For an overview of the interactions with the 2694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood// Keychain, as well as the rationale for some of the behaviors, see the 2794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood// Keychain integration design doc: 2894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood// http://dev.chromium.org/developers/design-documents/os-x-password-manager-keychain-integration 2994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwoodclass PasswordStoreMac : public password_manager::PasswordStore { 3094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood public: 3194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood // Takes ownership of |keychain| and |login_db|, both of which must be 3294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood // non-NULL. 3394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood PasswordStoreMac( 3494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, 3594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, 3694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood crypto::AppleKeychain* keychain, 3794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood password_manager::LoginDatabase* login_db); 3894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 3994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood // Initializes |thread_|. 4094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood virtual bool Init( 4194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood const syncer::SyncableService::StartSyncFlare& flare) OVERRIDE; 4294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 4394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood // Stops |thread_|. 4494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood virtual void Shutdown() OVERRIDE; 4594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 4694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood protected: 4794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood virtual ~PasswordStoreMac(); 4894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 4994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood virtual scoped_refptr<base::SingleThreadTaskRunner> 5094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood GetBackgroundTaskRunner() OVERRIDE; 5194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 5294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood private: 5394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood virtual void ReportMetricsImpl() OVERRIDE; 5494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood virtual password_manager::PasswordStoreChangeList AddLoginImpl( 5594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood const autofill::PasswordForm& form) OVERRIDE; 56abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey virtual password_manager::PasswordStoreChangeList UpdateLoginImpl( 5794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood const autofill::PasswordForm& form) OVERRIDE; 5894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood virtual password_manager::PasswordStoreChangeList RemoveLoginImpl( 5994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood const autofill::PasswordForm& form) OVERRIDE; 6094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood virtual password_manager::PasswordStoreChangeList 61abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey RemoveLoginsCreatedBetweenImpl(const base::Time& delete_begin, 6294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood const base::Time& delete_end) OVERRIDE; 63abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey virtual void GetLoginsImpl( 64abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey const autofill::PasswordForm& form, 65abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey AuthorizationPromptPolicy prompt_policy, 66abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey const ConsumerCallbackRunner& callback_runner) OVERRIDE; 67abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey virtual void GetAutofillableLoginsImpl(GetLoginsRequest* request) OVERRIDE; 6894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood virtual void GetBlacklistLoginsImpl(GetLoginsRequest* request) OVERRIDE; 69abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey virtual bool FillAutofillableLogins( 70abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey std::vector<autofill::PasswordForm*>* forms) OVERRIDE; 7194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood virtual bool FillBlacklistLogins( 7294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood std::vector<autofill::PasswordForm*>* forms) OVERRIDE; 73abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey 74abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey // Adds the given form to the Keychain if it's something we want to store 7594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood // there (i.e., not a blacklist entry). Returns true if the operation 7694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood // succeeded (either we added successfully, or we didn't need to). 7794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood bool AddToKeychainIfNecessary(const autofill::PasswordForm& form); 7894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 7994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood // Returns true if our database contains a form that exactly matches the given 8094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood // keychain form. 81abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey bool DatabaseHasFormMatchingKeychainForm( 8294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood const autofill::PasswordForm& form); 8394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 8494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood // Returns all the Keychain entries that we own but no longer have 8594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood // corresponding metadata for in our database. 86abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey // Caller is responsible for deleting the forms. 87abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey std::vector<autofill::PasswordForm*> GetUnusedKeychainForms(); 88abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey 8994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood // Removes the given forms from the database. 9094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood void RemoveDatabaseForms( 9194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood const std::vector<autofill::PasswordForm*>& forms); 9294afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 9394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood // Removes the given forms from the Keychain. 9494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood void RemoveKeychainForms( 9594afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood const std::vector<autofill::PasswordForm*>& forms); 9694afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 9794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood scoped_ptr<crypto::AppleKeychain> keychain_; 9894afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood scoped_ptr<password_manager::LoginDatabase> login_metadata_db_; 9994afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood 10094afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood // Thread that the synchronous methods are run on. 10194afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood scoped_ptr<base::Thread> thread_; 102abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey 10394afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood DISALLOW_COPY_AND_ASSIGN(PasswordStoreMac); 10494afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood}; 105abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey 106abe4fe5b46157ecd2a52d28abf938c816c3ce878Jeff Sharkey#endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_ 10794afecf4b6f437b3ee9a076242402e421c6c07a6Mike Lockwood