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

Unified Diff: base/nss_util.cc

Issue 2838010: Add a unit test to check KeygenHandler's thread-safety (Closed)
Patch Set: Another revision Created 10 years, 6 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
Index: base/nss_util.cc
diff --git a/base/nss_util.cc b/base/nss_util.cc
index 7043b8dc192ff9804f2dc8a66df0bc5139d80dd6..56368f5a22bfa1c534da952f57921442360a5f54 100644
--- a/base/nss_util.cc
+++ b/base/nss_util.cc
@@ -18,6 +18,11 @@
#include "base/singleton.h"
#include "base/string_util.h"
+#if defined(USE_NSS)
+#include "base/lock.h"
+#include "base/scoped_ptr.h"
+#endif // defined(USE_NSS)
wtc 2010/06/21 22:40:53 Two spaces before the comment.
davidben 2010/06/22 02:54:56 Done.
+
// On some platforms, we use NSS for SSL only -- we don't use NSS for crypto
// or certificate verification, and we don't use the NSS certificate and key
// databases.
@@ -168,6 +173,11 @@ class NSSInitSingleton {
PK11_FreeSlot(slot);
}
+ // TODO(davidben): When https://bugzilla.mozilla.org/show_bug.cgi?id=564011
+ // is fixed, we will no longer need the lock. We should detect this and not
+ // initialize a Lock here.
+ write_lock_.reset(new Lock());
+
root_ = InitDefaultRootCerts();
#endif // defined(USE_NSS_FOR_SSL_ONLY)
}
@@ -219,10 +229,19 @@ class NSSInitSingleton {
return PK11_GetInternalKeySlot();
}
+#if defined(USE_NSS)
+ Lock* write_lock() {
+ return write_lock_.get();
+ }
+#endif // defined(USE_NSS)
+
private:
PK11SlotInfo* real_db_slot_; // Overrides internal key slot if non-NULL.
SECMODModule *root_;
bool chromeos_user_logged_in_;
+#if defined(USE_NSS)
+ scoped_ptr<Lock> write_lock_;
+#endif // defined(USE_NSS)
};
} // namespace
@@ -237,6 +256,25 @@ void EnsureNSSInit() {
Singleton<NSSInitSingleton>::get();
}
+#if defined(USE_NSS)
+Lock* GetNSSWriteLock() {
+ return Singleton<NSSInitSingleton>::get()->write_lock();
+}
+
+AutoNSSWriteLock::AutoNSSWriteLock() : lock_(GetNSSWriteLock()) {
+ // May be NULL if the lock is not needed in our version of NSS.
+ if (lock_)
+ lock_->Acquire();
+}
+
+AutoNSSWriteLock::~AutoNSSWriteLock() {
+ if (lock_) {
+ lock_->AssertAcquired();
+ lock_->Release();
+ }
+}
+#endif // defined(USE_NSS)
+
#if defined(OS_CHROMEOS)
void OpenPersistentNSSDB() {
Singleton<NSSInitSingleton>::get()->OpenPersistentNSSDB();
« base/nss_util.h ('K') | « base/nss_util.h ('k') | net/base/keygen_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698