| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/crypto_module_delegate_nss.h" | 5 #include "chrome/browser/ui/crypto_module_delegate_nss.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "chrome/browser/net/nss_context.h" | 10 #include "chrome/browser/net/nss_context.h" |
| 9 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 10 | 12 |
| 11 using content::BrowserThread; | 13 using content::BrowserThread; |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 void CreateWithSlot(chrome::CryptoModulePasswordReason reason, | 17 void CreateWithSlot(chrome::CryptoModulePasswordReason reason, |
| 16 const net::HostPortPair& server, | 18 const net::HostPortPair& server, |
| 17 const base::Callback<void( | 19 const base::Callback<void( |
| 18 scoped_ptr<ChromeNSSCryptoModuleDelegate>)>& callback, | 20 scoped_ptr<ChromeNSSCryptoModuleDelegate>)>& callback, |
| 19 crypto::ScopedPK11Slot slot) { | 21 crypto::ScopedPK11Slot slot) { |
| 20 if (!slot) { | 22 if (!slot) { |
| 21 callback.Run(scoped_ptr<ChromeNSSCryptoModuleDelegate>()); | 23 callback.Run(scoped_ptr<ChromeNSSCryptoModuleDelegate>()); |
| 22 return; | 24 return; |
| 23 } | 25 } |
| 24 callback.Run(scoped_ptr<ChromeNSSCryptoModuleDelegate>( | 26 callback.Run(scoped_ptr<ChromeNSSCryptoModuleDelegate>( |
| 25 new ChromeNSSCryptoModuleDelegate(reason, server, slot.Pass()))); | 27 new ChromeNSSCryptoModuleDelegate(reason, server, std::move(slot)))); |
| 26 } | 28 } |
| 27 | 29 |
| 28 } // namespace | 30 } // namespace |
| 29 | 31 |
| 30 ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate( | 32 ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate( |
| 31 chrome::CryptoModulePasswordReason reason, | 33 chrome::CryptoModulePasswordReason reason, |
| 32 const net::HostPortPair& server, | 34 const net::HostPortPair& server, |
| 33 crypto::ScopedPK11Slot slot) | 35 crypto::ScopedPK11Slot slot) |
| 34 : reason_(reason), | 36 : reason_(reason), |
| 35 server_(server), | 37 server_(server), |
| 36 event_(false, false), | 38 event_(false, false), |
| 37 cancelled_(false), | 39 cancelled_(false), |
| 38 slot_(slot.Pass()) { | 40 slot_(std::move(slot)) {} |
| 39 } | |
| 40 | 41 |
| 41 ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {} | 42 ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {} |
| 42 | 43 |
| 43 // static | 44 // static |
| 44 void ChromeNSSCryptoModuleDelegate::CreateForResourceContext( | 45 void ChromeNSSCryptoModuleDelegate::CreateForResourceContext( |
| 45 chrome::CryptoModulePasswordReason reason, | 46 chrome::CryptoModulePasswordReason reason, |
| 46 const net::HostPortPair& server, | 47 const net::HostPortPair& server, |
| 47 content::ResourceContext* context, | 48 content::ResourceContext* context, |
| 48 const base::Callback<void(scoped_ptr<ChromeNSSCryptoModuleDelegate>)>& | 49 const base::Callback<void(scoped_ptr<ChromeNSSCryptoModuleDelegate>)>& |
| 49 callback) { | 50 callback) { |
| 50 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 51 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 51 DCHECK(!callback.is_null()); | 52 DCHECK(!callback.is_null()); |
| 52 | 53 |
| 53 base::Callback<void(crypto::ScopedPK11Slot)> get_slot_callback = | 54 base::Callback<void(crypto::ScopedPK11Slot)> get_slot_callback = |
| 54 base::Bind(&CreateWithSlot, reason, server, callback); | 55 base::Bind(&CreateWithSlot, reason, server, callback); |
| 55 | 56 |
| 56 crypto::ScopedPK11Slot slot = | 57 crypto::ScopedPK11Slot slot = |
| 57 GetPrivateNSSKeySlotForResourceContext(context, get_slot_callback); | 58 GetPrivateNSSKeySlotForResourceContext(context, get_slot_callback); |
| 58 if (slot) | 59 if (slot) |
| 59 get_slot_callback.Run(slot.Pass()); | 60 get_slot_callback.Run(std::move(slot)); |
| 60 } | 61 } |
| 61 | 62 |
| 62 // TODO(mattm): allow choosing which slot to generate and store the key. | 63 // TODO(mattm): allow choosing which slot to generate and store the key. |
| 63 crypto::ScopedPK11Slot ChromeNSSCryptoModuleDelegate::RequestSlot() { | 64 crypto::ScopedPK11Slot ChromeNSSCryptoModuleDelegate::RequestSlot() { |
| 64 return slot_.Pass(); | 65 return std::move(slot_); |
| 65 } | 66 } |
| 66 | 67 |
| 67 std::string ChromeNSSCryptoModuleDelegate::RequestPassword( | 68 std::string ChromeNSSCryptoModuleDelegate::RequestPassword( |
| 68 const std::string& slot_name, | 69 const std::string& slot_name, |
| 69 bool retry, | 70 bool retry, |
| 70 bool* cancelled) { | 71 bool* cancelled) { |
| 71 DCHECK(!event_.IsSignaled()); | 72 DCHECK(!event_.IsSignaled()); |
| 72 event_.Reset(); | 73 event_.Reset(); |
| 73 | 74 |
| 74 if (BrowserThread::PostTask( | 75 if (BrowserThread::PostTask( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 crypto::CryptoModuleBlockingPasswordDelegate* | 113 crypto::CryptoModuleBlockingPasswordDelegate* |
| 113 CreateCryptoModuleBlockingPasswordDelegate( | 114 CreateCryptoModuleBlockingPasswordDelegate( |
| 114 chrome::CryptoModulePasswordReason reason, | 115 chrome::CryptoModulePasswordReason reason, |
| 115 const net::HostPortPair& server) { | 116 const net::HostPortPair& server) { |
| 116 // Returns a ChromeNSSCryptoModuleDelegate without Pk11Slot. Since it is only | 117 // Returns a ChromeNSSCryptoModuleDelegate without Pk11Slot. Since it is only |
| 117 // being used as a CryptoModuleBlockingDialogDelegate, using a slot handle is | 118 // being used as a CryptoModuleBlockingDialogDelegate, using a slot handle is |
| 118 // unnecessary. | 119 // unnecessary. |
| 119 return new ChromeNSSCryptoModuleDelegate( | 120 return new ChromeNSSCryptoModuleDelegate( |
| 120 reason, server, crypto::ScopedPK11Slot()); | 121 reason, server, crypto::ScopedPK11Slot()); |
| 121 } | 122 } |
| OLD | NEW |