| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 192 |
| 193 bool CreateIndexOnSignonRealm(sql::Connection* db, const char* table_name) { | 193 bool CreateIndexOnSignonRealm(sql::Connection* db, const char* table_name) { |
| 194 std::string query = base::StringPrintf( | 194 std::string query = base::StringPrintf( |
| 195 "CREATE INDEX logins_signon ON %s (signon_realm)", table_name); | 195 "CREATE INDEX logins_signon ON %s (signon_realm)", table_name); |
| 196 return db->Execute(query.c_str()); | 196 return db->Execute(query.c_str()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 } // namespace | 199 } // namespace |
| 200 | 200 |
| 201 LoginDatabase::LoginDatabase(const base::FilePath& db_path) | 201 LoginDatabase::LoginDatabase(const base::FilePath& db_path) |
| 202 : db_path_(db_path) { | 202 : db_path_(db_path), clear_password_values_(false) { |
| 203 } | 203 } |
| 204 | 204 |
| 205 LoginDatabase::~LoginDatabase() { | 205 LoginDatabase::~LoginDatabase() { |
| 206 } | 206 } |
| 207 | 207 |
| 208 bool LoginDatabase::Init() { | 208 bool LoginDatabase::Init() { |
| 209 // Set pragmas for a small, private database (based on WebDatabase). | 209 // Set pragmas for a small, private database (based on WebDatabase). |
| 210 db_.set_page_size(2048); | 210 db_.set_page_size(2048); |
| 211 db_.set_cache_size(32); | 211 db_.set_cache_size(32); |
| 212 db_.set_exclusive_locking(); | 212 db_.set_exclusive_locking(); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 "PasswordManager.EmptyUsernames.WithoutCorrespondingNonempty", | 527 "PasswordManager.EmptyUsernames.WithoutCorrespondingNonempty", |
| 528 num_entries); | 528 num_entries); |
| 529 } | 529 } |
| 530 } | 530 } |
| 531 | 531 |
| 532 PasswordStoreChangeList LoginDatabase::AddLogin(const PasswordForm& form) { | 532 PasswordStoreChangeList LoginDatabase::AddLogin(const PasswordForm& form) { |
| 533 PasswordStoreChangeList list; | 533 PasswordStoreChangeList list; |
| 534 if (!DoesMatchConstraints(form)) | 534 if (!DoesMatchConstraints(form)) |
| 535 return list; | 535 return list; |
| 536 std::string encrypted_password; | 536 std::string encrypted_password; |
| 537 if (EncryptedString(form.password_value, &encrypted_password) != | 537 if (EncryptedString( |
| 538 ENCRYPTION_RESULT_SUCCESS) | 538 clear_password_values_ ? base::string16() : form.password_value, |
| 539 &encrypted_password) != ENCRYPTION_RESULT_SUCCESS) |
| 539 return list; | 540 return list; |
| 540 | 541 |
| 541 // You *must* change LoginTableColumns if this query changes. | 542 // You *must* change LoginTableColumns if this query changes. |
| 542 sql::Statement s(db_.GetCachedStatement( | 543 sql::Statement s(db_.GetCachedStatement( |
| 543 SQL_FROM_HERE, | 544 SQL_FROM_HERE, |
| 544 "INSERT INTO logins " | 545 "INSERT INTO logins " |
| 545 "(origin_url, action_url, username_element, username_value, " | 546 "(origin_url, action_url, username_element, username_value, " |
| 546 " password_element, password_value, submit_element, " | 547 " password_element, password_value, submit_element, " |
| 547 " signon_realm, ssl_valid, preferred, date_created, blacklisted_by_user, " | 548 " signon_realm, ssl_valid, preferred, date_created, blacklisted_by_user, " |
| 548 " scheme, password_type, possible_usernames, times_used, form_data, " | 549 " scheme, password_type, possible_usernames, times_used, form_data, " |
| (...skipping 22 matching lines...) Expand all Loading... |
| 571 BindAddStatement(form, encrypted_password, &s); | 572 BindAddStatement(form, encrypted_password, &s); |
| 572 if (s.Run()) { | 573 if (s.Run()) { |
| 573 list.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); | 574 list.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); |
| 574 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); | 575 list.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); |
| 575 } | 576 } |
| 576 return list; | 577 return list; |
| 577 } | 578 } |
| 578 | 579 |
| 579 PasswordStoreChangeList LoginDatabase::UpdateLogin(const PasswordForm& form) { | 580 PasswordStoreChangeList LoginDatabase::UpdateLogin(const PasswordForm& form) { |
| 580 std::string encrypted_password; | 581 std::string encrypted_password; |
| 581 if (EncryptedString(form.password_value, &encrypted_password) != | 582 if (EncryptedString( |
| 582 ENCRYPTION_RESULT_SUCCESS) | 583 clear_password_values_ ? base::string16() : form.password_value, |
| 584 &encrypted_password) != ENCRYPTION_RESULT_SUCCESS) |
| 583 return PasswordStoreChangeList(); | 585 return PasswordStoreChangeList(); |
| 584 | 586 |
| 585 // Replacement is necessary to deal with updating imported credentials. See | 587 // Replacement is necessary to deal with updating imported credentials. See |
| 586 // crbug.com/349138 for details. | 588 // crbug.com/349138 for details. |
| 587 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, | 589 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, |
| 588 "UPDATE OR REPLACE logins SET " | 590 "UPDATE OR REPLACE logins SET " |
| 589 "action_url = ?, " | 591 "action_url = ?, " |
| 590 "password_value = ?, " | 592 "password_value = ?, " |
| 591 "ssl_valid = ?, " | 593 "ssl_valid = ?, " |
| 592 "preferred = ?, " | 594 "preferred = ?, " |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", | 957 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", |
| 956 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT); | 958 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT); |
| 957 } | 959 } |
| 958 | 960 |
| 959 if (!statement->Succeeded()) | 961 if (!statement->Succeeded()) |
| 960 return false; | 962 return false; |
| 961 return true; | 963 return true; |
| 962 } | 964 } |
| 963 | 965 |
| 964 } // namespace password_manager | 966 } // namespace password_manager |
| OLD | NEW |