X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fchrome%2Fbrowser%2Fui%2Fcrypto_module_delegate_nss.cc;h=5812e5491eafe72163eea83e005b3faaa032ba66;hb=1afa4dd80ef85af7c90efaea6959db1d92330844;hp=4829a4ab320bfd940d1eab36c1a2adc74f5eddd7;hpb=90762837333c13ccf56f2ad88e4481fc71e8d281;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/chrome/browser/ui/crypto_module_delegate_nss.cc b/src/chrome/browser/ui/crypto_module_delegate_nss.cc index 4829a4a..5812e54 100644 --- a/src/chrome/browser/ui/crypto_module_delegate_nss.cc +++ b/src/chrome/browser/ui/crypto_module_delegate_nss.cc @@ -11,31 +11,53 @@ using content::BrowserThread; +namespace { + +void CreateWithSlot(chrome::CryptoModulePasswordReason reason, + const net::HostPortPair& server, + const base::Callback)>& callback, + crypto::ScopedPK11Slot slot) { + if (!slot) { + callback.Run(scoped_ptr()); + return; + } + callback.Run(scoped_ptr( + new ChromeNSSCryptoModuleDelegate(reason, server, slot.Pass()))); +} + +} // namespace + ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate( chrome::CryptoModulePasswordReason reason, - const net::HostPortPair& server) + const net::HostPortPair& server, + crypto::ScopedPK11Slot slot) : reason_(reason), server_(server), event_(false, false), - cancelled_(false) {} + cancelled_(false), + slot_(slot.Pass()) { +} ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {} -bool ChromeNSSCryptoModuleDelegate::InitializeSlot( +// static +void ChromeNSSCryptoModuleDelegate::CreateForResourceContext( + chrome::CryptoModulePasswordReason reason, + const net::HostPortPair& server, content::ResourceContext* context, - const base::Closure& initialization_complete_callback) { + const base::Callback)>& + callback) { DCHECK_CURRENTLY_ON(BrowserThread::IO); - DCHECK(!slot_); - base::Callback get_slot_callback; - if (!initialization_complete_callback.is_null()) - get_slot_callback = base::Bind(&ChromeNSSCryptoModuleDelegate::DidGetSlot, - // Caller is responsible for keeping |this| - // alive until the callback is run. - base::Unretained(this), - initialization_complete_callback); - - slot_ = GetPrivateNSSKeySlotForResourceContext(context, get_slot_callback); - return slot_.get() != NULL; + DCHECK(!callback.is_null()); + + base::Callback get_slot_callback = + base::Bind(&CreateWithSlot, reason, server, callback); + + crypto::ScopedPK11Slot slot = + GetPrivateNSSKeySlotForResourceContext(context, get_slot_callback); + if (slot) + get_slot_callback.Run(slot.Pass()); } // TODO(mattm): allow choosing which slot to generate and store the key. @@ -88,19 +110,13 @@ void ChromeNSSCryptoModuleDelegate::GotPassword(const std::string& password) { event_.Signal(); } -void ChromeNSSCryptoModuleDelegate::DidGetSlot(const base::Closure& callback, - crypto::ScopedPK11Slot slot) { - DCHECK(!slot_); - slot_ = slot.Pass(); - callback.Run(); -} - crypto::CryptoModuleBlockingPasswordDelegate* CreateCryptoModuleBlockingPasswordDelegate( chrome::CryptoModulePasswordReason reason, const net::HostPortPair& server) { - // Returns a ChromeNSSCryptoModuleDelegate without calling InitializeSlot. - // Since it is only being used as a CreateCryptoModuleBlockingDialogDelegate, - // initializing the slot handle is unnecessary. - return new ChromeNSSCryptoModuleDelegate(reason, server); + // Returns a ChromeNSSCryptoModuleDelegate without Pk11Slot. Since it is only + // being used as a CryptoModuleBlockingDialogDelegate, using a slot handle is + // unnecessary. + return new ChromeNSSCryptoModuleDelegate( + reason, server, crypto::ScopedPK11Slot()); }