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.
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_
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"
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
25 class PasswordStoreMac
: public PasswordStore
{
27 // Takes ownership of |keychain| and |login_db|, both of which must be
30 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_runner
,
31 scoped_refptr
<base::SingleThreadTaskRunner
> db_thread_runner
,
32 crypto::AppleKeychain
* keychain
,
33 LoginDatabase
* login_db
);
35 // Initializes |thread_|.
36 virtual bool Init() OVERRIDE
;
39 virtual ~PasswordStoreMac();
41 virtual scoped_refptr
<base::SingleThreadTaskRunner
>
42 GetBackgroundTaskRunner() OVERRIDE
;
45 virtual void ReportMetricsImpl() OVERRIDE
;
46 virtual PasswordStoreChangeList
AddLoginImpl(
47 const autofill::PasswordForm
& form
) OVERRIDE
;
48 virtual PasswordStoreChangeList
UpdateLoginImpl(
49 const autofill::PasswordForm
& form
) OVERRIDE
;
50 virtual PasswordStoreChangeList
RemoveLoginImpl(
51 const autofill::PasswordForm
& form
) OVERRIDE
;
52 virtual PasswordStoreChangeList
RemoveLoginsCreatedBetweenImpl(
53 const base::Time
& delete_begin
, const base::Time
& delete_end
) OVERRIDE
;
54 virtual void GetLoginsImpl(
55 const autofill::PasswordForm
& form
,
56 AuthorizationPromptPolicy prompt_policy
,
57 const ConsumerCallbackRunner
& callback_runner
) OVERRIDE
;
58 virtual void GetAutofillableLoginsImpl(GetLoginsRequest
* request
) OVERRIDE
;
59 virtual void GetBlacklistLoginsImpl(GetLoginsRequest
* request
) OVERRIDE
;
60 virtual bool FillAutofillableLogins(
61 std::vector
<autofill::PasswordForm
*>* forms
) OVERRIDE
;
62 virtual bool FillBlacklistLogins(
63 std::vector
<autofill::PasswordForm
*>* forms
) OVERRIDE
;
65 // Adds the given form to the Keychain if it's something we want to store
66 // there (i.e., not a blacklist entry). Returns true if the operation
67 // succeeded (either we added successfully, or we didn't need to).
68 bool AddToKeychainIfNecessary(const autofill::PasswordForm
& form
);
70 // Returns true if our database contains a form that exactly matches the given
72 bool DatabaseHasFormMatchingKeychainForm(
73 const autofill::PasswordForm
& form
);
75 // Returns all the Keychain entries that we own but no longer have
76 // corresponding metadata for in our database.
77 // Caller is responsible for deleting the forms.
78 std::vector
<autofill::PasswordForm
*> GetUnusedKeychainForms();
80 // Removes the given forms from the database.
81 void RemoveDatabaseForms(
82 const std::vector
<autofill::PasswordForm
*>& forms
);
84 // Removes the given forms from the Keychain.
85 void RemoveKeychainForms(
86 const std::vector
<autofill::PasswordForm
*>& forms
);
88 scoped_ptr
<crypto::AppleKeychain
> keychain_
;
89 scoped_ptr
<LoginDatabase
> login_metadata_db_
;
91 // Thread that the synchronous methods are run on.
92 scoped_ptr
<base::Thread
> thread_
;
94 DISALLOW_COPY_AND_ASSIGN(PasswordStoreMac
);
97 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_