Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_proxy_mac.h" | 5 #include "chrome/browser/password_manager/password_store_proxy_mac.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | |
| 7 #include "chrome/browser/password_manager/password_store_mac.h" | 8 #include "chrome/browser/password_manager/password_store_mac.h" |
| 8 #include "chrome/browser/password_manager/simple_password_store_mac.h" | 9 #include "chrome/browser/password_manager/simple_password_store_mac.h" |
| 10 #include "components/password_manager/core/common/password_manager_pref_names.h" | |
| 9 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 10 #include "crypto/apple_keychain.h" | 12 #include "crypto/apple_keychain.h" |
| 11 | 13 |
| 12 using password_manager::PasswordStoreChangeList; | 14 using password_manager::PasswordStoreChangeList; |
| 13 | 15 |
| 14 PasswordStoreProxyMac::PasswordStoreProxyMac( | 16 PasswordStoreProxyMac::PasswordStoreProxyMac( |
| 15 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, | 17 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, |
| 16 scoped_ptr<crypto::AppleKeychain> keychain, | 18 scoped_ptr<crypto::AppleKeychain> keychain, |
| 17 scoped_ptr<password_manager::LoginDatabase> login_db) | 19 scoped_ptr<password_manager::LoginDatabase> login_db, |
| 20 PrefService* prefs) | |
| 18 : PasswordStore(main_thread_runner, nullptr), | 21 : PasswordStore(main_thread_runner, nullptr), |
| 19 login_metadata_db_(login_db.Pass()) { | 22 login_metadata_db_(login_db.Pass()), |
| 23 migration_completion_(true, false) { | |
| 20 DCHECK(login_metadata_db_); | 24 DCHECK(login_metadata_db_); |
| 21 // TODO(vasilii): for now the class is just a wrapper around PasswordStoreMac. | 25 migration_status_.Init(password_manager::prefs::kKeychainMigrationStatus, |
| 22 password_store_mac_ = | 26 prefs); |
| 23 new PasswordStoreMac(main_thread_runner, nullptr, keychain.Pass()); | 27 if (migration_status_.GetValue() == MIGRATED) { |
| 28 // The login database will be set later after initialization. | |
| 29 password_store_simple_ = new SimplePasswordStoreMac( | |
| 30 main_thread_runner, nullptr, | |
| 31 scoped_ptr<password_manager::LoginDatabase>()); | |
|
vabr (Chromium)
2015/07/03 08:40:48
optional: I believe nullptr should work here as we
vasilii
2015/07/03 12:59:11
Done.
| |
| 32 } else { | |
| 33 password_store_mac_ = | |
| 34 new PasswordStoreMac(main_thread_runner, nullptr, keychain.Pass()); | |
| 35 } | |
| 24 } | 36 } |
| 25 | 37 |
| 26 PasswordStoreProxyMac::~PasswordStoreProxyMac() { | 38 PasswordStoreProxyMac::~PasswordStoreProxyMac() { |
| 27 } | 39 } |
| 28 | 40 |
| 29 bool PasswordStoreProxyMac::Init( | 41 bool PasswordStoreProxyMac::Init( |
| 30 const syncer::SyncableService::StartSyncFlare& flare) { | 42 const syncer::SyncableService::StartSyncFlare& flare) { |
| 31 // Set up a background thread. | 43 // Set up a background thread. |
| 32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 33 thread_.reset(new base::Thread("Chrome_PasswordStore_Thread")); | 45 thread_.reset(new base::Thread("Chrome_PasswordStore_Thread")); |
| 34 | 46 |
| 35 if (!thread_->Start()) { | 47 if (!thread_->Start()) { |
| 36 thread_.reset(); | 48 thread_.reset(); |
| 37 return false; | 49 return false; |
| 38 } | 50 } |
| 39 | 51 |
| 40 ScheduleTask( | 52 if (!password_manager::PasswordStore::Init(flare)) |
| 41 base::Bind(&PasswordStoreProxyMac::InitOnBackgroundThread, this)); | 53 return false; |
| 42 password_store_mac_->InitWithTaskRunner(GetBackgroundTaskRunner()); | 54 |
| 43 return password_manager::PasswordStore::Init(flare); | 55 return ScheduleTask( |
| 56 base::Bind(&PasswordStoreProxyMac::InitOnBackgroundThread, this, | |
| 57 static_cast<MigrationStatus>(migration_status_.GetValue()))); | |
| 44 } | 58 } |
| 45 | 59 |
| 46 void PasswordStoreProxyMac::Shutdown() { | 60 void PasswordStoreProxyMac::Shutdown() { |
| 47 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 61 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 48 PasswordStore::Shutdown(); | 62 PasswordStore::Shutdown(); |
| 63 // Wait for InitOnBackgroundThread completion so GetBackend() returns a | |
| 64 // correct pointer. | |
| 65 migration_completion_.Wait(); | |
| 49 GetBackend()->Shutdown(); | 66 GetBackend()->Shutdown(); |
| 50 thread_->Stop(); | 67 thread_->Stop(); |
| 51 } | 68 } |
| 52 | 69 |
| 53 scoped_refptr<base::SingleThreadTaskRunner> | 70 scoped_refptr<base::SingleThreadTaskRunner> |
| 54 PasswordStoreProxyMac::GetBackgroundTaskRunner() { | 71 PasswordStoreProxyMac::GetBackgroundTaskRunner() { |
| 55 return thread_ ? thread_->task_runner() : nullptr; | 72 return thread_ ? thread_->task_runner() : nullptr; |
| 56 } | 73 } |
| 57 | 74 |
| 58 password_manager::PasswordStore* PasswordStoreProxyMac::GetBackend() const { | 75 password_manager::PasswordStore* PasswordStoreProxyMac::GetBackend() const { |
| 59 if (password_store_mac_) | 76 if (password_store_mac_) |
| 60 return password_store_mac_.get(); | 77 return password_store_mac_.get(); |
| 61 return password_store_simple_.get(); | 78 return password_store_simple_.get(); |
| 62 } | 79 } |
| 63 | 80 |
| 64 void PasswordStoreProxyMac::InitOnBackgroundThread() { | 81 void PasswordStoreProxyMac::InitOnBackgroundThread(MigrationStatus status) { |
| 65 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); | 82 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); |
| 66 if (!login_metadata_db_->Init()) { | 83 if (!login_metadata_db_->Init()) { |
| 67 login_metadata_db_.reset(); | 84 login_metadata_db_.reset(); |
| 68 LOG(ERROR) << "Could not create/open login database."; | 85 LOG(ERROR) << "Could not create/open login database."; |
| 69 return; | |
| 70 } | 86 } |
| 71 if (password_store_mac_) | 87 |
| 88 if (status == MIGRATED) { | |
| 89 password_store_simple_->InitWithTaskRunner(GetBackgroundTaskRunner(), | |
| 90 login_metadata_db_.Pass()); | |
| 91 } else { | |
| 72 password_store_mac_->set_login_metadata_db(login_metadata_db_.get()); | 92 password_store_mac_->set_login_metadata_db(login_metadata_db_.get()); |
| 93 password_store_mac_->InitWithTaskRunner(GetBackgroundTaskRunner()); | |
| 94 if (login_metadata_db_ && | |
| 95 (status == NOT_STARTED || status == FAILED_ONCE)) { | |
| 96 // Let's try to migrate the passwords. | |
| 97 if (password_store_mac_->ImportFromKeychain() == | |
| 98 PasswordStoreMac::MIGRATION_OK) { | |
| 99 status = MIGRATED; | |
| 100 // Switch from |password_store_mac_| to |password_store_simple_|. | |
| 101 password_store_mac_->set_login_metadata_db(nullptr); | |
| 102 main_thread_runner_->PostTask( | |
| 103 FROM_HERE, | |
| 104 base::Bind(&PasswordStoreMac::Shutdown, password_store_mac_)); | |
| 105 password_store_mac_ = nullptr; | |
| 106 password_store_simple_ = new SimplePasswordStoreMac( | |
| 107 main_thread_runner_, GetBackgroundTaskRunner(), | |
| 108 login_metadata_db_.Pass()); | |
| 109 } else { | |
| 110 status = (status == FAILED_ONCE ? FAILED_TWICE : FAILED_ONCE); | |
| 111 } | |
| 112 main_thread_runner_->PostTask( | |
| 113 FROM_HERE, | |
| 114 base::Bind(&PasswordStoreProxyMac::UpdateStatusPref, this, status)); | |
| 115 } | |
| 116 } | |
| 117 migration_completion_.Signal(); | |
| 118 ReportStatusPref(status); | |
| 119 DCHECK(GetBackend()); | |
| 120 } | |
| 121 | |
| 122 void PasswordStoreProxyMac::UpdateStatusPref(MigrationStatus status) { | |
| 123 migration_status_.SetValue(status); | |
| 124 } | |
| 125 | |
| 126 // static | |
| 127 void PasswordStoreProxyMac::ReportStatusPref(MigrationStatus status) { | |
| 128 UMA_HISTOGRAM_ENUMERATION("PasswordManager.KeychainMigration.Status", status, | |
| 129 NUM_MIGRATION_STATUS); | |
| 73 } | 130 } |
| 74 | 131 |
| 75 void PasswordStoreProxyMac::ReportMetricsImpl( | 132 void PasswordStoreProxyMac::ReportMetricsImpl( |
| 76 const std::string& sync_username, | 133 const std::string& sync_username, |
| 77 bool custom_passphrase_sync_enabled) { | 134 bool custom_passphrase_sync_enabled) { |
| 78 GetBackend()->ReportMetricsImpl(sync_username, | 135 GetBackend()->ReportMetricsImpl(sync_username, |
| 79 custom_passphrase_sync_enabled); | 136 custom_passphrase_sync_enabled); |
| 80 } | 137 } |
| 81 | 138 |
| 82 PasswordStoreChangeList PasswordStoreProxyMac::AddLoginImpl( | 139 PasswordStoreChangeList PasswordStoreProxyMac::AddLoginImpl( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 } | 185 } |
| 129 | 186 |
| 130 void PasswordStoreProxyMac::RemoveSiteStatsImpl(const GURL& origin_domain) { | 187 void PasswordStoreProxyMac::RemoveSiteStatsImpl(const GURL& origin_domain) { |
| 131 GetBackend()->RemoveSiteStatsImpl(origin_domain); | 188 GetBackend()->RemoveSiteStatsImpl(origin_domain); |
| 132 } | 189 } |
| 133 | 190 |
| 134 scoped_ptr<password_manager::InteractionsStats> | 191 scoped_ptr<password_manager::InteractionsStats> |
| 135 PasswordStoreProxyMac::GetSiteStatsImpl(const GURL& origin_domain) { | 192 PasswordStoreProxyMac::GetSiteStatsImpl(const GURL& origin_domain) { |
| 136 return GetBackend()->GetSiteStatsImpl(origin_domain); | 193 return GetBackend()->GetSiteStatsImpl(origin_domain); |
| 137 } | 194 } |
| OLD | NEW |