| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/password_manager/password_store_proxy_mac.h" | |
| 6 | |
| 7 #include "base/metrics/histogram_macros.h" | |
| 8 #include "components/password_manager/core/common/password_manager_pref_names.h" | |
| 9 #include "content/public/browser/browser_thread.h" | |
| 10 | |
| 11 using password_manager::MigrationStatus; | |
| 12 | |
| 13 PasswordStoreProxyMac::PasswordStoreProxyMac( | |
| 14 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, | |
| 15 std::unique_ptr<password_manager::LoginDatabase> login_db, | |
| 16 PrefService* prefs) | |
| 17 : PasswordStoreDefault(main_thread_runner, nullptr, std::move(login_db)) { | |
| 18 migration_status_.Init(password_manager::prefs::kKeychainMigrationStatus, | |
| 19 prefs); | |
| 20 } | |
| 21 | |
| 22 bool PasswordStoreProxyMac::Init( | |
| 23 const syncer::SyncableService::StartSyncFlare& flare, | |
| 24 PrefService* prefs) { | |
| 25 // Set up a background thread. | |
| 26 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 27 thread_.reset(new base::Thread("Chrome_PasswordStore_Thread")); | |
| 28 | |
| 29 if (!thread_->Start()) { | |
| 30 thread_.reset(); | |
| 31 return false; | |
| 32 } | |
| 33 | |
| 34 if (PasswordStoreDefault::Init(flare, prefs)) { | |
| 35 return ScheduleTask( | |
| 36 base::Bind(&PasswordStoreProxyMac::InitOnBackgroundThread, this, | |
| 37 static_cast<MigrationStatus>(migration_status_.GetValue()))); | |
| 38 } | |
| 39 | |
| 40 return false; | |
| 41 } | |
| 42 | |
| 43 void PasswordStoreProxyMac::ShutdownOnUIThread() { | |
| 44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 45 PasswordStoreDefault::ShutdownOnUIThread(); | |
| 46 thread_->Stop(); | |
| 47 | |
| 48 // Unsubscribe the observer, otherwise it's too late in the destructor. | |
| 49 migration_status_.Destroy(); | |
| 50 } | |
| 51 | |
| 52 scoped_refptr<base::SingleThreadTaskRunner> | |
| 53 PasswordStoreProxyMac::GetBackgroundTaskRunner() { | |
| 54 return thread_ ? thread_->task_runner() : nullptr; | |
| 55 } | |
| 56 | |
| 57 PasswordStoreProxyMac::~PasswordStoreProxyMac() = default; | |
| 58 | |
| 59 void PasswordStoreProxyMac::InitOnBackgroundThread(MigrationStatus status) { | |
| 60 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); | |
| 61 | |
| 62 if (login_db() && (status == MigrationStatus::NOT_STARTED || | |
| 63 status == MigrationStatus::FAILED_ONCE || | |
| 64 status == MigrationStatus::FAILED_TWICE)) { | |
| 65 // Migration isn't possible due to Chrome changing the certificate. Just | |
| 66 // drop the entries in the DB because they don't have passwords anyway. | |
| 67 login_db()->RemoveLoginsCreatedBetween(base::Time(), base::Time()); | |
| 68 status = MigrationStatus::MIGRATION_STOPPED; | |
| 69 main_thread_runner_->PostTask( | |
| 70 FROM_HERE, | |
| 71 base::Bind(&PasswordStoreProxyMac::UpdateStatusPref, this, status)); | |
| 72 } | |
| 73 | |
| 74 UMA_HISTOGRAM_ENUMERATION( | |
| 75 "PasswordManager.KeychainMigration.Status", static_cast<int>(status), | |
| 76 static_cast<int>(MigrationStatus::MIGRATION_STATUS_COUNT)); | |
| 77 } | |
| 78 | |
| 79 void PasswordStoreProxyMac::UpdateStatusPref(MigrationStatus status) { | |
| 80 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 81 // The method can be called after ShutdownOnUIThread(). | |
| 82 if (migration_status_.prefs()) | |
| 83 migration_status_.SetValue(static_cast<int>(status)); | |
| 84 } | |
| OLD | NEW |