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 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "components/password_manager/core/browser/password_store_change.h" | |
| 14 #include "components/password_manager/core/browser/psl_matching_helper.h" | 15 #include "components/password_manager/core/browser/psl_matching_helper.h" |
| 15 #include "sql/connection.h" | 16 #include "sql/connection.h" |
| 16 #include "sql/meta_table.h" | 17 #include "sql/meta_table.h" |
| 17 | 18 |
| 18 namespace autofill { | |
| 19 struct PasswordForm; | |
| 20 } // namespace autofill | |
| 21 | |
| 22 namespace password_manager { | 19 namespace password_manager { |
| 23 | 20 |
| 24 // Interface to the database storage of login information, intended as a helper | 21 // Interface to the database storage of login information, intended as a helper |
| 25 // for PasswordStore on platforms that need internal storage of some or all of | 22 // for PasswordStore on platforms that need internal storage of some or all of |
| 26 // the login information. | 23 // the login information. |
| 27 class LoginDatabase { | 24 class LoginDatabase { |
| 28 public: | 25 public: |
| 29 LoginDatabase(); | 26 LoginDatabase(); |
| 30 virtual ~LoginDatabase(); | 27 virtual ~LoginDatabase(); |
| 31 | 28 |
| 32 // Initialize the database with an sqlite file at the given path. | 29 // Initialize the database with an sqlite file at the given path. |
| 33 // If false is returned, no other method should be called. | 30 // If false is returned, no other method should be called. |
| 34 bool Init(const base::FilePath& db_path); | 31 bool Init(const base::FilePath& db_path); |
| 35 | 32 |
| 36 // Reports usage metrics to UMA. | 33 // Reports usage metrics to UMA. |
| 37 void ReportMetrics(); | 34 void ReportMetrics(); |
| 38 | 35 |
| 39 // Adds |form| to the list of remembered password forms. | 36 // Adds |form| to the list of remembered password forms. Returns the list of |
| 40 bool AddLogin(const autofill::PasswordForm& form); | 37 // changes applied ({}, {ADD}, {REMOVE, ADD}). If it returns {REMOVE, ADD} |
| 38 // then the REMOVE is associated with the form that was added. Thus only the | |
| 39 // primary key columns contain the values associated with the removed form. | |
| 40 PasswordStoreChangeList AddLogin(const autofill::PasswordForm& form); | |
| 41 | 41 |
| 42 // Updates remembered password form. Returns true on success and sets | 42 // Updates remembered password form. Returns true on success and sets |
| 43 // items_changed (if non-NULL) to the number of logins updated. | 43 // items_changed (if non-NULL) to the number of logins updated. |
| 44 bool UpdateLogin(const autofill::PasswordForm& form, int* items_changed); | 44 bool UpdateLogin(const autofill::PasswordForm& form, int* items_changed); |
| 45 | 45 |
| 46 // Removes |form| from the list of remembered password forms. | 46 // Removes |form| from the list of remembered password forms. |
| 47 bool RemoveLogin(const autofill::PasswordForm& form); | 47 bool RemoveLogin(const autofill::PasswordForm& form); |
| 48 | 48 |
| 49 // Removes all logins created from |delete_begin| onwards (inclusive) and | 49 // Removes all logins created from |delete_begin| onwards (inclusive) and |
| 50 // before |delete_end|. You may use a null Time value to do an unbounded | 50 // before |delete_end|. You may use a null Time value to do an unbounded |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 75 bool GetBlacklistLogins( | 75 bool GetBlacklistLogins( |
| 76 std::vector<autofill::PasswordForm*>* forms) const; | 76 std::vector<autofill::PasswordForm*>* forms) const; |
| 77 | 77 |
| 78 // Deletes the login database file on disk, and creates a new, empty database. | 78 // Deletes the login database file on disk, and creates a new, empty database. |
| 79 // This can be used after migrating passwords to some other store, to ensure | 79 // This can be used after migrating passwords to some other store, to ensure |
| 80 // that SQLite doesn't leave fragments of passwords in the database file. | 80 // that SQLite doesn't leave fragments of passwords in the database file. |
| 81 // Returns true on success; otherwise, whether the file was deleted and | 81 // Returns true on success; otherwise, whether the file was deleted and |
| 82 // whether further use of this login database will succeed is unspecified. | 82 // whether further use of this login database will succeed is unspecified. |
| 83 bool DeleteAndRecreateDatabaseFile(); | 83 bool DeleteAndRecreateDatabaseFile(); |
| 84 | 84 |
| 85 // Serialization routines for vectors. | |
|
Garrett Casto
2014/05/14 18:34:48
These routines really shouldn't be externally visi
vasilii
2014/05/15 08:36:52
Done.
| |
| 86 static Pickle SerializeVector(const std::vector<base::string16>& vec); | |
| 87 static std::vector<base::string16> DeserializeVector(const Pickle& pickle); | |
| 88 | |
| 85 private: | 89 private: |
| 86 friend class LoginDatabaseTest; | |
| 87 | |
| 88 // Result values for encryption/decryption actions. | 90 // Result values for encryption/decryption actions. |
| 89 enum EncryptionResult { | 91 enum EncryptionResult { |
| 90 // Success. | 92 // Success. |
| 91 ENCRYPTION_RESULT_SUCCESS, | 93 ENCRYPTION_RESULT_SUCCESS, |
| 92 // Failure for a specific item (e.g., the encrypted value was manually | 94 // Failure for a specific item (e.g., the encrypted value was manually |
| 93 // moved from another machine, and can't be decrypted on this machine). | 95 // moved from another machine, and can't be decrypted on this machine). |
| 94 // This is presumed to be a permanent failure. | 96 // This is presumed to be a permanent failure. |
| 95 ENCRYPTION_RESULT_ITEM_FAILURE, | 97 ENCRYPTION_RESULT_ITEM_FAILURE, |
| 96 // A service-level failure (e.g., on a platform using a keyring, the keyring | 98 // A service-level failure (e.g., on a platform using a keyring, the keyring |
| 97 // is temporarily unavailable). | 99 // is temporarily unavailable). |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 121 // Returns the EncryptionResult from decrypting the password in |s|; if not | 123 // Returns the EncryptionResult from decrypting the password in |s|; if not |
| 122 // ENCRYPTION_RESULT_SUCCESS, |form| is not filled. | 124 // ENCRYPTION_RESULT_SUCCESS, |form| is not filled. |
| 123 EncryptionResult InitPasswordFormFromStatement(autofill::PasswordForm* form, | 125 EncryptionResult InitPasswordFormFromStatement(autofill::PasswordForm* form, |
| 124 sql::Statement& s) const; | 126 sql::Statement& s) const; |
| 125 | 127 |
| 126 // Loads all logins whose blacklist setting matches |blacklisted| into | 128 // Loads all logins whose blacklist setting matches |blacklisted| into |
| 127 // |forms|. | 129 // |forms|. |
| 128 bool GetAllLoginsWithBlacklistSetting( | 130 bool GetAllLoginsWithBlacklistSetting( |
| 129 bool blacklisted, std::vector<autofill::PasswordForm*>* forms) const; | 131 bool blacklisted, std::vector<autofill::PasswordForm*>* forms) const; |
| 130 | 132 |
| 131 // Serialization routines for vectors. | |
| 132 Pickle SerializeVector(const std::vector<base::string16>& vec) const; | |
| 133 std::vector<base::string16> DeserializeVector(const Pickle& pickle) const; | |
| 134 | |
| 135 base::FilePath db_path_; | 133 base::FilePath db_path_; |
| 136 mutable sql::Connection db_; | 134 mutable sql::Connection db_; |
| 137 sql::MetaTable meta_table_; | 135 sql::MetaTable meta_table_; |
| 138 | 136 |
| 139 PSLMatchingHelper psl_helper_; | 137 PSLMatchingHelper psl_helper_; |
| 140 | 138 |
| 141 DISALLOW_COPY_AND_ASSIGN(LoginDatabase); | 139 DISALLOW_COPY_AND_ASSIGN(LoginDatabase); |
| 142 }; | 140 }; |
| 143 | 141 |
| 144 } // namespace password_manager | 142 } // namespace password_manager |
| 145 | 143 |
| 146 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_DATABASE_H_ | 144 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_DATABASE_H_ |
| OLD | NEW |