Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / password_manager / password_store_mac.h
blob60a7a6c4e8f6c0be139459ea41abc5617599d0a9
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_
8 #include <vector>
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"
17 namespace crypto {
18 class AppleKeychain;
21 namespace password_manager {
22 class LoginDatabase;
25 // Implements PasswordStore on top of the OS X Keychain, with an internal
26 // database for extra metadata. For an overview of the interactions with the
27 // Keychain, as well as the rationale for some of the behaviors, see the
28 // Keychain integration design doc:
29 // http://dev.chromium.org/developers/design-documents/os-x-password-manager-keychain-integration
30 class PasswordStoreMac : public password_manager::PasswordStore {
31 public:
32 // The |login_db| must not have been Init()-ed yet. It will be initialized in
33 // a deferred manner on the background thread.
34 PasswordStoreMac(
35 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner,
36 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner,
37 scoped_ptr<crypto::AppleKeychain> keychain,
38 scoped_ptr<password_manager::LoginDatabase> login_db);
40 // Initializes |thread_|.
41 bool Init(const syncer::SyncableService::StartSyncFlare& flare) override;
43 // Stops |thread_|.
44 void Shutdown() override;
46 // To be used for testing.
47 password_manager::LoginDatabase* login_metadata_db() const {
48 return login_metadata_db_.get();
51 // To be used for testing.
52 crypto::AppleKeychain* keychain() const { return keychain_.get(); }
54 protected:
55 ~PasswordStoreMac() override;
57 // Opens |login_metadata_db_| on the background |thread_|.
58 void InitOnBackgroundThread();
60 scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner()
61 override;
63 private:
64 void ReportMetricsImpl(const std::string& sync_username,
65 bool custom_passphrase_sync_enabled) override;
66 password_manager::PasswordStoreChangeList AddLoginImpl(
67 const autofill::PasswordForm& form) override;
68 password_manager::PasswordStoreChangeList UpdateLoginImpl(
69 const autofill::PasswordForm& form) override;
70 password_manager::PasswordStoreChangeList RemoveLoginImpl(
71 const autofill::PasswordForm& form) override;
72 password_manager::PasswordStoreChangeList RemoveLoginsCreatedBetweenImpl(
73 base::Time delete_begin,
74 base::Time delete_end) override;
75 password_manager::PasswordStoreChangeList RemoveLoginsSyncedBetweenImpl(
76 base::Time delete_begin,
77 base::Time delete_end) override;
78 ScopedVector<autofill::PasswordForm> FillMatchingLogins(
79 const autofill::PasswordForm& form,
80 AuthorizationPromptPolicy prompt_policy) override;
81 void GetAutofillableLoginsImpl(
82 scoped_ptr<PasswordStore::GetLoginsRequest> request) override;
83 void GetBlacklistLoginsImpl(
84 scoped_ptr<PasswordStore::GetLoginsRequest> request) override;
85 bool FillAutofillableLogins(
86 ScopedVector<autofill::PasswordForm>* forms) override;
87 bool FillBlacklistLogins(
88 ScopedVector<autofill::PasswordForm>* forms) override;
90 // Adds the given form to the Keychain if it's something we want to store
91 // there (i.e., not a blacklist entry). Returns true if the operation
92 // succeeded (either we added successfully, or we didn't need to).
93 bool AddToKeychainIfNecessary(const autofill::PasswordForm& form);
95 // Returns true if our database contains a form that exactly matches the given
96 // keychain form.
97 bool DatabaseHasFormMatchingKeychainForm(
98 const autofill::PasswordForm& form);
100 // Removes the given forms from the database. After the call |forms| contains
101 // only those forms which were successfully removed.
102 void RemoveDatabaseForms(ScopedVector<autofill::PasswordForm>* forms);
104 // Removes the given forms from the Keychain.
105 void RemoveKeychainForms(
106 const std::vector<autofill::PasswordForm*>& forms);
108 // Searches the database for forms without a corresponding entry in the
109 // keychain. Removes those forms from the database, and adds them to
110 // |orphaned_forms|.
111 void CleanOrphanedForms(ScopedVector<autofill::PasswordForm>* orphaned_forms);
113 scoped_ptr<crypto::AppleKeychain> keychain_;
115 // The login metadata SQL database. The LoginDatabase instance is received via
116 // the in an uninitialized state, so as to allow injecting mocks, then Init()
117 // is called on the DB thread in a deferred manner. If opening the DB fails,
118 // |login_metadata_db_| will be reset to NULL for the lifetime of |this|.
119 scoped_ptr<password_manager::LoginDatabase> login_metadata_db_;
121 // Thread that the synchronous methods are run on.
122 scoped_ptr<base::Thread> thread_;
124 DISALLOW_COPY_AND_ASSIGN(PasswordStoreMac);
127 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_