OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_ | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_ |
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_ | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 class LoginDatabase; | 21 class LoginDatabase; |
22 } | 22 } |
23 | 23 |
24 // Implements PasswordStore on top of the OS X Keychain, with an internal | 24 // Implements PasswordStore on top of the OS X Keychain, with an internal |
25 // database for extra metadata. For an overview of the interactions with the | 25 // database for extra metadata. For an overview of the interactions with the |
26 // Keychain, as well as the rationale for some of the behaviors, see the | 26 // Keychain, as well as the rationale for some of the behaviors, see the |
27 // Keychain integration design doc: | 27 // Keychain integration design doc: |
28 // http://dev.chromium.org/developers/design-documents/os-x-password-manager-key
chain-integration | 28 // http://dev.chromium.org/developers/design-documents/os-x-password-manager-key
chain-integration |
29 class PasswordStoreMac : public password_manager::PasswordStore { | 29 class PasswordStoreMac : public password_manager::PasswordStore { |
30 public: | 30 public: |
31 // Takes ownership of |keychain| and |login_db|, both of which must be | 31 // The |login_db| must not have been Init()-ed yet. It will be initialized in |
32 // non-NULL. | 32 // a deferred manner on the background thread. |
33 PasswordStoreMac( | 33 PasswordStoreMac( |
34 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, | 34 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, |
35 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, | 35 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, |
36 crypto::AppleKeychain* keychain, | 36 scoped_ptr<crypto::AppleKeychain> keychain, |
37 password_manager::LoginDatabase* login_db); | 37 scoped_ptr<password_manager::LoginDatabase> login_db); |
38 | 38 |
39 // Initializes |thread_|. | 39 // Initializes |thread_|. |
40 bool Init(const syncer::SyncableService::StartSyncFlare& flare) override; | 40 bool Init(const syncer::SyncableService::StartSyncFlare& flare) override; |
41 | 41 |
42 // Stops |thread_|. | 42 // Stops |thread_|. |
43 void Shutdown() override; | 43 void Shutdown() override; |
44 | 44 |
| 45 // To be used for testing. |
| 46 password_manager::LoginDatabase* login_metadata_db() const { |
| 47 return login_metadata_db_.get(); |
| 48 } |
| 49 |
| 50 // To be used for testing. |
| 51 crypto::AppleKeychain* keychain() const { return keychain_.get(); } |
| 52 |
45 protected: | 53 protected: |
46 ~PasswordStoreMac() override; | 54 ~PasswordStoreMac() override; |
47 | 55 |
| 56 // Opens |login_metadata_db_| on the background |thread_|. |
| 57 void InitOnBackgroundThread(); |
| 58 |
48 scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner() | 59 scoped_refptr<base::SingleThreadTaskRunner> GetBackgroundTaskRunner() |
49 override; | 60 override; |
50 | 61 |
51 private: | 62 private: |
52 void ReportMetricsImpl(const std::string& sync_username, | 63 void ReportMetricsImpl(const std::string& sync_username, |
53 bool custom_passphrase_sync_enabled) override; | 64 bool custom_passphrase_sync_enabled) override; |
54 password_manager::PasswordStoreChangeList AddLoginImpl( | 65 password_manager::PasswordStoreChangeList AddLoginImpl( |
55 const autofill::PasswordForm& form) override; | 66 const autofill::PasswordForm& form) override; |
56 password_manager::PasswordStoreChangeList UpdateLoginImpl( | 67 password_manager::PasswordStoreChangeList UpdateLoginImpl( |
57 const autofill::PasswordForm& form) override; | 68 const autofill::PasswordForm& form) override; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // Removes the given forms from the Keychain. | 101 // Removes the given forms from the Keychain. |
91 void RemoveKeychainForms( | 102 void RemoveKeychainForms( |
92 const std::vector<autofill::PasswordForm*>& forms); | 103 const std::vector<autofill::PasswordForm*>& forms); |
93 | 104 |
94 // Searches the database for forms without a corresponding entry in the | 105 // Searches the database for forms without a corresponding entry in the |
95 // keychain. Removes those forms from the database, and returns them in | 106 // keychain. Removes those forms from the database, and returns them in |
96 // |forms|. Ownership of |forms| is passed to the caller. | 107 // |forms|. Ownership of |forms| is passed to the caller. |
97 void CleanOrphanedForms(std::vector<autofill::PasswordForm*>* forms); | 108 void CleanOrphanedForms(std::vector<autofill::PasswordForm*>* forms); |
98 | 109 |
99 scoped_ptr<crypto::AppleKeychain> keychain_; | 110 scoped_ptr<crypto::AppleKeychain> keychain_; |
| 111 |
| 112 // The login metadata SQL database. The LoginDatabase instance is received via |
| 113 // the in an uninitialized state, so as to allow injecting mocks, then Init() |
| 114 // is called on the DB thread in a deferred manner. If opening the DB fails, |
| 115 // |login_metadata_db_| will be reset to NULL for the lifetime of |this|. |
100 scoped_ptr<password_manager::LoginDatabase> login_metadata_db_; | 116 scoped_ptr<password_manager::LoginDatabase> login_metadata_db_; |
101 | 117 |
102 // Thread that the synchronous methods are run on. | 118 // Thread that the synchronous methods are run on. |
103 scoped_ptr<base::Thread> thread_; | 119 scoped_ptr<base::Thread> thread_; |
104 | 120 |
105 DISALLOW_COPY_AND_ASSIGN(PasswordStoreMac); | 121 DISALLOW_COPY_AND_ASSIGN(PasswordStoreMac); |
106 }; | 122 }; |
107 | 123 |
108 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_ | 124 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_H_ |
OLD | NEW |