Chromium Code Reviews| Index: chrome/browser/chromeos/ownership/owner_settings_service_chromeos.cc |
| diff --git a/chrome/browser/chromeos/ownership/owner_settings_service_chromeos.cc b/chrome/browser/chromeos/ownership/owner_settings_service_chromeos.cc |
| index b4912e2fcca64cd5292374369a7410aa1d96732e..39a9d04d4dc6fe44fae7c3621e761e514dd079cc 100644 |
| --- a/chrome/browser/chromeos/ownership/owner_settings_service_chromeos.cc |
| +++ b/chrome/browser/chromeos/ownership/owner_settings_service_chromeos.cc |
| @@ -53,6 +53,10 @@ namespace chromeos { |
| namespace { |
| +using ReloadKeyCallback = |
| + base::Callback<void(const scoped_refptr<PublicKey>& public_key, |
| + const scoped_refptr<PrivateKey>& private_key)>; |
| + |
| bool IsOwnerInTests(const std::string& user_id) { |
| if (user_id.empty() || |
| !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| @@ -70,9 +74,7 @@ void LoadPrivateKeyByPublicKeyOnWorkerThread( |
| const scoped_refptr<OwnerKeyUtil>& owner_key_util, |
| crypto::ScopedPK11Slot public_slot, |
| crypto::ScopedPK11Slot private_slot, |
| - const base::Callback<void(const scoped_refptr<PublicKey>& public_key, |
| - const scoped_refptr<PrivateKey>& private_key)>& |
| - callback) { |
| + const ReloadKeyCallback& callback) { |
| DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| std::vector<uint8_t> public_key_data; |
| @@ -106,28 +108,39 @@ void LoadPrivateKeyByPublicKeyOnWorkerThread( |
| base::Bind(callback, public_key, private_key)); |
| } |
| -void LoadPrivateKeyOnIOThread( |
| +void ContinueLoadPrivateKeyOnIOThread( |
| const scoped_refptr<OwnerKeyUtil>& owner_key_util, |
| const std::string username_hash, |
| - const base::Callback<void(const scoped_refptr<PublicKey>& public_key, |
| - const scoped_refptr<PrivateKey>& private_key)>& |
| - callback) { |
| + const ReloadKeyCallback& callback, |
| + crypto::ScopedPK11Slot private_slot) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| - crypto::EnsureNSSInit(); |
| - crypto::ScopedPK11Slot public_slot = |
| - crypto::GetPublicSlotForChromeOSUser(username_hash); |
| - crypto::ScopedPK11Slot private_slot = crypto::GetPrivateSlotForChromeOSUser( |
| - username_hash, base::Callback<void(crypto::ScopedPK11Slot)>()); |
| - |
| scoped_refptr<base::TaskRunner> task_runner = |
| BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
| base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| task_runner->PostTask( |
| FROM_HERE, |
| - base::Bind(&LoadPrivateKeyByPublicKeyOnWorkerThread, owner_key_util, |
| - base::Passed(std::move(public_slot)), |
| - base::Passed(std::move(private_slot)), callback)); |
| + base::Bind( |
| + &LoadPrivateKeyByPublicKeyOnWorkerThread, owner_key_util, |
| + base::Passed(crypto::GetPublicSlotForChromeOSUser(username_hash)), |
| + base::Passed(std::move(private_slot)), callback)); |
| +} |
| + |
| +void LoadPrivateKeyOnIOThread(const scoped_refptr<OwnerKeyUtil>& owner_key_util, |
|
mattm
2017/04/06 18:00:52
Is it possible for this function to get called mul
xiyuan
2017/04/06 18:14:25
Yes, it is possible. I have seen two overlapping c
mattm
2017/04/06 18:23:27
If it's already happening and the code is fine wit
|
| + const std::string username_hash, |
| + const ReloadKeyCallback& callback) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| + |
| + crypto::EnsureNSSInit(); |
| + |
| + auto continue_load_private_key_callback = |
| + base::Bind(&ContinueLoadPrivateKeyOnIOThread, owner_key_util, |
| + username_hash, callback); |
| + |
| + crypto::ScopedPK11Slot private_slot = crypto::GetPrivateSlotForChromeOSUser( |
| + username_hash, continue_load_private_key_callback); |
| + if (private_slot) |
| + continue_load_private_key_callback.Run(std::move(private_slot)); |
| } |
| bool DoesPrivateKeyExistAsyncHelper( |