| 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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "chrome/browser/password_manager/password_store_change.h" | 14 #include "chrome/browser/password_manager/password_store_change.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
| 18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| 19 #include "content/common/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 20 | 20 |
| 21 using std::vector; | 21 using std::vector; |
| 22 using webkit_glue::PasswordForm; | 22 using webkit_glue::PasswordForm; |
| 23 | 23 |
| 24 PasswordStoreX::PasswordStoreX(LoginDatabase* login_db, | 24 PasswordStoreX::PasswordStoreX(LoginDatabase* login_db, |
| 25 Profile* profile, | 25 Profile* profile, |
| 26 WebDataService* web_data_service, | 26 WebDataService* web_data_service, |
| 27 NativeBackend* backend) | 27 NativeBackend* backend) |
| 28 : PasswordStoreDefault(login_db, profile, web_data_service), | 28 : PasswordStoreDefault(login_db, profile, web_data_service), |
| 29 backend_(backend), migration_checked_(!backend), allow_fallback_(false) { | 29 backend_(backend), migration_checked_(!backend), allow_fallback_(false) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 PasswordStoreX::~PasswordStoreX() { | 32 PasswordStoreX::~PasswordStoreX() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 void PasswordStoreX::AddLoginImpl(const PasswordForm& form) { | 35 void PasswordStoreX::AddLoginImpl(const PasswordForm& form) { |
| 36 CheckMigration(); | 36 CheckMigration(); |
| 37 if (use_native_backend() && backend_->AddLogin(form)) { | 37 if (use_native_backend() && backend_->AddLogin(form)) { |
| 38 PasswordStoreChangeList changes; | 38 PasswordStoreChangeList changes; |
| 39 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); | 39 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form)); |
| 40 NotificationService::current()->Notify( | 40 content::NotificationService::current()->Notify( |
| 41 chrome::NOTIFICATION_LOGINS_CHANGED, | 41 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 42 content::Source<PasswordStore>(this), | 42 content::Source<PasswordStore>(this), |
| 43 content::Details<PasswordStoreChangeList>(&changes)); | 43 content::Details<PasswordStoreChangeList>(&changes)); |
| 44 allow_fallback_ = false; | 44 allow_fallback_ = false; |
| 45 } else if (allow_default_store()) { | 45 } else if (allow_default_store()) { |
| 46 PasswordStoreDefault::AddLoginImpl(form); | 46 PasswordStoreDefault::AddLoginImpl(form); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 void PasswordStoreX::UpdateLoginImpl(const PasswordForm& form) { | 50 void PasswordStoreX::UpdateLoginImpl(const PasswordForm& form) { |
| 51 CheckMigration(); | 51 CheckMigration(); |
| 52 if (use_native_backend() && backend_->UpdateLogin(form)) { | 52 if (use_native_backend() && backend_->UpdateLogin(form)) { |
| 53 PasswordStoreChangeList changes; | 53 PasswordStoreChangeList changes; |
| 54 changes.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form)); | 54 changes.push_back(PasswordStoreChange(PasswordStoreChange::UPDATE, form)); |
| 55 NotificationService::current()->Notify( | 55 content::NotificationService::current()->Notify( |
| 56 chrome::NOTIFICATION_LOGINS_CHANGED, | 56 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 57 content::Source<PasswordStore>(this), | 57 content::Source<PasswordStore>(this), |
| 58 content::Details<PasswordStoreChangeList>(&changes)); | 58 content::Details<PasswordStoreChangeList>(&changes)); |
| 59 allow_fallback_ = false; | 59 allow_fallback_ = false; |
| 60 } else if (allow_default_store()) { | 60 } else if (allow_default_store()) { |
| 61 PasswordStoreDefault::UpdateLoginImpl(form); | 61 PasswordStoreDefault::UpdateLoginImpl(form); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 void PasswordStoreX::RemoveLoginImpl(const PasswordForm& form) { | 65 void PasswordStoreX::RemoveLoginImpl(const PasswordForm& form) { |
| 66 CheckMigration(); | 66 CheckMigration(); |
| 67 if (use_native_backend() && backend_->RemoveLogin(form)) { | 67 if (use_native_backend() && backend_->RemoveLogin(form)) { |
| 68 PasswordStoreChangeList changes; | 68 PasswordStoreChangeList changes; |
| 69 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); | 69 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); |
| 70 NotificationService::current()->Notify( | 70 content::NotificationService::current()->Notify( |
| 71 chrome::NOTIFICATION_LOGINS_CHANGED, | 71 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 72 content::Source<PasswordStore>(this), | 72 content::Source<PasswordStore>(this), |
| 73 content::Details<PasswordStoreChangeList>(&changes)); | 73 content::Details<PasswordStoreChangeList>(&changes)); |
| 74 allow_fallback_ = false; | 74 allow_fallback_ = false; |
| 75 } else if (allow_default_store()) { | 75 } else if (allow_default_store()) { |
| 76 PasswordStoreDefault::RemoveLoginImpl(form); | 76 PasswordStoreDefault::RemoveLoginImpl(form); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 | 79 |
| 80 void PasswordStoreX::RemoveLoginsCreatedBetweenImpl( | 80 void PasswordStoreX::RemoveLoginsCreatedBetweenImpl( |
| 81 const base::Time& delete_begin, | 81 const base::Time& delete_begin, |
| 82 const base::Time& delete_end) { | 82 const base::Time& delete_end) { |
| 83 CheckMigration(); | 83 CheckMigration(); |
| 84 vector<PasswordForm*> forms; | 84 vector<PasswordForm*> forms; |
| 85 if (use_native_backend() && | 85 if (use_native_backend() && |
| 86 backend_->GetLoginsCreatedBetween(delete_begin, delete_end, &forms) && | 86 backend_->GetLoginsCreatedBetween(delete_begin, delete_end, &forms) && |
| 87 backend_->RemoveLoginsCreatedBetween(delete_begin, delete_end)) { | 87 backend_->RemoveLoginsCreatedBetween(delete_begin, delete_end)) { |
| 88 PasswordStoreChangeList changes; | 88 PasswordStoreChangeList changes; |
| 89 for (vector<PasswordForm*>::const_iterator it = forms.begin(); | 89 for (vector<PasswordForm*>::const_iterator it = forms.begin(); |
| 90 it != forms.end(); ++it) { | 90 it != forms.end(); ++it) { |
| 91 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, | 91 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, |
| 92 **it)); | 92 **it)); |
| 93 } | 93 } |
| 94 NotificationService::current()->Notify( | 94 content::NotificationService::current()->Notify( |
| 95 chrome::NOTIFICATION_LOGINS_CHANGED, | 95 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 96 content::Source<PasswordStore>(this), | 96 content::Source<PasswordStore>(this), |
| 97 content::Details<PasswordStoreChangeList>(&changes)); | 97 content::Details<PasswordStoreChangeList>(&changes)); |
| 98 allow_fallback_ = false; | 98 allow_fallback_ = false; |
| 99 } else if (allow_default_store()) { | 99 } else if (allow_default_store()) { |
| 100 PasswordStoreDefault::RemoveLoginsCreatedBetweenImpl(delete_begin, | 100 PasswordStoreDefault::RemoveLoginsCreatedBetweenImpl(delete_begin, |
| 101 delete_end); | 101 delete_end); |
| 102 } | 102 } |
| 103 STLDeleteElements(&forms); | 103 STLDeleteElements(&forms); |
| 104 } | 104 } |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 } // anonymous namespace | 294 } // anonymous namespace |
| 295 | 295 |
| 296 // static | 296 // static |
| 297 void PasswordStoreX::SetPasswordsUseLocalProfileId(PrefService* prefs) { | 297 void PasswordStoreX::SetPasswordsUseLocalProfileId(PrefService* prefs) { |
| 298 // This method should work on any thread, but we expect the DB thread. | 298 // This method should work on any thread, but we expect the DB thread. |
| 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 300 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 300 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 301 base::Bind(UISetPasswordsUseLocalProfileId, prefs)); | 301 base::Bind(UISetPasswordsUseLocalProfileId, prefs)); |
| 302 } | 302 } |
| 303 #endif // !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) | 303 #endif // !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) |
| OLD | NEW |