Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Unified Diff: chrome/browser/chromeos/cros/cert_library.cc

Issue 10332191: Remove TPMTokenInfoDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: _ Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | crypto/nss_util.h » ('j') | crypto/nss_util.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/cros/cert_library.cc
diff --git a/chrome/browser/chromeos/cros/cert_library.cc b/chrome/browser/chromeos/cros/cert_library.cc
index f2e1ee893f5648263d9161c384e5a82afa520da3..ef294ebe2474a1a541fa6aeadd45c7b4ea07cdde 100644
--- a/chrome/browser/chromeos/cros/cert_library.cc
+++ b/chrome/browser/chromeos/cros/cert_library.cc
@@ -95,97 +95,6 @@ string16 GetDisplayString(net::X509Certificate* cert, bool hardware_backed) {
}
}
-class RealTPMTokenInfoDelegate : public crypto::TPMTokenInfoDelegate {
- public:
- RealTPMTokenInfoDelegate();
- virtual ~RealTPMTokenInfoDelegate();
-
- // TPMTokenInfoDeleagte overrides:
- virtual void RequestIsTokenReady(
- base::Callback<void(bool result)> callback) const OVERRIDE;
- virtual void GetTokenInfo(std::string* token_name,
- std::string* user_pin) const OVERRIDE;
-
- private:
- // This method is used to implement RequestIsTokenReady.
- void OnPkcs11IsTpmTokenReady(base::Callback<void(bool result)> callback,
- DBusMethodCallStatus call_status,
- bool is_tpm_token_ready) const;
-
- // This method is used to implement RequestIsTokenReady.
- void OnPkcs11GetTpmTokenInfo(base::Callback<void(bool result)> callback,
- DBusMethodCallStatus call_status,
- const std::string& token_name,
- const std::string& user_pin) const;
-
- // These are mutable since we need to cache them in IsTokenReady().
- mutable bool token_ready_;
- mutable std::string token_name_;
- mutable std::string user_pin_;
- mutable base::WeakPtrFactory<RealTPMTokenInfoDelegate> weak_ptr_factory_;
-};
-
-RealTPMTokenInfoDelegate::RealTPMTokenInfoDelegate() : token_ready_(false),
- weak_ptr_factory_(this) {
-}
-
-RealTPMTokenInfoDelegate::~RealTPMTokenInfoDelegate() {}
-
-void RealTPMTokenInfoDelegate::RequestIsTokenReady(
- base::Callback<void(bool result)> callback) const {
- CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (token_ready_) {
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(callback, true));
- return;
- }
- DBusThreadManager::Get()->GetCryptohomeClient()->Pkcs11IsTpmTokenReady(
- base::Bind(&RealTPMTokenInfoDelegate::OnPkcs11IsTpmTokenReady,
- weak_ptr_factory_.GetWeakPtr(),
- callback));
-}
-
-void RealTPMTokenInfoDelegate::GetTokenInfo(std::string* token_name,
- std::string* user_pin) const {
- // May be called from a non UI thread, but must only be called after
- // IsTokenReady() returns true.
- CHECK(token_ready_);
- if (token_name)
- *token_name = token_name_;
- if (user_pin)
- *user_pin = user_pin_;
-}
-
-void RealTPMTokenInfoDelegate::OnPkcs11IsTpmTokenReady(
- base::Callback<void(bool result)> callback,
- DBusMethodCallStatus call_status,
- bool is_tpm_token_ready) const {
- if (call_status != DBUS_METHOD_CALL_SUCCESS || !is_tpm_token_ready) {
- callback.Run(false);
- return;
- }
-
- // Retrieve token_name_ and user_pin_ here since they will never change
- // and CryptohomeClient calls are not thread safe.
- DBusThreadManager::Get()->GetCryptohomeClient()->Pkcs11GetTpmTokenInfo(
- base::Bind(&RealTPMTokenInfoDelegate::OnPkcs11GetTpmTokenInfo,
- weak_ptr_factory_.GetWeakPtr(),
- callback));
-}
-
-void RealTPMTokenInfoDelegate::OnPkcs11GetTpmTokenInfo(
- base::Callback<void(bool result)> callback,
- DBusMethodCallStatus call_status,
- const std::string& token_name,
- const std::string& user_pin) const {
- if (call_status == DBUS_METHOD_CALL_SUCCESS) {
- token_name_ = token_name;
- user_pin_ = user_pin;
- token_ready_ = true;
- }
- callback.Run(token_ready_);
-}
-
} // namespace
//////////////////////////////////////////////////////////////////////////////
@@ -201,6 +110,7 @@ class CertLibraryImpl
CertLibraryImpl() :
observer_list_(new CertLibraryObserverList),
+ tpm_token_ready_(false),
user_logged_in_(false),
certificates_requested_(false),
certificates_loaded_(false),
@@ -246,7 +156,7 @@ class CertLibraryImpl
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kLoadOpencryptoki) ||
CommandLine::ForCurrentProcess()->HasSwitch(switches::kStubCros)) {
- crypto::EnableTPMTokenForNSS(new RealTPMTokenInfoDelegate());
+ crypto::EnableTPMTokenForNSS();
Ryan Sleevi 2012/05/16 17:02:16 See comments in crypto/
// Note: this calls crypto::EnsureTPMTokenReady()
RequestCertificates();
}
@@ -387,14 +297,6 @@ class CertLibraryImpl
icu::Collator* collator_;
};
- void RequestCertificatesTask() {
- CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI))
- << __FUNCTION__ << " should be called on UI thread.";
- // Reset the task to the initial state so is_null() returns true.
- request_task_ = base::Closure();
- RequestCertificates();
- }
-
void NotifyCertificatesLoaded(bool initial_load) {
observer_list_->Notify(
&CertLibrary::Observer::OnCertificatesLoaded, initial_load);
@@ -506,13 +408,12 @@ class CertLibraryImpl
VLOG(1) << "Requesting Certificates.";
DBusThreadManager::Get()->GetCryptohomeClient()->TpmIsEnabled(
- base::Bind(&CertLibraryImpl::RequestCertificatesInternal,
+ base::Bind(&CertLibraryImpl::OnTpmIsEnabled,
weak_ptr_factory_.GetWeakPtr()));
}
// This method is used to implement RequestCertificates.
- void RequestCertificatesInternal(DBusMethodCallStatus call_status,
- bool tpm_is_enabled) {
+ void OnTpmIsEnabled(DBusMethodCallStatus call_status, bool tpm_is_enabled) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI))
<< __FUNCTION__ << " should be called on UI thread.";
if (call_status != DBUS_METHOD_CALL_SUCCESS || !tpm_is_enabled) {
@@ -522,35 +423,51 @@ class CertLibraryImpl
BrowserThread::DB, FROM_HERE,
base::Bind(&CertLibraryImpl::LoadCertificates,
base::Unretained(this)));
- } else if (crypto::IsTPMTokenReady()) {
- // Need TPM token name to filter user certificates.
- const bool tpm_token_ready = true;
- GetTPMTokenName(tpm_token_ready);
+ } else if (tpm_token_ready_) {
+ InitializeTPMToken();
} else {
- crypto::InitializeTPMToken(
- base::Bind(&CertLibraryImpl::GetTPMTokenName,
+ DBusThreadManager::Get()->GetCryptohomeClient()->Pkcs11IsTpmTokenReady(
+ base::Bind(&CertLibraryImpl::OnPkcs11IsTpmTokenReady,
weak_ptr_factory_.GetWeakPtr()));
}
}
// This method is used to implement RequestCertificates.
- void GetTPMTokenName(bool tpm_token_ready) {
+ void OnPkcs11IsTpmTokenReady(DBusMethodCallStatus call_status,
+ bool is_tpm_token_ready) {
+ if (call_status != DBUS_METHOD_CALL_SUCCESS || !is_tpm_token_ready) {
+ MaybeRetryRequestCertificates();
+ return;
+ }
+
+ // Retrieve token_name_ and user_pin_ here since they will never change
+ // and CryptohomeClient calls are not thread safe.
+ DBusThreadManager::Get()->GetCryptohomeClient()->Pkcs11GetTpmTokenInfo(
+ base::Bind(&CertLibraryImpl::OnPkcs11GetTpmTokenInfo,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+
+ // This method is used to implement RequestCertificates.
+ void OnPkcs11GetTpmTokenInfo(DBusMethodCallStatus call_status,
+ const std::string& token_name,
+ const std::string& user_pin) {
+ if (call_status != DBUS_METHOD_CALL_SUCCESS) {
+ MaybeRetryRequestCertificates();
+ return;
+ }
+ tpm_token_name_ = token_name;
+ tpm_user_pin_ = user_pin;
+ tpm_token_ready_ = true;
+
+ InitializeTPMToken();
+ }
+
+ // This method is used to implement RequestCertificates.
+ void InitializeTPMToken() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI))
<< __FUNCTION__ << " should be called on UI thread.";
Ryan Sleevi 2012/05/16 17:02:16 nit: These strings will not get optimized out in a
hashimoto 2012/05/17 07:35:07 Agree, CHECK itself is sufficient, removed the str
- if (tpm_token_ready) {
- std::string unused_pin;
- crypto::GetTPMTokenInfo(&tpm_token_name_, &unused_pin);
- } else {
- VLOG(1) << "TPM token not ready.";
- if (request_task_.is_null()) {
- // Cryptohome does not notify us when the token is ready, so call
- // this again after a delay.
- request_task_ = base::Bind(&CertLibraryImpl::RequestCertificatesTask,
- weak_ptr_factory_.GetWeakPtr());
- BrowserThread::PostDelayedTask(
- BrowserThread::UI, FROM_HERE, request_task_,
- base::TimeDelta::FromMilliseconds(kRequestDelayMs));
- }
+ if (!crypto::InitializeTPMToken(tpm_token_name_, tpm_user_pin_)) {
+ MaybeRetryRequestCertificates();
return;
}
@@ -560,15 +477,40 @@ class CertLibraryImpl
base::Bind(&CertLibraryImpl::LoadCertificates, base::Unretained(this)));
}
+ void MaybeRetryRequestCertificates() {
+ if (!request_task_.is_null())
+ return;
+ // Cryptohome does not notify us when the token is ready, so call
+ // this again after a delay.
+ request_task_ = base::Bind(&CertLibraryImpl::RequestCertificatesTask,
+ weak_ptr_factory_.GetWeakPtr());
+ BrowserThread::PostDelayedTask(
+ BrowserThread::UI, FROM_HERE, request_task_,
+ base::TimeDelta::FromMilliseconds(kRequestDelayMs));
+ }
+
+ void RequestCertificatesTask() {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI))
+ << __FUNCTION__ << " should be called on UI thread.";
+ // Reset the task to the initial state so is_null() returns true.
+ request_task_ = base::Closure();
+ RequestCertificates();
+ }
+
// Observers.
const scoped_refptr<CertLibraryObserverList> observer_list_;
// Active request task for re-requests while waiting for TPM init.
base::Closure request_task_;
+ bool tpm_token_ready_;
+
// Cached TPM token name.
std::string tpm_token_name_;
+ // Cached TPM user pin.
+ std::string tpm_user_pin_;
+
// Supplemental user key.
scoped_ptr<crypto::SymmetricKey> supplemental_user_key_;
« no previous file with comments | « no previous file | crypto/nss_util.h » ('j') | crypto/nss_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698