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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 " use_additional_auth) VALUES " | 328 " use_additional_auth) VALUES " |
329 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")); | 329 "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")); |
330 BindAddStatement(form, encrypted_password, &s); | 330 BindAddStatement(form, encrypted_password, &s); |
331 if (s.Run()) { | 331 if (s.Run()) { |
332 list.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); | 332 list.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); |
333 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); | 333 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); |
334 } | 334 } |
335 return list; | 335 return list; |
336 } | 336 } |
337 | 337 |
338 bool LoginDatabase::UpdateLogin(const PasswordForm& form, int* items_changed) { | 338 PasswordStoreChangeList LoginDatabase::UpdateLogin(const PasswordForm& form) { |
339 std::string encrypted_password; | 339 std::string encrypted_password; |
340 if (EncryptedString(form.password_value, &encrypted_password) != | 340 if (EncryptedString(form.password_value, &encrypted_password) != |
341 ENCRYPTION_RESULT_SUCCESS) | 341 ENCRYPTION_RESULT_SUCCESS) |
342 return false; | 342 return PasswordStoreChangeList(); |
343 | 343 |
344 // Replacement is necessary to deal with updating imported credentials. See | 344 // Replacement is necessary to deal with updating imported credentials. See |
345 // crbug.com/349138 for details. | 345 // crbug.com/349138 for details. |
346 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, | 346 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, |
347 "UPDATE OR REPLACE logins SET " | 347 "UPDATE OR REPLACE logins SET " |
348 "action_url = ?, " | 348 "action_url = ?, " |
349 "password_value = ?, " | 349 "password_value = ?, " |
350 "ssl_valid = ?, " | 350 "ssl_valid = ?, " |
351 "preferred = ?, " | 351 "preferred = ?, " |
352 "possible_usernames = ?, " | 352 "possible_usernames = ?, " |
353 "times_used = ?, " | 353 "times_used = ?, " |
354 "username_element = ?, " | |
355 "password_element = ?, " | |
356 "submit_element = ? " | 354 "submit_element = ? " |
357 "WHERE origin_url = ? AND " | 355 "WHERE origin_url = ? AND " |
358 "(username_element = ? OR username_element = '') AND " | 356 "username_element = ? AND " |
359 "username_value = ? AND " | 357 "username_value = ? AND " |
360 "(password_element = ? OR password_element = '') AND " | 358 "password_element = ? AND " |
361 "(submit_element = ? OR submit_element = '') AND " | |
362 "signon_realm = ?")); | 359 "signon_realm = ?")); |
363 s.BindString(0, form.action.spec()); | 360 s.BindString(0, form.action.spec()); |
364 s.BindBlob(1, encrypted_password.data(), | 361 s.BindBlob(1, encrypted_password.data(), |
365 static_cast<int>(encrypted_password.length())); | 362 static_cast<int>(encrypted_password.length())); |
366 s.BindInt(2, form.ssl_valid); | 363 s.BindInt(2, form.ssl_valid); |
367 s.BindInt(3, form.preferred); | 364 s.BindInt(3, form.preferred); |
368 Pickle pickle = SerializeVector(form.other_possible_usernames); | 365 Pickle pickle = SerializeVector(form.other_possible_usernames); |
369 s.BindBlob(4, pickle.data(), pickle.size()); | 366 s.BindBlob(4, pickle.data(), pickle.size()); |
370 s.BindInt(5, form.times_used); | 367 s.BindInt(5, form.times_used); |
371 s.BindString16(6, form.username_element); | 368 s.BindString16(6, form.submit_element); |
372 s.BindString16(7, form.password_element); | |
373 s.BindString16(8, form.submit_element); | |
374 | 369 |
375 s.BindString(9, form.origin.spec()); | 370 s.BindString(7, form.origin.spec()); |
376 s.BindString16(10, form.username_element); | 371 s.BindString16(8, form.username_element); |
377 s.BindString16(11, form.username_value); | 372 s.BindString16(9, form.username_value); |
378 s.BindString16(12, form.password_element); | 373 s.BindString16(10, form.password_element); |
379 s.BindString16(13, form.submit_element); | 374 s.BindString(11, form.signon_realm); |
380 s.BindString(14, form.signon_realm); | |
381 | 375 |
382 if (!s.Run()) | 376 if (!s.Run()) |
383 return false; | 377 return PasswordStoreChangeList(); |
384 | 378 |
385 if (items_changed) | 379 PasswordStoreChangeList list; |
386 *items_changed = db_.GetLastChangeCount(); | 380 if (db_.GetLastChangeCount()) |
| 381 list.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form)); |
387 | 382 |
388 return true; | 383 return list; |
389 } | 384 } |
390 | 385 |
391 bool LoginDatabase::RemoveLogin(const PasswordForm& form) { | 386 bool LoginDatabase::RemoveLogin(const PasswordForm& form) { |
392 // Remove a login by UNIQUE-constrained fields. | 387 // Remove a login by UNIQUE-constrained fields. |
393 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, | 388 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, |
394 "DELETE FROM logins WHERE " | 389 "DELETE FROM logins WHERE " |
395 "origin_url = ? AND " | 390 "origin_url = ? AND " |
396 "username_element = ? AND " | 391 "username_element = ? AND " |
397 "username_value = ? AND " | 392 "username_value = ? AND " |
398 "password_element = ? AND " | 393 "password_element = ? AND " |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 | 626 |
632 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { | 627 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { |
633 DCHECK(db_.is_open()); | 628 DCHECK(db_.is_open()); |
634 meta_table_.Reset(); | 629 meta_table_.Reset(); |
635 db_.Close(); | 630 db_.Close(); |
636 sql::Connection::Delete(db_path_); | 631 sql::Connection::Delete(db_path_); |
637 return Init(db_path_); | 632 return Init(db_path_); |
638 } | 633 } |
639 | 634 |
640 } // namespace password_manager | 635 } // namespace password_manager |
OLD | NEW |