| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/password_store_x.h" | 5 #include "chrome/browser/password_manager/password_store_x.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 PasswordStoreX::~PasswordStoreX() { | 28 PasswordStoreX::~PasswordStoreX() { |
| 29 } | 29 } |
| 30 | 30 |
| 31 void PasswordStoreX::AddLoginImpl(const PasswordForm& form) { | 31 void PasswordStoreX::AddLoginImpl(const PasswordForm& form) { |
| 32 CheckMigration(); | 32 CheckMigration(); |
| 33 if (use_native_backend() && backend_->AddLogin(form)) { | 33 if (use_native_backend() && backend_->AddLogin(form)) { |
| 34 PasswordStoreChangeList changes; | 34 PasswordStoreChangeList changes; |
| 35 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); | 35 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); |
| 36 NotificationService::current()->Notify( | 36 NotificationService::current()->Notify( |
| 37 NotificationType::LOGINS_CHANGED, | 37 chrome::LOGINS_CHANGED, |
| 38 Source<PasswordStore>(this), | 38 Source<PasswordStore>(this), |
| 39 Details<PasswordStoreChangeList>(&changes)); | 39 Details<PasswordStoreChangeList>(&changes)); |
| 40 allow_fallback_ = false; | 40 allow_fallback_ = false; |
| 41 } else if (allow_default_store()) { | 41 } else if (allow_default_store()) { |
| 42 PasswordStoreDefault::AddLoginImpl(form); | 42 PasswordStoreDefault::AddLoginImpl(form); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 void PasswordStoreX::UpdateLoginImpl(const PasswordForm& form) { | 46 void PasswordStoreX::UpdateLoginImpl(const PasswordForm& form) { |
| 47 CheckMigration(); | 47 CheckMigration(); |
| 48 if (use_native_backend() && backend_->UpdateLogin(form)) { | 48 if (use_native_backend() && backend_->UpdateLogin(form)) { |
| 49 PasswordStoreChangeList changes; | 49 PasswordStoreChangeList changes; |
| 50 changes.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form)); | 50 changes.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form)); |
| 51 NotificationService::current()->Notify( | 51 NotificationService::current()->Notify( |
| 52 NotificationType::LOGINS_CHANGED, | 52 chrome::LOGINS_CHANGED, |
| 53 Source<PasswordStore>(this), | 53 Source<PasswordStore>(this), |
| 54 Details<PasswordStoreChangeList>(&changes)); | 54 Details<PasswordStoreChangeList>(&changes)); |
| 55 allow_fallback_ = false; | 55 allow_fallback_ = false; |
| 56 } else if (allow_default_store()) { | 56 } else if (allow_default_store()) { |
| 57 PasswordStoreDefault::UpdateLoginImpl(form); | 57 PasswordStoreDefault::UpdateLoginImpl(form); |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 void PasswordStoreX::RemoveLoginImpl(const PasswordForm& form) { | 61 void PasswordStoreX::RemoveLoginImpl(const PasswordForm& form) { |
| 62 CheckMigration(); | 62 CheckMigration(); |
| 63 if (use_native_backend() && backend_->RemoveLogin(form)) { | 63 if (use_native_backend() && backend_->RemoveLogin(form)) { |
| 64 PasswordStoreChangeList changes; | 64 PasswordStoreChangeList changes; |
| 65 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); | 65 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); |
| 66 NotificationService::current()->Notify( | 66 NotificationService::current()->Notify( |
| 67 NotificationType::LOGINS_CHANGED, | 67 chrome::LOGINS_CHANGED, |
| 68 Source<PasswordStore>(this), | 68 Source<PasswordStore>(this), |
| 69 Details<PasswordStoreChangeList>(&changes)); | 69 Details<PasswordStoreChangeList>(&changes)); |
| 70 allow_fallback_ = false; | 70 allow_fallback_ = false; |
| 71 } else if (allow_default_store()) { | 71 } else if (allow_default_store()) { |
| 72 PasswordStoreDefault::RemoveLoginImpl(form); | 72 PasswordStoreDefault::RemoveLoginImpl(form); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 void PasswordStoreX::RemoveLoginsCreatedBetweenImpl( | 76 void PasswordStoreX::RemoveLoginsCreatedBetweenImpl( |
| 77 const base::Time& delete_begin, | 77 const base::Time& delete_begin, |
| 78 const base::Time& delete_end) { | 78 const base::Time& delete_end) { |
| 79 CheckMigration(); | 79 CheckMigration(); |
| 80 vector<PasswordForm*> forms; | 80 vector<PasswordForm*> forms; |
| 81 if (use_native_backend() && | 81 if (use_native_backend() && |
| 82 backend_->GetLoginsCreatedBetween(delete_begin, delete_end, &forms) && | 82 backend_->GetLoginsCreatedBetween(delete_begin, delete_end, &forms) && |
| 83 backend_->RemoveLoginsCreatedBetween(delete_begin, delete_end)) { | 83 backend_->RemoveLoginsCreatedBetween(delete_begin, delete_end)) { |
| 84 PasswordStoreChangeList changes; | 84 PasswordStoreChangeList changes; |
| 85 for (vector<PasswordForm*>::const_iterator it = forms.begin(); | 85 for (vector<PasswordForm*>::const_iterator it = forms.begin(); |
| 86 it != forms.end(); ++it) { | 86 it != forms.end(); ++it) { |
| 87 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, | 87 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, |
| 88 **it)); | 88 **it)); |
| 89 } | 89 } |
| 90 NotificationService::current()->Notify( | 90 NotificationService::current()->Notify( |
| 91 NotificationType::LOGINS_CHANGED, | 91 chrome::LOGINS_CHANGED, |
| 92 Source<PasswordStore>(this), | 92 Source<PasswordStore>(this), |
| 93 Details<PasswordStoreChangeList>(&changes)); | 93 Details<PasswordStoreChangeList>(&changes)); |
| 94 allow_fallback_ = false; | 94 allow_fallback_ = false; |
| 95 } else if (allow_default_store()) { | 95 } else if (allow_default_store()) { |
| 96 PasswordStoreDefault::RemoveLoginsCreatedBetweenImpl(delete_begin, | 96 PasswordStoreDefault::RemoveLoginsCreatedBetweenImpl(delete_begin, |
| 97 delete_end); | 97 delete_end); |
| 98 } | 98 } |
| 99 STLDeleteElements(&forms); | 99 STLDeleteElements(&forms); |
| 100 } | 100 } |
| 101 | 101 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 // it before deleting the file just in case there is some problem deleting | 254 // it before deleting the file just in case there is some problem deleting |
| 255 // the file (e.g. directory is not writable, but file is), which would | 255 // the file (e.g. directory is not writable, but file is), which would |
| 256 // otherwise cause passwords to re-migrate next (or maybe every) time. | 256 // otherwise cause passwords to re-migrate next (or maybe every) time. |
| 257 DeleteAndRecreateDatabaseFile(); | 257 DeleteAndRecreateDatabaseFile(); |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 ssize_t result = ok ? forms.size() : -1; | 260 ssize_t result = ok ? forms.size() : -1; |
| 261 STLDeleteElements(&forms); | 261 STLDeleteElements(&forms); |
| 262 return result; | 262 return result; |
| 263 } | 263 } |
| OLD | NEW |