OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/password_manager/native_backend_kwallet_x.h" | 5 #include "chrome/browser/password_manager/native_backend_kwallet_x.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 kept_forms.push_back(all_forms[i]); | 349 kept_forms.push_back(all_forms[i]); |
350 } | 350 } |
351 | 351 |
352 // Update the entry in the wallet, possibly deleting it. | 352 // Update the entry in the wallet, possibly deleting it. |
353 bool ok = SetLoginsList(kept_forms, form.signon_realm, wallet_handle); | 353 bool ok = SetLoginsList(kept_forms, form.signon_realm, wallet_handle); |
354 | 354 |
355 STLDeleteElements(&kept_forms); | 355 STLDeleteElements(&kept_forms); |
356 return ok; | 356 return ok; |
357 } | 357 } |
358 | 358 |
359 bool NativeBackendKWallet::RemoveLoginsCreatedBetween(base::Time delete_begin, | 359 bool NativeBackendKWallet::RemoveLoginsCreatedBetween( |
360 base::Time delete_end) { | 360 base::Time delete_begin, |
361 password_manager::PasswordStoreChangeList changes; | 361 base::Time delete_end, |
| 362 password_manager::PasswordStoreChangeList* changes) { |
362 return RemoveLoginsBetween( | 363 return RemoveLoginsBetween( |
363 delete_begin, delete_end, CREATION_TIMESTAMP, &changes); | 364 delete_begin, delete_end, CREATION_TIMESTAMP, changes); |
364 } | 365 } |
365 | 366 |
366 bool NativeBackendKWallet::RemoveLoginsSyncedBetween( | 367 bool NativeBackendKWallet::RemoveLoginsSyncedBetween( |
367 base::Time delete_begin, | 368 base::Time delete_begin, |
368 base::Time delete_end, | 369 base::Time delete_end, |
369 password_manager::PasswordStoreChangeList* changes) { | 370 password_manager::PasswordStoreChangeList* changes) { |
370 return RemoveLoginsBetween(delete_begin, delete_end, SYNC_TIMESTAMP, changes); | 371 return RemoveLoginsBetween(delete_begin, delete_end, SYNC_TIMESTAMP, changes); |
371 } | 372 } |
372 | 373 |
373 bool NativeBackendKWallet::GetLogins(const PasswordForm& form, | 374 bool NativeBackendKWallet::GetLogins(const PasswordForm& form, |
374 PasswordFormList* forms) { | 375 PasswordFormList* forms) { |
375 int wallet_handle = WalletHandle(); | 376 int wallet_handle = WalletHandle(); |
376 if (wallet_handle == kInvalidKWalletHandle) | 377 if (wallet_handle == kInvalidKWalletHandle) |
377 return false; | 378 return false; |
378 return GetLoginsList(forms, form.signon_realm, wallet_handle); | 379 return GetLoginsList(forms, form.signon_realm, wallet_handle); |
379 } | 380 } |
380 | 381 |
381 bool NativeBackendKWallet::GetLoginsCreatedBetween(base::Time get_begin, | |
382 base::Time get_end, | |
383 PasswordFormList* forms) { | |
384 int wallet_handle = WalletHandle(); | |
385 if (wallet_handle == kInvalidKWalletHandle) | |
386 return false; | |
387 return GetLoginsList( | |
388 forms, get_begin, get_end, wallet_handle, CREATION_TIMESTAMP); | |
389 } | |
390 | |
391 bool NativeBackendKWallet::GetAutofillableLogins(PasswordFormList* forms) { | 382 bool NativeBackendKWallet::GetAutofillableLogins(PasswordFormList* forms) { |
392 int wallet_handle = WalletHandle(); | 383 int wallet_handle = WalletHandle(); |
393 if (wallet_handle == kInvalidKWalletHandle) | 384 if (wallet_handle == kInvalidKWalletHandle) |
394 return false; | 385 return false; |
395 return GetLoginsList(forms, true, wallet_handle); | 386 return GetLoginsList(forms, true, wallet_handle); |
396 } | 387 } |
397 | 388 |
398 bool NativeBackendKWallet::GetBlacklistLogins(PasswordFormList* forms) { | 389 bool NativeBackendKWallet::GetBlacklistLogins(PasswordFormList* forms) { |
399 int wallet_handle = WalletHandle(); | 390 int wallet_handle = WalletHandle(); |
400 if (wallet_handle == kInvalidKWalletHandle) | 391 if (wallet_handle == kInvalidKWalletHandle) |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 for (size_t i = 0; i < all_forms.size(); ++i) { | 477 for (size_t i = 0; i < all_forms.size(); ++i) { |
487 if (all_forms[i]->blacklisted_by_user == !autofillable) | 478 if (all_forms[i]->blacklisted_by_user == !autofillable) |
488 forms->push_back(all_forms[i]); | 479 forms->push_back(all_forms[i]); |
489 else | 480 else |
490 delete all_forms[i]; | 481 delete all_forms[i]; |
491 } | 482 } |
492 | 483 |
493 return true; | 484 return true; |
494 } | 485 } |
495 | 486 |
496 bool NativeBackendKWallet::GetLoginsList(PasswordFormList* forms, | |
497 const base::Time& begin, | |
498 const base::Time& end, | |
499 int wallet_handle, | |
500 TimestampToCompare date_to_compare) { | |
501 PasswordFormList all_forms; | |
502 if (!GetAllLogins(&all_forms, wallet_handle)) | |
503 return false; | |
504 | |
505 // We have to read all the entries, and then filter them here. | |
506 base::Time autofill::PasswordForm::*date_member = | |
507 date_to_compare == CREATION_TIMESTAMP | |
508 ? &autofill::PasswordForm::date_created | |
509 : &autofill::PasswordForm::date_synced; | |
510 forms->reserve(forms->size() + all_forms.size()); | |
511 for (size_t i = 0; i < all_forms.size(); ++i) { | |
512 if (begin <= all_forms[i]->*date_member && | |
513 (end.is_null() || all_forms[i]->*date_member < end)) { | |
514 forms->push_back(all_forms[i]); | |
515 } else { | |
516 delete all_forms[i]; | |
517 } | |
518 } | |
519 | |
520 return true; | |
521 } | |
522 | |
523 bool NativeBackendKWallet::GetAllLogins(PasswordFormList* forms, | 487 bool NativeBackendKWallet::GetAllLogins(PasswordFormList* forms, |
524 int wallet_handle) { | 488 int wallet_handle) { |
525 // We could probably also use readEntryList here. | 489 // We could probably also use readEntryList here. |
526 std::vector<std::string> realm_list; | 490 std::vector<std::string> realm_list; |
527 { | 491 { |
528 dbus::MethodCall method_call(kKWalletInterface, "entryList"); | 492 dbus::MethodCall method_call(kKWalletInterface, "entryList"); |
529 dbus::MessageWriter builder(&method_call); | 493 dbus::MessageWriter builder(&method_call); |
530 builder.AppendInt32(wallet_handle); // handle | 494 builder.AppendInt32(wallet_handle); // handle |
531 builder.AppendString(folder_name_); // folder | 495 builder.AppendString(folder_name_); // folder |
532 builder.AppendString(app_name_); // appid | 496 builder.AppendString(app_name_); // appid |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 } | 938 } |
975 | 939 |
976 return handle; | 940 return handle; |
977 } | 941 } |
978 | 942 |
979 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { | 943 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { |
980 // Originally, the folder name was always just "Chrome Form Data". | 944 // Originally, the folder name was always just "Chrome Form Data". |
981 // Now we use it to distinguish passwords for different profiles. | 945 // Now we use it to distinguish passwords for different profiles. |
982 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); | 946 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); |
983 } | 947 } |
OLD | NEW |