summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authortoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-18 07:02:54 +0000
committertoyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-18 07:02:54 +0000
commit7025e931b4a1a297f802c1de3ad9a76d3cdd7006 (patch)
treeac6d517f6e892fc74b424de7d568cd83fccb5402 /crypto
parent8a8f4d1a570302b00c7c2a64c699a108621893ec (diff)
downloadchromium_src-7025e931b4a1a297f802c1de3ad9a76d3cdd7006.zip
chromium_src-7025e931b4a1a297f802c1de3ad9a76d3cdd7006.tar.gz
chromium_src-7025e931b4a1a297f802c1de3ad9a76d3cdd7006.tar.bz2
Reland: Implement ScopedTestNSSDB instead of OpenTestNSSDB()
This CL needs memory suppression because of missing CloseTestNSSDB(). See also TODO. BUG=136950, 156433 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=162327 Review URL: https://chromiumcodereview.appspot.com/11174006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162659 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto')
-rw-r--r--crypto/crypto_export.h9
-rw-r--r--crypto/nss_util.cc10
-rw-r--r--crypto/nss_util.h20
3 files changed, 32 insertions, 7 deletions
diff --git a/crypto/crypto_export.h b/crypto/crypto_export.h
index f8b0b6c..983afe6 100644
--- a/crypto/crypto_export.h
+++ b/crypto/crypto_export.h
@@ -5,25 +5,34 @@
#ifndef CRYPTO_CRYPTO_EXPORT_H_
#define CRYPTO_CRYPTO_EXPORT_H_
+// Defines CRYPTO_EXPORT so that functionality implemented by the crypto module
+// can be exported to consumers, and CRYPTO_EXPORT_PRIVATE that allows unit
+// tests to access features not intended to be used directly by real consumers.
+
#if defined(COMPONENT_BUILD)
#if defined(WIN32)
#if defined(CRYPTO_IMPLEMENTATION)
#define CRYPTO_EXPORT __declspec(dllexport)
+#define CRYPTO_EXPORT_PRIVATE __declspec(dllexport)
#else
#define CRYPTO_EXPORT __declspec(dllimport)
+#define CRYPTO_EXPORT_PRIVATE __declspec(dllimport)
#endif // defined(CRYPTO_IMPLEMENTATION)
#else // defined(WIN32)
#if defined(CRYPTO_IMPLEMENTATION)
#define CRYPTO_EXPORT __attribute__((visibility("default")))
+#define CRYPTO_EXPORT_PRIVATE __attribute__((visibility("default")))
#else
#define CRYPTO_EXPORT
+#define CRYPTO_EXPORT_PRIVATE
#endif
#endif
#else // defined(COMPONENT_BUILD)
#define CRYPTO_EXPORT
+#define CRYPTO_EXPORT_PRIVATE
#endif
#endif // CRYPTO_CRYPTO_EXPORT_H_
diff --git a/crypto/nss_util.cc b/crypto/nss_util.cc
index db89a70..47b4d06 100644
--- a/crypto/nss_util.cc
+++ b/crypto/nss_util.cc
@@ -702,8 +702,14 @@ bool CheckNSSVersion(const char* version) {
}
#if defined(USE_NSS)
-bool OpenTestNSSDB() {
- return g_nss_singleton.Get().OpenTestNSSDB();
+ScopedTestNSSDB::ScopedTestNSSDB()
+ : is_open_(g_nss_singleton.Get().OpenTestNSSDB()) {
+}
+
+ScopedTestNSSDB::~ScopedTestNSSDB() {
+ // TODO(mattm): Close the dababase once NSS 3.14 is required,
+ // which fixes https://bugzilla.mozilla.org/show_bug.cgi?id=588269
+ // Resource leaks are suppressed. http://crbug.com/156433 .
}
base::Lock* GetNSSWriteLock() {
diff --git a/crypto/nss_util.h b/crypto/nss_util.h
index 88d7d05..9e09d6d 100644
--- a/crypto/nss_util.h
+++ b/crypto/nss_util.h
@@ -128,11 +128,21 @@ CRYPTO_EXPORT int64 BaseTimeToPRTime(base::Time time);
#if defined(USE_NSS)
// Exposed for unittests only.
-// TODO(mattm): when https://bugzilla.mozilla.org/show_bug.cgi?id=588269 is
-// fixed, switch back to using a separate userdb for each test. (Maybe refactor
-// to provide a ScopedTestNSSDB instead of open/close methods.)
-CRYPTO_EXPORT bool OpenTestNSSDB();
-// NOTE: due to NSS bug 588269, mentioned above, there is no CloseTestNSSDB.
+// TODO(mattm): When NSS 3.14 is the minimum version required,
+// switch back to using a separate user DB for each test.
+// Because of https://bugzilla.mozilla.org/show_bug.cgi?id=588269 , the
+// opened user DB is not automatically closed.
+class CRYPTO_EXPORT_PRIVATE ScopedTestNSSDB {
+ public:
+ ScopedTestNSSDB();
+ ~ScopedTestNSSDB();
+
+ bool is_open() { return is_open_; }
+
+ private:
+ bool is_open_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedTestNSSDB);
+};
// NSS has a bug which can cause a deadlock or stall in some cases when writing
// to the certDB and keyDB. It also has a bug which causes concurrent key pair