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/memory/scoped_vector.h"
13 #include "base/threading/thread.h"
14 #include "components/password_manager/core/browser/login_database.h"
15 #include "components/password_manager/core/browser/password_store.h"
21 namespace password_manager
{
25 // TODO(vasilii): Deprecate this class. The class should be used by
26 // PasswordStoreProxyMac wrapper.
27 // Implements PasswordStore on top of the OS X Keychain, with an internal
28 // database for extra metadata. For an overview of the interactions with the
29 // Keychain, as well as the rationale for some of the behaviors, see the
30 // Keychain integration design doc:
31 // http://dev.chromium.org/developers/design-documents/os-x-password-manager-keychain-integration
32 class PasswordStoreMac
: public password_manager::PasswordStore
{
34 enum MigrationResult
{
43 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_runner
,
44 scoped_refptr
<base::SingleThreadTaskRunner
> db_thread_runner
,
45 scoped_ptr
<crypto::AppleKeychain
> keychain
);
47 // Sets the background thread.
48 void InitWithTaskRunner(
49 scoped_refptr
<base::SingleThreadTaskRunner
> background_task_runner
);
51 // Reads all the passwords from the Keychain and stores them in LoginDatabase.
52 // After the successful migration PasswordStoreMac should not be used. If the
53 // migration fails, PasswordStoreMac remains the active backend for
54 // PasswordStoreProxyMac.
55 MigrationResult
ImportFromKeychain();
57 // To be used for testing.
58 password_manager::LoginDatabase
* login_metadata_db() const {
59 return login_metadata_db_
;
62 void set_login_metadata_db(password_manager::LoginDatabase
* login_db
);
64 // To be used for testing.
65 crypto::AppleKeychain
* keychain() const { return keychain_
.get(); }
68 ~PasswordStoreMac() override
;
71 bool Init(const syncer::SyncableService::StartSyncFlare
& flare
) override
;
72 void ReportMetricsImpl(const std::string
& sync_username
,
73 bool custom_passphrase_sync_enabled
) override
;
74 password_manager::PasswordStoreChangeList
AddLoginImpl(
75 const autofill::PasswordForm
& form
) override
;
76 password_manager::PasswordStoreChangeList
UpdateLoginImpl(
77 const autofill::PasswordForm
& form
) override
;
78 password_manager::PasswordStoreChangeList
RemoveLoginImpl(
79 const autofill::PasswordForm
& form
) override
;
80 password_manager::PasswordStoreChangeList
RemoveLoginsCreatedBetweenImpl(
81 base::Time delete_begin
,
82 base::Time delete_end
) override
;
83 password_manager::PasswordStoreChangeList
RemoveLoginsSyncedBetweenImpl(
84 base::Time delete_begin
,
85 base::Time delete_end
) override
;
86 ScopedVector
<autofill::PasswordForm
> FillMatchingLogins(
87 const autofill::PasswordForm
& form
,
88 AuthorizationPromptPolicy prompt_policy
) override
;
89 bool FillAutofillableLogins(
90 ScopedVector
<autofill::PasswordForm
>* forms
) override
;
91 bool FillBlacklistLogins(
92 ScopedVector
<autofill::PasswordForm
>* forms
) override
;
93 void AddSiteStatsImpl(
94 const password_manager::InteractionsStats
& stats
) override
;
95 void RemoveSiteStatsImpl(const GURL
& origin_domain
) override
;
96 scoped_ptr
<password_manager::InteractionsStats
> GetSiteStatsImpl(
97 const GURL
& origin_domain
) override
;
99 // Adds the given form to the Keychain if it's something we want to store
100 // there (i.e., not a blacklist entry or a federated login). Returns true if
101 // the operation succeeded (either we added successfully, or we didn't need
103 bool AddToKeychainIfNecessary(const autofill::PasswordForm
& form
);
105 // Returns true if our database contains a form that exactly matches the given
107 bool DatabaseHasFormMatchingKeychainForm(
108 const autofill::PasswordForm
& form
);
110 // Removes the given forms from the database. After the call |forms| contains
111 // only those forms which were successfully removed.
112 void RemoveDatabaseForms(ScopedVector
<autofill::PasswordForm
>* forms
);
114 // Removes the given forms from the Keychain.
115 void RemoveKeychainForms(
116 const std::vector
<autofill::PasswordForm
*>& forms
);
118 // Searches the database for forms without a corresponding entry in the
119 // keychain. Removes those forms from the database, and adds them to
121 void CleanOrphanedForms(ScopedVector
<autofill::PasswordForm
>* orphaned_forms
);
123 scoped_ptr
<crypto::AppleKeychain
> keychain_
;
125 // The login metadata SQL database. The caller is resonsible for initializing
127 password_manager::LoginDatabase
* login_metadata_db_
;
129 DISALLOW_COPY_AND_ASSIGN(PasswordStoreMac
);
132 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_