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 #include "components/password_manager/core/browser/login_database.h" | 5 #include "components/password_manager/core/browser/login_database.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 case 6: | 250 case 6: |
251 if (!db_.Execute("ALTER TABLE logins ADD COLUMN display_name VARCHAR") || | 251 if (!db_.Execute("ALTER TABLE logins ADD COLUMN display_name VARCHAR") || |
252 !db_.Execute("ALTER TABLE logins ADD COLUMN avatar_url VARCHAR") || | 252 !db_.Execute("ALTER TABLE logins ADD COLUMN avatar_url VARCHAR") || |
253 !db_.Execute("ALTER TABLE logins " | 253 !db_.Execute("ALTER TABLE logins " |
254 "ADD COLUMN federation_url VARCHAR") || | 254 "ADD COLUMN federation_url VARCHAR") || |
255 !db_.Execute("ALTER TABLE logins ADD COLUMN is_zero_click INTEGER")) { | 255 !db_.Execute("ALTER TABLE logins ADD COLUMN is_zero_click INTEGER")) { |
256 return false; | 256 return false; |
257 } | 257 } |
258 meta_table_.SetVersionNumber(7); | 258 meta_table_.SetVersionNumber(7); |
259 // Fall through. | 259 // Fall through. |
260 case 7: | 260 case 7: { |
261 // Keep version 8 around even though no changes are made. See | 261 // Remove use_additional_auth column from database schema |
Garrett Casto
2015/01/06 21:48:16
This shouldn't be here, you need to increment the
melandory
2015/01/13 12:51:15
Done.
| |
262 // crbug.com/423716 for context. | 262 // crbug.com/423716 for context. |
263 std::string fields_to_copy = | |
264 "origin_url, action_url, username_element, username_value, " | |
265 "password_element, password_value, submit_element, " | |
266 "signon_realm, ssl_valid, preferred, date_created, " | |
267 "blacklisted_by_user, " | |
268 "scheme, password_type, possible_usernames, times_used, form_data, " | |
269 "date_synced, display_name, avatar_url," | |
270 "federation_url, is_zero_click"; | |
271 auto copy_data_from_to_query = | |
Garrett Casto
2015/01/06 21:48:16
I would just call this "copy_data_query". I can se
melandory
2015/01/13 12:51:15
Done.
| |
272 [&fields_to_copy](std::string from, std::string to) { | |
273 return ("INSERT INTO " + to + " SELECT " + fields_to_copy + " FROM " + | |
274 from).c_str(); | |
275 }; | |
Garrett Casto
2015/01/06 21:48:16
Nit: Whitespace here.
melandory
2015/01/13 12:51:15
Done.
| |
276 if (!db_.Execute(("CREATE TEMPORARY TABLE logins_data(" + fields_to_copy + | |
277 ")").c_str()) || | |
278 !db_.Execute( | |
279 copy_data_from_to_query("logins", "logins_data")) || | |
280 !db_.Execute("DROP TABLE logins") || | |
281 !db_.Execute( | |
282 ("CREATE TABLE logins(" + fields_to_copy + ")").c_str()) || | |
283 !db_.Execute( | |
284 copy_data_from_to_query("logins_data", "logins")) || | |
285 !db_.Execute("DROP TABLE logins_data")) | |
Garrett Casto
2015/01/06 21:48:16
You need to recreate the index on logins as well.
| |
286 return false; | |
263 meta_table_.SetVersionNumber(8); | 287 meta_table_.SetVersionNumber(8); |
264 // Fall through. | 288 // Fall through. |
265 // TODO(gcasto): Remove use_additional_auth by copying table. | 289 } |
266 // https://www.sqlite.org/lang_altertable.html | |
267 case 8: { | 290 case 8: { |
268 sql::Statement s; | 291 sql::Statement s; |
269 s.Assign(db_.GetCachedStatement(SQL_FROM_HERE, | 292 s.Assign(db_.GetCachedStatement(SQL_FROM_HERE, |
270 "UPDATE logins SET " | 293 "UPDATE logins SET " |
271 "date_created = " | 294 "date_created = " |
272 "(date_created * ?) + ?")); | 295 "(date_created * ?) + ?")); |
273 s.BindInt64(0, base::Time::kMicrosecondsPerSecond); | 296 s.BindInt64(0, base::Time::kMicrosecondsPerSecond); |
274 s.BindInt64(1, base::Time::kTimeTToMicrosecondsOffset); | 297 s.BindInt64(1, base::Time::kTimeTToMicrosecondsOffset); |
275 if (!s.Run()) | 298 if (!s.Run()) |
276 return false; | 299 return false; |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
843 | 866 |
844 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { | 867 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { |
845 DCHECK(db_.is_open()); | 868 DCHECK(db_.is_open()); |
846 meta_table_.Reset(); | 869 meta_table_.Reset(); |
847 db_.Close(); | 870 db_.Close(); |
848 sql::Connection::Delete(db_path_); | 871 sql::Connection::Delete(db_path_); |
849 return Init(db_path_); | 872 return Init(db_path_); |
850 } | 873 } |
851 | 874 |
852 } // namespace password_manager | 875 } // namespace password_manager |
OLD | NEW |