Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: components/password_manager/core/browser/login_database.h

Issue 2126713006: Refactor LoginDatabase migration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments addressed Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 #include "components/password_manager/core/browser/statistics_table.h" 21 #include "components/password_manager/core/browser/statistics_table.h"
22 #include "sql/connection.h" 22 #include "sql/connection.h"
23 #include "sql/meta_table.h" 23 #include "sql/meta_table.h"
24 24
25 #if defined(OS_IOS) 25 #if defined(OS_IOS)
26 #include "base/gtest_prod_util.h" 26 #include "base/gtest_prod_util.h"
27 #endif 27 #endif
28 28
29 namespace password_manager { 29 namespace password_manager {
30 30
31 class SQLTableBuilder;
32
31 extern const int kCurrentVersionNumber; 33 extern const int kCurrentVersionNumber;
32 extern const int kCompatibleVersionNumber; 34 extern const int kCompatibleVersionNumber;
33 35
34 // Interface to the database storage of login information, intended as a helper 36 // Interface to the database storage of login information, intended as a helper
35 // for PasswordStore on platforms that need internal storage of some or all of 37 // for PasswordStore on platforms that need internal storage of some or all of
36 // the login information. 38 // the login information.
37 class LoginDatabase { 39 class LoginDatabase {
38 public: 40 public:
39 explicit LoginDatabase(const base::FilePath& db_path); 41 explicit LoginDatabase(const base::FilePath& db_path);
40 virtual ~LoginDatabase(); 42 virtual ~LoginDatabase();
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 static EncryptionResult EncryptedString(const base::string16& plain_text, 165 static EncryptionResult EncryptedString(const base::string16& plain_text,
164 std::string* cipher_text); 166 std::string* cipher_text);
165 167
166 // Decrypts cipher_text, setting the value of plain_text and returning true if 168 // Decrypts cipher_text, setting the value of plain_text and returning true if
167 // successful, or returning false and leaving plain_text unchanged if 169 // successful, or returning false and leaving plain_text unchanged if
168 // decryption fails (e.g., if the underlying OS encryption system is 170 // decryption fails (e.g., if the underlying OS encryption system is
169 // temporarily unavailable). 171 // temporarily unavailable).
170 static EncryptionResult DecryptedString(const std::string& cipher_text, 172 static EncryptionResult DecryptedString(const std::string& cipher_text,
171 base::string16* plain_text); 173 base::string16* plain_text);
172 174
173 bool InitLoginsTable();
174 bool MigrateOldVersionsAsNeeded();
175
176 // Fills |form| from the values in the given statement (which is assumed to 175 // Fills |form| from the values in the given statement (which is assumed to
177 // be of the form used by the Get*Logins methods). 176 // be of the form used by the Get*Logins methods).
178 // Returns the EncryptionResult from decrypting the password in |s|; if not 177 // Returns the EncryptionResult from decrypting the password in |s|; if not
179 // ENCRYPTION_RESULT_SUCCESS, |form| is not filled. 178 // ENCRYPTION_RESULT_SUCCESS, |form| is not filled.
180 static EncryptionResult InitPasswordFormFromStatement( 179 static EncryptionResult InitPasswordFormFromStatement(
181 autofill::PasswordForm* form, 180 autofill::PasswordForm* form,
182 const sql::Statement& s); 181 const sql::Statement& s);
183 182
184 // Gets all blacklisted or all non-blacklisted (depending on |blacklisted|) 183 // Gets all blacklisted or all non-blacklisted (depending on |blacklisted|)
185 // credentials. On success returns true and overwrites |forms| with the 184 // credentials. On success returns true and overwrites |forms| with the
186 // result. 185 // result.
187 bool GetAllLoginsWithBlacklistSetting( 186 bool GetAllLoginsWithBlacklistSetting(
188 bool blacklisted, 187 bool blacklisted,
189 ScopedVector<autofill::PasswordForm>* forms) const; 188 ScopedVector<autofill::PasswordForm>* forms) const;
190 189
191 // Overwrites |forms| with credentials retrieved from |statement|. If 190 // Overwrites |forms| with credentials retrieved from |statement|. If
192 // |matched_form| is not null, filters out all results but those PSL-matching 191 // |matched_form| is not null, filters out all results but those PSL-matching
193 // |*matched_form| or federated credentials for it. On success returns true. 192 // |*matched_form| or federated credentials for it. On success returns true.
194 static bool StatementToForms(sql::Statement* statement, 193 static bool StatementToForms(sql::Statement* statement,
195 const autofill::PasswordForm* matched_form, 194 const autofill::PasswordForm* matched_form,
196 ScopedVector<autofill::PasswordForm>* forms); 195 ScopedVector<autofill::PasswordForm>* forms);
197 196
197 // Initializes all the *_statement_ data members with appropriate SQL
198 // fragments based on |builder|.
199 void InitializeStatementStrings(const SQLTableBuilder& builder);
200
198 base::FilePath db_path_; 201 base::FilePath db_path_;
199 mutable sql::Connection db_; 202 mutable sql::Connection db_;
200 sql::MetaTable meta_table_; 203 sql::MetaTable meta_table_;
201 StatisticsTable stats_table_; 204 StatisticsTable stats_table_;
202 205
203 // If set to 'true', then the password values are cleared before encrypting 206 // If set to 'true', then the password values are cleared before encrypting
204 // and storing in the database. At the same time AddLogin/UpdateLogin return 207 // and storing in the database. At the same time AddLogin/UpdateLogin return
205 // PasswordStoreChangeList containing the real password. 208 // PasswordStoreChangeList containing the real password.
206 // This is a temporary measure for migration the Keychain on Mac. 209 // This is a temporary measure for migration the Keychain on Mac.
207 // crbug.com/466638 210 // crbug.com/466638
208 bool clear_password_values_; 211 bool clear_password_values_;
209 212
213 // These cached strings are used to build SQL statements.
214 std::string add_statement_;
215 std::string add_replace_statement_;
216 std::string update_statement_;
217 std::string delete_statement_;
218 std::string autosignin_statement_;
219 std::string get_statement_;
220 std::string get_statement_psl_;
221 std::string get_statement_federated_;
222 std::string get_statement_psl_federated_;
223 std::string created_statement_;
224 std::string synced_statement_;
225 std::string blacklisted_statement_;
226 std::string encrypted_statement_;
227
210 DISALLOW_COPY_AND_ASSIGN(LoginDatabase); 228 DISALLOW_COPY_AND_ASSIGN(LoginDatabase);
211 }; 229 };
212 230
213 } // namespace password_manager 231 } // namespace password_manager
214 232
215 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_DATABASE_H_ 233 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_LOGIN_DATABASE_H_
OLDNEW
« no previous file with comments | « components/password_manager/core/browser/BUILD.gn ('k') | components/password_manager/core/browser/login_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698