| 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 "chrome/browser/password_manager/password_store_mac.h" | 7 #include "chrome/browser/password_manager/password_store_mac.h" |
| 8 #include "chrome/browser/password_manager/simple_password_store_mac.h" | 8 #include "chrome/browser/password_manager/simple_password_store_mac.h" |
| 9 #include "content/public/browser/browser_thread.h" |
| 9 #include "crypto/apple_keychain.h" | 10 #include "crypto/apple_keychain.h" |
| 10 | 11 |
| 11 using password_manager::PasswordStoreChangeList; | 12 using password_manager::PasswordStoreChangeList; |
| 12 | 13 |
| 13 PasswordStoreProxyMac::PasswordStoreProxyMac( | 14 PasswordStoreProxyMac::PasswordStoreProxyMac( |
| 14 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, | 15 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, |
| 15 scoped_ptr<crypto::AppleKeychain> keychain, | 16 scoped_ptr<crypto::AppleKeychain> keychain, |
| 16 scoped_ptr<password_manager::LoginDatabase> login_db) | 17 scoped_ptr<password_manager::LoginDatabase> login_db) |
| 17 : PasswordStore(main_thread_runner, nullptr) { | 18 : PasswordStore(main_thread_runner, nullptr), |
| 19 login_metadata_db_(login_db.Pass()) { |
| 20 DCHECK(login_metadata_db_); |
| 18 // TODO(vasilii): for now the class is just a wrapper around PasswordStoreMac. | 21 // TODO(vasilii): for now the class is just a wrapper around PasswordStoreMac. |
| 19 password_store_mac_ = new PasswordStoreMac(main_thread_runner, nullptr, | 22 password_store_mac_ = new PasswordStoreMac( |
| 20 keychain.Pass(), login_db.Pass()); | 23 main_thread_runner, nullptr, keychain.Pass(), login_metadata_db_.get()); |
| 21 } | 24 } |
| 22 | 25 |
| 23 PasswordStoreProxyMac::~PasswordStoreProxyMac() { | 26 PasswordStoreProxyMac::~PasswordStoreProxyMac() { |
| 24 } | 27 } |
| 25 | 28 |
| 26 bool PasswordStoreProxyMac::Init( | 29 bool PasswordStoreProxyMac::Init( |
| 27 const syncer::SyncableService::StartSyncFlare& flare) { | 30 const syncer::SyncableService::StartSyncFlare& flare) { |
| 28 return GetBackend()->Init(flare); | 31 // Set up a background thread. |
| 32 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 33 thread_.reset(new base::Thread("Chrome_PasswordStore_Thread")); |
| 34 |
| 35 if (!thread_->Start()) { |
| 36 thread_.reset(); |
| 37 return false; |
| 38 } |
| 39 |
| 40 ScheduleTask( |
| 41 base::Bind(&PasswordStoreProxyMac::InitOnBackgroundThread, this)); |
| 42 password_store_mac_->InitWithTaskRunner(GetBackgroundTaskRunner()); |
| 43 return password_manager::PasswordStore::Init(flare); |
| 29 } | 44 } |
| 30 | 45 |
| 31 void PasswordStoreProxyMac::Shutdown() { | 46 void PasswordStoreProxyMac::Shutdown() { |
| 32 return GetBackend()->Shutdown(); | 47 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 48 PasswordStore::Shutdown(); |
| 49 GetBackend()->Shutdown(); |
| 50 thread_->Stop(); |
| 51 } |
| 52 |
| 53 scoped_refptr<base::SingleThreadTaskRunner> |
| 54 PasswordStoreProxyMac::GetBackgroundTaskRunner() { |
| 55 return thread_ ? thread_->task_runner() : nullptr; |
| 33 } | 56 } |
| 34 | 57 |
| 35 password_manager::PasswordStore* PasswordStoreProxyMac::GetBackend() const { | 58 password_manager::PasswordStore* PasswordStoreProxyMac::GetBackend() const { |
| 36 if (password_store_mac_) | 59 if (password_store_mac_) |
| 37 return password_store_mac_.get(); | 60 return password_store_mac_.get(); |
| 38 return password_store_simple_.get(); | 61 return password_store_simple_.get(); |
| 39 } | 62 } |
| 40 | 63 |
| 41 scoped_refptr<base::SingleThreadTaskRunner> | 64 void PasswordStoreProxyMac::InitOnBackgroundThread() { |
| 42 PasswordStoreProxyMac::GetBackgroundTaskRunner() { | 65 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); |
| 43 return GetBackend()->GetBackgroundTaskRunner(); | 66 if (!login_metadata_db_->Init()) { |
| 67 login_metadata_db_.reset(); |
| 68 LOG(ERROR) << "Could not create/open login database."; |
| 69 } |
| 44 } | 70 } |
| 45 | 71 |
| 46 void PasswordStoreProxyMac::ReportMetricsImpl( | 72 void PasswordStoreProxyMac::ReportMetricsImpl( |
| 47 const std::string& sync_username, | 73 const std::string& sync_username, |
| 48 bool custom_passphrase_sync_enabled) { | 74 bool custom_passphrase_sync_enabled) { |
| 49 GetBackend()->ReportMetricsImpl(sync_username, | 75 GetBackend()->ReportMetricsImpl(sync_username, |
| 50 custom_passphrase_sync_enabled); | 76 custom_passphrase_sync_enabled); |
| 51 } | 77 } |
| 52 | 78 |
| 53 PasswordStoreChangeList PasswordStoreProxyMac::AddLoginImpl( | 79 PasswordStoreChangeList PasswordStoreProxyMac::AddLoginImpl( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 76 base::Time delete_end) { | 102 base::Time delete_end) { |
| 77 return GetBackend()->RemoveLoginsSyncedBetweenImpl(delete_begin, delete_end); | 103 return GetBackend()->RemoveLoginsSyncedBetweenImpl(delete_begin, delete_end); |
| 78 } | 104 } |
| 79 | 105 |
| 80 ScopedVector<autofill::PasswordForm> PasswordStoreProxyMac::FillMatchingLogins( | 106 ScopedVector<autofill::PasswordForm> PasswordStoreProxyMac::FillMatchingLogins( |
| 81 const autofill::PasswordForm& form, | 107 const autofill::PasswordForm& form, |
| 82 AuthorizationPromptPolicy prompt_policy) { | 108 AuthorizationPromptPolicy prompt_policy) { |
| 83 return GetBackend()->FillMatchingLogins(form, prompt_policy); | 109 return GetBackend()->FillMatchingLogins(form, prompt_policy); |
| 84 } | 110 } |
| 85 | 111 |
| 86 void PasswordStoreProxyMac::GetAutofillableLoginsImpl( | |
| 87 scoped_ptr<PasswordStore::GetLoginsRequest> request) { | |
| 88 GetBackend()->GetAutofillableLoginsImpl(request.Pass()); | |
| 89 } | |
| 90 | |
| 91 void PasswordStoreProxyMac::GetBlacklistLoginsImpl( | |
| 92 scoped_ptr<PasswordStore::GetLoginsRequest> request) { | |
| 93 GetBackend()->GetBlacklistLoginsImpl(request.Pass()); | |
| 94 } | |
| 95 | |
| 96 bool PasswordStoreProxyMac::FillAutofillableLogins( | 112 bool PasswordStoreProxyMac::FillAutofillableLogins( |
| 97 ScopedVector<autofill::PasswordForm>* forms) { | 113 ScopedVector<autofill::PasswordForm>* forms) { |
| 98 return GetBackend()->FillAutofillableLogins(forms); | 114 return GetBackend()->FillAutofillableLogins(forms); |
| 99 } | 115 } |
| 100 | 116 |
| 101 bool PasswordStoreProxyMac::FillBlacklistLogins( | 117 bool PasswordStoreProxyMac::FillBlacklistLogins( |
| 102 ScopedVector<autofill::PasswordForm>* forms) { | 118 ScopedVector<autofill::PasswordForm>* forms) { |
| 103 return GetBackend()->FillBlacklistLogins(forms); | 119 return GetBackend()->FillBlacklistLogins(forms); |
| 104 } | 120 } |
| 105 | 121 |
| 106 void PasswordStoreProxyMac::AddSiteStatsImpl( | 122 void PasswordStoreProxyMac::AddSiteStatsImpl( |
| 107 const password_manager::InteractionsStats& stats) { | 123 const password_manager::InteractionsStats& stats) { |
| 108 GetBackend()->AddSiteStatsImpl(stats); | 124 GetBackend()->AddSiteStatsImpl(stats); |
| 109 } | 125 } |
| 110 | 126 |
| 111 void PasswordStoreProxyMac::RemoveSiteStatsImpl(const GURL& origin_domain) { | 127 void PasswordStoreProxyMac::RemoveSiteStatsImpl(const GURL& origin_domain) { |
| 112 GetBackend()->RemoveSiteStatsImpl(origin_domain); | 128 GetBackend()->RemoveSiteStatsImpl(origin_domain); |
| 113 } | 129 } |
| 114 | 130 |
| 115 scoped_ptr<password_manager::InteractionsStats> | 131 scoped_ptr<password_manager::InteractionsStats> |
| 116 PasswordStoreProxyMac::GetSiteStatsImpl(const GURL& origin_domain) { | 132 PasswordStoreProxyMac::GetSiteStatsImpl(const GURL& origin_domain) { |
| 117 return GetBackend()->GetSiteStatsImpl(origin_domain); | 133 return GetBackend()->GetSiteStatsImpl(origin_domain); |
| 118 } | 134 } |
| OLD | NEW |