This source file includes following definitions.
- cancelled_
- InitializeSlot
- RequestSlot
- RequestPassword
- ShowDialog
- GotPassword
- DidGetSlot
- CreateCryptoModuleBlockingPasswordDelegate
#include "chrome/browser/ui/crypto_module_delegate_nss.h"
#include "base/basictypes.h"
#include "base/bind.h"
#include "chrome/browser/net/nss_context.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
ChromeNSSCryptoModuleDelegate::ChromeNSSCryptoModuleDelegate(
chrome::CryptoModulePasswordReason reason,
const net::HostPortPair& server)
: reason_(reason),
server_(server),
event_(false, false),
cancelled_(false) {}
ChromeNSSCryptoModuleDelegate::~ChromeNSSCryptoModuleDelegate() {}
bool ChromeNSSCryptoModuleDelegate::InitializeSlot(
content::ResourceContext* context,
const base::Closure& initialization_complete_callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(!slot_);
base::Callback<void(crypto::ScopedPK11Slot)> get_slot_callback;
if (!initialization_complete_callback.is_null())
get_slot_callback = base::Bind(&ChromeNSSCryptoModuleDelegate::DidGetSlot,
base::Unretained(this),
initialization_complete_callback);
slot_ = GetPrivateNSSKeySlotForResourceContext(context, get_slot_callback);
return slot_.get() != NULL;
}
crypto::ScopedPK11Slot ChromeNSSCryptoModuleDelegate::RequestSlot() {
return slot_.Pass();
}
std::string ChromeNSSCryptoModuleDelegate::RequestPassword(
const std::string& slot_name,
bool retry,
bool* cancelled) {
DCHECK(!event_.IsSignaled());
event_.Reset();
if (BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
base::Bind(&ChromeNSSCryptoModuleDelegate::ShowDialog,
base::Unretained(this),
slot_name,
retry))) {
event_.Wait();
}
*cancelled = cancelled_;
return password_;
}
void ChromeNSSCryptoModuleDelegate::ShowDialog(const std::string& slot_name,
bool retry) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
ShowCryptoModulePasswordDialog(
slot_name,
retry,
reason_,
server_.host(),
NULL,
base::Bind(&ChromeNSSCryptoModuleDelegate::GotPassword,
base::Unretained(this)));
}
void ChromeNSSCryptoModuleDelegate::GotPassword(const std::string& password) {
if (!password.empty())
password_ = password;
else
cancelled_ = true;
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) {
return new ChromeNSSCryptoModuleDelegate(reason, server);
}