Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_DATABASE_H_ | 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_DATABASE_H_ |
| 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_DATABASE_H_ | 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_DATABASE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 // delete in either direction. | 62 // delete in either direction. |
| 63 bool RemoveLoginsCreatedBetween(base::Time delete_begin, | 63 bool RemoveLoginsCreatedBetween(base::Time delete_begin, |
| 64 base::Time delete_end); | 64 base::Time delete_end); |
| 65 | 65 |
| 66 // Removes all logins synced from |delete_begin| onwards (inclusive) and | 66 // Removes all logins synced from |delete_begin| onwards (inclusive) and |
| 67 // before |delete_end|. You may use a null Time value to do an unbounded | 67 // before |delete_end|. You may use a null Time value to do an unbounded |
| 68 // delete in either direction. | 68 // delete in either direction. |
| 69 bool RemoveLoginsSyncedBetween(base::Time delete_begin, | 69 bool RemoveLoginsSyncedBetween(base::Time delete_begin, |
| 70 base::Time delete_end); | 70 base::Time delete_end); |
| 71 | 71 |
| 72 // Loads a list of matching password forms into the specified vector |forms|. | 72 // All Get* methods below overwrite |forms| with the returned credentials. On |
| 73 // The list will contain all possibly relevant entries to the observed |form|, | 73 // success, those methods return true, on failure they return false and clear |
| 74 // including blacklisted matches. | 74 // |forms|. |
| 75 | |
| 76 // Get a list of credentials matching |form|, including blacklisted matches. | |
| 75 bool GetLogins(const autofill::PasswordForm& form, | 77 bool GetLogins(const autofill::PasswordForm& form, |
| 76 ScopedVector<autofill::PasswordForm>* forms) const; | 78 ScopedVector<autofill::PasswordForm>* forms) const; |
| 77 | 79 |
| 78 // Loads all logins created from |begin| onwards (inclusive) and before |end|. | 80 // Get all logins created from |begin| onwards (inclusive) and before |end|. |
|
engedy
2015/02/25 15:17:48
Nit: 'Gets' or 'Retrieves'. (4 occurrences)
vabr (Chromium)
2015/03/09 10:56:19
Done.
| |
| 79 // You may use a null Time value to do an unbounded search in either | 81 // You may use a null Time value to do an unbounded search in either |
| 80 // direction. | 82 // direction. |
| 81 bool GetLoginsCreatedBetween( | 83 bool GetLoginsCreatedBetween( |
| 82 base::Time begin, | 84 base::Time begin, |
| 83 base::Time end, | 85 base::Time end, |
| 84 ScopedVector<autofill::PasswordForm>* forms) const; | 86 ScopedVector<autofill::PasswordForm>* forms) const; |
| 85 | 87 |
| 86 // Loads all logins synced from |begin| onwards (inclusive) and before |end|. | 88 // Get all logins synced from |begin| onwards (inclusive) and before |end|. |
| 87 // You may use a null Time value to do an unbounded search in either | 89 // You may use a null Time value to do an unbounded search in either |
| 88 // direction. | 90 // direction. |
| 89 bool GetLoginsSyncedBetween( | 91 bool GetLoginsSyncedBetween( |
| 90 base::Time begin, | 92 base::Time begin, |
| 91 base::Time end, | 93 base::Time end, |
| 92 ScopedVector<autofill::PasswordForm>* forms) const; | 94 ScopedVector<autofill::PasswordForm>* forms) const; |
| 93 | 95 |
| 94 // Loads the complete list of autofillable password forms (i.e., not blacklist | 96 // Get the complete list of not blacklisted credentials. |
| 95 // entries) into |forms|. | |
| 96 bool GetAutofillableLogins(ScopedVector<autofill::PasswordForm>* forms) const; | 97 bool GetAutofillableLogins(ScopedVector<autofill::PasswordForm>* forms) const; |
| 97 | 98 |
| 98 // Loads the complete list of blacklist forms into |forms|. | 99 // Get the complete list of blacklisted credentials. |
| 99 bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms) const; | 100 bool GetBlacklistLogins(ScopedVector<autofill::PasswordForm>* forms) const; |
| 100 | 101 |
| 101 // Deletes the login database file on disk, and creates a new, empty database. | 102 // Deletes the login database file on disk, and creates a new, empty database. |
| 102 // This can be used after migrating passwords to some other store, to ensure | 103 // This can be used after migrating passwords to some other store, to ensure |
| 103 // that SQLite doesn't leave fragments of passwords in the database file. | 104 // that SQLite doesn't leave fragments of passwords in the database file. |
| 104 // Returns true on success; otherwise, whether the file was deleted and | 105 // Returns true on success; otherwise, whether the file was deleted and |
| 105 // whether further use of this login database will succeed is unspecified. | 106 // whether further use of this login database will succeed is unspecified. |
| 106 bool DeleteAndRecreateDatabaseFile(); | 107 bool DeleteAndRecreateDatabaseFile(); |
| 107 | 108 |
| 108 private: | 109 private: |
| 109 // Result values for encryption/decryption actions. | 110 // Result values for encryption/decryption actions. |
| 110 enum EncryptionResult { | 111 enum EncryptionResult { |
| 111 // Success. | 112 // Success. |
| 112 ENCRYPTION_RESULT_SUCCESS, | 113 ENCRYPTION_RESULT_SUCCESS, |
| 113 // Failure for a specific item (e.g., the encrypted value was manually | 114 // Failure for a specific item (e.g., the encrypted value was manually |
| 114 // moved from another machine, and can't be decrypted on this machine). | 115 // moved from another machine, and can't be decrypted on this machine). |
| 115 // This is presumed to be a permanent failure. | 116 // This is presumed to be a permanent failure. |
| 116 ENCRYPTION_RESULT_ITEM_FAILURE, | 117 ENCRYPTION_RESULT_ITEM_FAILURE, |
| 117 // A service-level failure (e.g., on a platform using a keyring, the keyring | 118 // A service-level failure (e.g., on a platform using a keyring, the keyring |
| 118 // is temporarily unavailable). | 119 // is temporarily unavailable). |
| 119 // This is presumed to be a temporary failure. | 120 // This is presumed to be a temporary failure. |
| 120 ENCRYPTION_RESULT_SERVICE_FAILURE, | 121 ENCRYPTION_RESULT_SERVICE_FAILURE, |
| 121 }; | 122 }; |
| 122 | 123 |
| 123 // Encrypts plain_text, setting the value of cipher_text and returning true if | 124 // Encrypts plain_text, setting the value of cipher_text and returning true if |
| 124 // successful, or returning false and leaving cipher_text unchanged if | 125 // successful, or returning false and leaving cipher_text unchanged if |
| 125 // encryption fails (e.g., if the underlying OS encryption system is | 126 // encryption fails (e.g., if the underlying OS encryption system is |
| 126 // temporarily unavailable). | 127 // temporarily unavailable). |
| 127 EncryptionResult EncryptedString(const base::string16& plain_text, | 128 static EncryptionResult EncryptedString(const base::string16& plain_text, |
| 128 std::string* cipher_text) const; | 129 std::string* cipher_text); |
| 129 | 130 |
| 130 // Decrypts cipher_text, setting the value of plain_text and returning true if | 131 // Decrypts cipher_text, setting the value of plain_text and returning true if |
| 131 // successful, or returning false and leaving plain_text unchanged if | 132 // successful, or returning false and leaving plain_text unchanged if |
| 132 // decryption fails (e.g., if the underlying OS encryption system is | 133 // decryption fails (e.g., if the underlying OS encryption system is |
| 133 // temporarily unavailable). | 134 // temporarily unavailable). |
| 134 EncryptionResult DecryptedString(const std::string& cipher_text, | 135 static EncryptionResult DecryptedString(const std::string& cipher_text, |
| 135 base::string16* plain_text) const; | 136 base::string16* plain_text); |
| 136 | 137 |
| 137 bool InitLoginsTable(); | 138 bool InitLoginsTable(); |
| 138 bool MigrateOldVersionsAsNeeded(); | 139 bool MigrateOldVersionsAsNeeded(); |
| 139 | 140 |
| 140 // Fills |form| from the values in the given statement (which is assumed to | 141 // Fills |form| from the values in the given statement (which is assumed to |
| 141 // be of the form used by the Get*Logins methods). | 142 // be of the form used by the Get*Logins methods). |
| 142 // Returns the EncryptionResult from decrypting the password in |s|; if not | 143 // Returns the EncryptionResult from decrypting the password in |s|; if not |
| 143 // ENCRYPTION_RESULT_SUCCESS, |form| is not filled. | 144 // ENCRYPTION_RESULT_SUCCESS, |form| is not filled. |
| 144 EncryptionResult InitPasswordFormFromStatement(autofill::PasswordForm* form, | 145 static EncryptionResult InitPasswordFormFromStatement( |
| 145 sql::Statement& s) const; | 146 autofill::PasswordForm* form, |
| 147 sql::Statement& s); | |
| 146 | 148 |
| 147 // Loads all logins whose blacklist setting matches |blacklisted| into | 149 // Gets all blacklisted or all non-blacklisted (depending on |blacklisted|) |
| 148 // |forms|. | 150 // credentials. On success returns true and overwrites |forms| with the |
| 151 // result, otherwise returns false and clears |forms|. | |
| 149 bool GetAllLoginsWithBlacklistSetting( | 152 bool GetAllLoginsWithBlacklistSetting( |
| 150 bool blacklisted, | 153 bool blacklisted, |
| 151 ScopedVector<autofill::PasswordForm>* forms) const; | 154 ScopedVector<autofill::PasswordForm>* forms) const; |
| 152 | 155 |
| 156 // Overwrites |forms| with credentials retrieved from |statement|. If | |
| 157 // |psl_match| is not null, filters out all results but thos PSL-matching | |
| 158 // |*psl_match|. On success returns true, otherwise clears |forms| and returns | |
| 159 // false. | |
| 160 static bool StatementToForms(sql::Statement* statement, | |
| 161 const autofill::PasswordForm* psl_match, | |
| 162 ScopedVector<autofill::PasswordForm>* forms); | |
| 163 | |
| 153 base::FilePath db_path_; | 164 base::FilePath db_path_; |
| 154 mutable sql::Connection db_; | 165 mutable sql::Connection db_; |
| 155 sql::MetaTable meta_table_; | 166 sql::MetaTable meta_table_; |
| 156 | 167 |
| 157 DISALLOW_COPY_AND_ASSIGN(LoginDatabase); | 168 DISALLOW_COPY_AND_ASSIGN(LoginDatabase); |
| 158 }; | 169 }; |
| 159 | 170 |
| 160 } // namespace password_manager | 171 } // namespace password_manager |
| 161 | 172 |
| 162 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_DATABASE_H_ | 173 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_DATABASE_H_ |
| OLD | NEW |