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

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

Issue 818443004: Remove use_additional_auth column from logins table. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « no previous file | components/password_manager/core/browser/login_database_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 10 matching lines...) Expand all
21 #include "google_apis/gaia/gaia_auth_util.h" 21 #include "google_apis/gaia/gaia_auth_util.h"
22 #include "google_apis/gaia/gaia_urls.h" 22 #include "google_apis/gaia/gaia_urls.h"
23 #include "sql/connection.h" 23 #include "sql/connection.h"
24 #include "sql/statement.h" 24 #include "sql/statement.h"
25 #include "sql/transaction.h" 25 #include "sql/transaction.h"
26 26
27 using autofill::PasswordForm; 27 using autofill::PasswordForm;
28 28
29 namespace password_manager { 29 namespace password_manager {
30 30
31 const int kCurrentVersionNumber = 9; 31 const int kCurrentVersionNumber = 10;
32 static const int kCompatibleVersionNumber = 1; 32 static const int kCompatibleVersionNumber = 1;
33 33
34 Pickle SerializeVector(const std::vector<base::string16>& vec) { 34 Pickle SerializeVector(const std::vector<base::string16>& vec) {
35 Pickle p; 35 Pickle p;
36 for (size_t i = 0; i < vec.size(); ++i) { 36 for (size_t i = 0; i < vec.size(); ++i) {
37 p.WriteString16(vec[i]); 37 p.WriteString16(vec[i]);
38 } 38 }
39 return p; 39 return p;
40 } 40 }
41 41
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 case 6: 262 case 6:
263 if (!db_.Execute("ALTER TABLE logins ADD COLUMN display_name VARCHAR") || 263 if (!db_.Execute("ALTER TABLE logins ADD COLUMN display_name VARCHAR") ||
264 !db_.Execute("ALTER TABLE logins ADD COLUMN avatar_url VARCHAR") || 264 !db_.Execute("ALTER TABLE logins ADD COLUMN avatar_url VARCHAR") ||
265 !db_.Execute("ALTER TABLE logins " 265 !db_.Execute("ALTER TABLE logins "
266 "ADD COLUMN federation_url VARCHAR") || 266 "ADD COLUMN federation_url VARCHAR") ||
267 !db_.Execute("ALTER TABLE logins ADD COLUMN is_zero_click INTEGER")) { 267 !db_.Execute("ALTER TABLE logins ADD COLUMN is_zero_click INTEGER")) {
268 return false; 268 return false;
269 } 269 }
270 meta_table_.SetVersionNumber(7); 270 meta_table_.SetVersionNumber(7);
271 // Fall through. 271 // Fall through.
272 case 7: 272 case 7: {
273 // Keep version 8 around even though no changes are made. See 273 // Keep version 8 around even though no changes are made. See
274 // crbug.com/423716 for context. 274 // crbug.com/423716 for context.
275 meta_table_.SetVersionNumber(8); 275 meta_table_.SetVersionNumber(8);
276 // Fall through. 276 // Fall through.
277 // TODO(gcasto): Remove use_additional_auth by copying table. 277 }
278 // https://www.sqlite.org/lang_altertable.html
279 case 8: { 278 case 8: {
280 sql::Statement s; 279 sql::Statement s;
281 s.Assign(db_.GetCachedStatement(SQL_FROM_HERE, 280 s.Assign(db_.GetCachedStatement(SQL_FROM_HERE,
282 "UPDATE logins SET " 281 "UPDATE logins SET "
283 "date_created = " 282 "date_created = "
284 "(date_created * ?) + ?")); 283 "(date_created * ?) + ?"));
285 s.BindInt64(0, base::Time::kMicrosecondsPerSecond); 284 s.BindInt64(0, base::Time::kMicrosecondsPerSecond);
286 s.BindInt64(1, base::Time::kTimeTToMicrosecondsOffset); 285 s.BindInt64(1, base::Time::kTimeTToMicrosecondsOffset);
287 if (!s.Run()) 286 if (!s.Run())
288 return false; 287 return false;
289 meta_table_.SetVersionNumber(9); 288 meta_table_.SetVersionNumber(9);
290 // Fall through. 289 // Fall through.
291 } 290 }
291 case 9: {
292 // Remove use_additional_auth column from database schema
293 // crbug.com/423716 for context.
294 std::string fields_to_copy =
295 "origin_url, action_url, username_element, username_value, "
296 "password_element, password_value, submit_element, "
297 "signon_realm, ssl_valid, preferred, date_created, "
298 "blacklisted_by_user, scheme, password_type, possible_usernames, "
299 "times_used, form_data, date_synced, display_name, avatar_url, "
300 "federation_url, is_zero_click";
301 auto copy_data_query =
302 [&fields_to_copy](const std::string& from, const std::string& to) {
303 return "INSERT INTO " + to + " SELECT " + fields_to_copy + " FROM " +
304 from;
305 };
306
307 if (!db_.Execute(("CREATE TEMPORARY TABLE logins_data(" + fields_to_copy +
308 ")").c_str()) ||
309 !db_.Execute(copy_data_query("logins", "logins_data").c_str()) ||
310 !db_.Execute("DROP TABLE logins") ||
311 !db_.Execute(
312 ("CREATE TABLE logins(" + fields_to_copy + ")").c_str()) ||
313 !db_.Execute(copy_data_query("logins_data", "logins").c_str()) ||
314 !db_.Execute("DROP TABLE logins_data") ||
315 !db_.Execute("CREATE INDEX logins_signon ON logins (signon_realm)"))
316 return false;
317
318 meta_table_.SetVersionNumber(10);
319 }
292 case kCurrentVersionNumber: 320 case kCurrentVersionNumber:
293 // Already up to date 321 // Already up to date
294 return true; 322 return true;
295 default: 323 default:
296 NOTREACHED(); 324 NOTREACHED();
297 return false; 325 return false;
298 } 326 }
299 } 327 }
300 328
301 bool LoginDatabase::InitLoginsTable() { 329 bool LoginDatabase::InitLoginsTable() {
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 885
858 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { 886 bool LoginDatabase::DeleteAndRecreateDatabaseFile() {
859 DCHECK(db_.is_open()); 887 DCHECK(db_.is_open());
860 meta_table_.Reset(); 888 meta_table_.Reset();
861 db_.Close(); 889 db_.Close();
862 sql::Connection::Delete(db_path_); 890 sql::Connection::Delete(db_path_);
863 return Init(db_path_); 891 return Init(db_path_);
864 } 892 }
865 893
866 } // namespace password_manager 894 } // namespace password_manager
OLDNEW
« no previous file with comments | « no previous file | components/password_manager/core/browser/login_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698