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

Side by Side Diff: base/crypto/cssm_init.cc

Issue 6354017: Allow CDSA/CSSM to be used on worker threads in debug builds (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/crypto/cssm_init.h" 5 #include "base/crypto/cssm_init.h"
6 6
7 #include <Security/SecBase.h> 7 #include <Security/SecBase.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/singleton.h" 10 #include "base/singleton.h"
11 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
12 #include "base/sys_string_conversions.h" 12 #include "base/sys_string_conversions.h"
13 13
14 // When writing crypto code for Mac OS X, you may find the following 14 // When writing crypto code for Mac OS X, you may find the following
15 // documentation useful: 15 // documentation useful:
16 // - Common Security: CDSA and CSSM, Version 2 (with corrigenda) 16 // - Common Security: CDSA and CSSM, Version 2 (with corrigenda)
17 // http://www.opengroup.org/security/cdsa.htm 17 // http://www.opengroup.org/security/cdsa.htm
18 // - Apple Cryptographic Service Provider Functional Specification 18 // - Apple Cryptographic Service Provider Functional Specification
19 // - CryptoSample: http://developer.apple.com/SampleCode/CryptoSample/ 19 // - CryptoSample: http://developer.apple.com/SampleCode/CryptoSample/
20 20
21 namespace { 21 namespace {
22 22
23 class CSSMInitSingleton { 23 class CSSMInitSingleton {
24 public: 24 public:
25 static CSSMInitSingleton* GetInstance() { 25 static CSSMInitSingleton* GetInstance() {
26 return Singleton<CSSMInitSingleton>::get(); 26 return Singleton<CSSMInitSingleton,
27 LeakySingletonTraits<CSSMInitSingleton> >::get();
27 } 28 }
28 29
29 CSSM_CSP_HANDLE csp_handle() const {return csp_handle_;} 30 CSSM_CSP_HANDLE csp_handle() const { return csp_handle_; }
30 31
31 private: 32 private:
32 CSSMInitSingleton() : inited_(false), loaded_(false), csp_handle_(NULL) { 33 CSSMInitSingleton() : inited_(false), loaded_(false), csp_handle_(NULL) {
33 static CSSM_VERSION version = {2, 0}; 34 static CSSM_VERSION version = {2, 0};
34 // TODO(wtc): what should our caller GUID be? 35 // TODO(wtc): what should our caller GUID be?
35 static const CSSM_GUID test_guid = { 36 static const CSSM_GUID test_guid = {
36 0xFADE, 0, 0, { 1, 2, 3, 4, 5, 6, 7, 0 } 37 0xFADE, 0, 0, { 1, 2, 3, 4, 5, 6, 7, 0 }
37 }; 38 };
38 CSSM_RETURN crtn; 39 CSSM_RETURN crtn;
39 CSSM_PVC_MODE pvc_policy = CSSM_PVC_NONE; 40 CSSM_PVC_MODE pvc_policy = CSSM_PVC_NONE;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 CSSM_CSP_HANDLE csp_handle_; 81 CSSM_CSP_HANDLE csp_handle_;
81 82
82 friend struct DefaultSingletonTraits<CSSMInitSingleton>; 83 friend struct DefaultSingletonTraits<CSSMInitSingleton>;
83 }; 84 };
84 85
85 // This singleton is separate as it pertains to Apple's wrappers over 86 // This singleton is separate as it pertains to Apple's wrappers over
86 // their own CSSM handles, as opposed to our own CSSM_CSP_HANDLE. 87 // their own CSSM handles, as opposed to our own CSSM_CSP_HANDLE.
87 class SecurityServicesSingleton { 88 class SecurityServicesSingleton {
88 public: 89 public:
89 static SecurityServicesSingleton* GetInstance() { 90 static SecurityServicesSingleton* GetInstance() {
90 return Singleton<SecurityServicesSingleton>::get(); 91 return Singleton<SecurityServicesSingleton,
92 LeakySingletonTraits<SecurityServicesSingleton> >::get();
91 } 93 }
92 94
93 ~SecurityServicesSingleton() {}
94
95 base::Lock& lock() { return lock_; } 95 base::Lock& lock() { return lock_; }
96 96
97 private: 97 private:
98 friend class Singleton<SecurityServicesSingleton>;
99 friend struct DefaultSingletonTraits<SecurityServicesSingleton>; 98 friend struct DefaultSingletonTraits<SecurityServicesSingleton>;
100 99
101 SecurityServicesSingleton() {} 100 SecurityServicesSingleton() {}
101 ~SecurityServicesSingleton() {}
102 102
103 base::Lock lock_; 103 base::Lock lock_;
104 104
105 DISALLOW_COPY_AND_ASSIGN(SecurityServicesSingleton); 105 DISALLOW_COPY_AND_ASSIGN(SecurityServicesSingleton);
106 }; 106 };
107 107
108 } // namespace 108 } // namespace
109 109
110 namespace base { 110 namespace base {
111 111
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } else { 152 } else {
153 LOG(ERROR) << fn_name << " returned " << err; 153 LOG(ERROR) << fn_name << " returned " << err;
154 } 154 }
155 } 155 }
156 156
157 base::Lock& GetMacSecurityServicesLock() { 157 base::Lock& GetMacSecurityServicesLock() {
158 return SecurityServicesSingleton::GetInstance()->lock(); 158 return SecurityServicesSingleton::GetInstance()->lock();
159 } 159 }
160 160
161 } // namespace base 161 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698