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

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

Issue 335893002: Support to remove passwords by date_synced timestamp. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync integration tests Created 6 years, 6 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 | Annotate | Revision Log
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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 // Replacement is necessary to deal with updating imported credentials. See 354 // Replacement is necessary to deal with updating imported credentials. See
355 // crbug.com/349138 for details. 355 // crbug.com/349138 for details.
356 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, 356 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
357 "UPDATE OR REPLACE logins SET " 357 "UPDATE OR REPLACE logins SET "
358 "action_url = ?, " 358 "action_url = ?, "
359 "password_value = ?, " 359 "password_value = ?, "
360 "ssl_valid = ?, " 360 "ssl_valid = ?, "
361 "preferred = ?, " 361 "preferred = ?, "
362 "possible_usernames = ?, " 362 "possible_usernames = ?, "
363 "times_used = ?, " 363 "times_used = ?, "
364 "submit_element = ? " 364 "submit_element = ?, "
365 "date_synced = ? "
365 "WHERE origin_url = ? AND " 366 "WHERE origin_url = ? AND "
366 "username_element = ? AND " 367 "username_element = ? AND "
367 "username_value = ? AND " 368 "username_value = ? AND "
368 "password_element = ? AND " 369 "password_element = ? AND "
369 "signon_realm = ?")); 370 "signon_realm = ?"));
370 s.BindString(0, form.action.spec()); 371 s.BindString(0, form.action.spec());
371 s.BindBlob(1, encrypted_password.data(), 372 s.BindBlob(1, encrypted_password.data(),
372 static_cast<int>(encrypted_password.length())); 373 static_cast<int>(encrypted_password.length()));
373 s.BindInt(2, form.ssl_valid); 374 s.BindInt(2, form.ssl_valid);
374 s.BindInt(3, form.preferred); 375 s.BindInt(3, form.preferred);
375 Pickle pickle = SerializeVector(form.other_possible_usernames); 376 Pickle pickle = SerializeVector(form.other_possible_usernames);
376 s.BindBlob(4, pickle.data(), pickle.size()); 377 s.BindBlob(4, pickle.data(), pickle.size());
377 s.BindInt(5, form.times_used); 378 s.BindInt(5, form.times_used);
378 s.BindString16(6, form.submit_element); 379 s.BindString16(6, form.submit_element);
380 s.BindInt64(7, form.date_synced.ToInternalValue());
379 381
380 s.BindString(7, form.origin.spec()); 382 s.BindString(8, form.origin.spec());
381 s.BindString16(8, form.username_element); 383 s.BindString16(9, form.username_element);
382 s.BindString16(9, form.username_value); 384 s.BindString16(10, form.username_value);
383 s.BindString16(10, form.password_element); 385 s.BindString16(11, form.password_element);
384 s.BindString(11, form.signon_realm); 386 s.BindString(12, form.signon_realm);
385 387
386 if (!s.Run()) 388 if (!s.Run())
387 return PasswordStoreChangeList(); 389 return PasswordStoreChangeList();
388 390
389 PasswordStoreChangeList list; 391 PasswordStoreChangeList list;
390 if (db_.GetLastChangeCount()) 392 if (db_.GetLastChangeCount())
391 list.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form)); 393 list.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form));
392 394
393 return list; 395 return list;
394 } 396 }
(...skipping 23 matching lines...) Expand all
418 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, 420 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
419 "DELETE FROM logins WHERE " 421 "DELETE FROM logins WHERE "
420 "date_created >= ? AND date_created < ?")); 422 "date_created >= ? AND date_created < ?"));
421 s.BindInt64(0, delete_begin.ToTimeT()); 423 s.BindInt64(0, delete_begin.ToTimeT());
422 s.BindInt64(1, delete_end.is_null() ? std::numeric_limits<int64>::max() 424 s.BindInt64(1, delete_end.is_null() ? std::numeric_limits<int64>::max()
423 : delete_end.ToTimeT()); 425 : delete_end.ToTimeT());
424 426
425 return s.Run(); 427 return s.Run();
426 } 428 }
427 429
430 bool LoginDatabase::RemoveLoginsSyncedBetween(const base::Time delete_begin,
431 const base::Time delete_end) {
432 sql::Statement s(db_.GetCachedStatement(
433 SQL_FROM_HERE,
434 "DELETE FROM logins WHERE date_synced >= ? AND date_synced < ?"));
435 s.BindInt64(0, delete_begin.ToInternalValue());
436 s.BindInt64(1, delete_end.is_null() ? base::Time::Max().ToInternalValue()
437 : delete_end.ToInternalValue());
438
439 return s.Run();
440 }
441
428 LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement( 442 LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement(
429 PasswordForm* form, 443 PasswordForm* form,
430 sql::Statement& s) const { 444 sql::Statement& s) const {
431 std::string encrypted_password; 445 std::string encrypted_password;
432 s.ColumnBlobAsString(COLUMN_PASSWORD_VALUE, &encrypted_password); 446 s.ColumnBlobAsString(COLUMN_PASSWORD_VALUE, &encrypted_password);
433 base::string16 decrypted_password; 447 base::string16 decrypted_password;
434 EncryptionResult encryption_result = 448 EncryptionResult encryption_result =
435 DecryptedString(encrypted_password, &decrypted_password); 449 DecryptedString(encrypted_password, &decrypted_password);
436 if (encryption_result != ENCRYPTION_RESULT_SUCCESS) 450 if (encryption_result != ENCRYPTION_RESULT_SUCCESS)
437 return encryption_result; 451 return encryption_result;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 if (result == ENCRYPTION_RESULT_SERVICE_FAILURE) 610 if (result == ENCRYPTION_RESULT_SERVICE_FAILURE)
597 return false; 611 return false;
598 if (result == ENCRYPTION_RESULT_ITEM_FAILURE) 612 if (result == ENCRYPTION_RESULT_ITEM_FAILURE)
599 continue; 613 continue;
600 DCHECK(result == ENCRYPTION_RESULT_SUCCESS); 614 DCHECK(result == ENCRYPTION_RESULT_SUCCESS);
601 forms->push_back(new_form.release()); 615 forms->push_back(new_form.release());
602 } 616 }
603 return s.Succeeded(); 617 return s.Succeeded();
604 } 618 }
605 619
620 bool LoginDatabase::GetLoginsSyncedBetween(
621 const base::Time begin,
622 const base::Time end,
623 std::vector<autofill::PasswordForm*>* forms) const {
624 DCHECK(forms);
625 sql::Statement s(db_.GetCachedStatement(
626 SQL_FROM_HERE,
627 "SELECT origin_url, action_url, username_element, username_value, "
628 "password_element, password_value, submit_element, signon_realm, "
629 "ssl_valid, preferred, date_created, blacklisted_by_user, "
630 "scheme, password_type, possible_usernames, times_used, form_data, "
631 "use_additional_auth, date_synced FROM logins "
632 "WHERE date_synced >= ? AND date_synced < ?"
633 "ORDER BY origin_url"));
634 s.BindInt64(0, begin.ToInternalValue());
635 s.BindInt64(1, end.is_null() ? base::Time::Max().ToInternalValue()
636 : end.ToInternalValue());
637
638 while (s.Step()) {
639 scoped_ptr<PasswordForm> new_form(new PasswordForm());
640 EncryptionResult result = InitPasswordFormFromStatement(new_form.get(), s);
641 if (result == ENCRYPTION_RESULT_SERVICE_FAILURE)
642 return false;
643 if (result == ENCRYPTION_RESULT_ITEM_FAILURE)
644 continue;
645 DCHECK(result == ENCRYPTION_RESULT_SUCCESS);
646 forms->push_back(new_form.release());
647 }
648 return s.Succeeded();
649 }
650
606 bool LoginDatabase::GetAutofillableLogins( 651 bool LoginDatabase::GetAutofillableLogins(
607 std::vector<PasswordForm*>* forms) const { 652 std::vector<PasswordForm*>* forms) const {
608 return GetAllLoginsWithBlacklistSetting(false, forms); 653 return GetAllLoginsWithBlacklistSetting(false, forms);
609 } 654 }
610 655
611 bool LoginDatabase::GetBlacklistLogins( 656 bool LoginDatabase::GetBlacklistLogins(
612 std::vector<PasswordForm*>* forms) const { 657 std::vector<PasswordForm*>* forms) const {
613 return GetAllLoginsWithBlacklistSetting(true, forms); 658 return GetAllLoginsWithBlacklistSetting(true, forms);
614 } 659 }
615 660
(...skipping 26 matching lines...) Expand all
642 687
643 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { 688 bool LoginDatabase::DeleteAndRecreateDatabaseFile() {
644 DCHECK(db_.is_open()); 689 DCHECK(db_.is_open());
645 meta_table_.Reset(); 690 meta_table_.Reset();
646 db_.Close(); 691 db_.Close();
647 sql::Connection::Delete(db_path_); 692 sql::Connection::Delete(db_path_);
648 return Init(db_path_); 693 return Init(db_path_);
649 } 694 }
650 695
651 } // namespace password_manager 696 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698