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

Unified Diff: net/base/x509_certificate_mac.cc

Issue 5024003: Reland r65996. Disallows Singletons on non-joinable thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Allow another use that should be fixed. Created 10 years, 1 month 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 | « net/base/x509_certificate.cc ('k') | net/ocsp/nss_ocsp.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/x509_certificate_mac.cc
diff --git a/net/base/x509_certificate_mac.cc b/net/base/x509_certificate_mac.cc
index a2a0eeaa676b1b43c254185c83c64f87563ed076..2a604ee71b68ff0e3199b65a571d33b3fbf67a5a 100644
--- a/net/base/x509_certificate_mac.cc
+++ b/net/base/x509_certificate_mac.cc
@@ -8,6 +8,7 @@
#include <Security/Security.h>
#include <time.h>
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/pickle.h"
#include "base/mac/scoped_cftyperef.h"
@@ -21,6 +22,8 @@ using base::Time;
namespace net {
+namespace {
+
class MacTrustedCertificates {
public:
// Sets the trusted root certificate used by tests. Call with |cert| set
@@ -57,7 +60,7 @@ class MacTrustedCertificates {
return merged_array;
}
private:
- friend struct DefaultSingletonTraits<MacTrustedCertificates>;
+ friend struct base::DefaultLazyInstanceTraits<MacTrustedCertificates>;
// Obtain an instance of MacTrustedCertificates via the singleton
// interface.
@@ -73,11 +76,9 @@ class MacTrustedCertificates {
DISALLOW_COPY_AND_ASSIGN(MacTrustedCertificates);
};
-void SetMacTestCertificate(X509Certificate* cert) {
- Singleton<MacTrustedCertificates>::get()->SetTestCertificate(cert);
-}
-
-namespace {
+base::LazyInstance<MacTrustedCertificates,
+ base::LeakyLazyInstanceTraits<MacTrustedCertificates> >
+ g_mac_trusted_certificates(base::LINKER_INITIALIZED);
typedef OSStatus (*SecTrustCopyExtendedResultFuncPtr)(SecTrustRef,
CFDictionaryRef*);
@@ -443,6 +444,10 @@ void AddCertificatesFromBytes(const char* data, size_t length,
} // namespace
+void SetMacTestCertificate(X509Certificate* cert) {
+ g_mac_trusted_certificates.Get().SetTestCertificate(cert);
+}
+
void X509Certificate::Initialize() {
const CSSM_X509_NAME* name;
OSStatus status = SecCertificateGetSubject(cert_handle_, &name);
@@ -545,7 +550,7 @@ int X509Certificate::Verify(const std::string& hostname, int flags,
// Set the trusted anchor certificates for the SecTrustRef by merging the
// system trust anchors and the test root certificate.
CFArrayRef anchor_array =
- Singleton<MacTrustedCertificates>::get()->CopyTrustedCertificateArray();
+ g_mac_trusted_certificates.Get().CopyTrustedCertificateArray();
ScopedCFTypeRef<CFArrayRef> scoped_anchor_array(anchor_array);
if (anchor_array) {
status = SecTrustSetAnchorCertificates(trust_ref, anchor_array);
« no previous file with comments | « net/base/x509_certificate.cc ('k') | net/ocsp/nss_ocsp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698