OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CRYPTO_NSS_UTIL_H_ | 5 #ifndef CRYPTO_NSS_UTIL_H_ |
6 #define CRYPTO_NSS_UTIL_H_ | 6 #define CRYPTO_NSS_UTIL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "crypto/crypto_export.h" | 12 #include "crypto/crypto_export.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 class FilePath; | 15 class FilePath; |
16 class Lock; | 16 class Lock; |
17 class Time; | 17 class Time; |
18 } // namespace base | 18 } // namespace base |
19 | 19 |
20 // This file specifically doesn't depend on any NSS or NSPR headers because it | 20 // This file specifically doesn't depend on any NSS or NSPR headers because it |
21 // is included by various (non-crypto) parts of chrome to call the | 21 // is included by various (non-crypto) parts of chrome to call the |
22 // initialization functions. | 22 // initialization functions. |
23 namespace crypto { | 23 namespace crypto { |
24 | 24 |
25 #if defined(USE_NSS) | 25 #if defined(USE_NSS_CERTS) |
26 // EarlySetupForNSSInit performs lightweight setup which must occur before the | 26 // EarlySetupForNSSInit performs lightweight setup which must occur before the |
27 // process goes multithreaded. This does not initialise NSS. For test, see | 27 // process goes multithreaded. This does not initialise NSS. For test, see |
28 // EnsureNSSInit. | 28 // EnsureNSSInit. |
29 CRYPTO_EXPORT void EarlySetupForNSSInit(); | 29 CRYPTO_EXPORT void EarlySetupForNSSInit(); |
30 #endif | 30 #endif |
31 | 31 |
32 // Initialize NRPR if it isn't already initialized. This function is | 32 // Initialize NRPR if it isn't already initialized. This function is |
33 // thread-safe, and NSPR will only ever be initialized once. | 33 // thread-safe, and NSPR will only ever be initialized once. |
34 CRYPTO_EXPORT void EnsureNSPRInit(); | 34 CRYPTO_EXPORT void EnsureNSPRInit(); |
35 | 35 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 #endif | 120 #endif |
121 | 121 |
122 // Convert a NSS PRTime value into a base::Time object. | 122 // Convert a NSS PRTime value into a base::Time object. |
123 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. | 123 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. |
124 CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64 prtime); | 124 CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64 prtime); |
125 | 125 |
126 // Convert a base::Time object into a PRTime value. | 126 // Convert a base::Time object into a PRTime value. |
127 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. | 127 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. |
128 CRYPTO_EXPORT int64 BaseTimeToPRTime(base::Time time); | 128 CRYPTO_EXPORT int64 BaseTimeToPRTime(base::Time time); |
129 | 129 |
130 #if defined(USE_NSS) | 130 #if defined(USE_NSS_CERTS) |
131 // NSS has a bug which can cause a deadlock or stall in some cases when writing | 131 // NSS has a bug which can cause a deadlock or stall in some cases when writing |
132 // to the certDB and keyDB. It also has a bug which causes concurrent key pair | 132 // to the certDB and keyDB. It also has a bug which causes concurrent key pair |
133 // generations to scribble over each other. To work around this, we synchronize | 133 // generations to scribble over each other. To work around this, we synchronize |
134 // writes to the NSS databases with a global lock. The lock is hidden beneath a | 134 // writes to the NSS databases with a global lock. The lock is hidden beneath a |
135 // function for easy disabling when the bug is fixed. Callers should allow for | 135 // function for easy disabling when the bug is fixed. Callers should allow for |
136 // it to return NULL in the future. | 136 // it to return NULL in the future. |
137 // | 137 // |
138 // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011 | 138 // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011 |
139 base::Lock* GetNSSWriteLock(); | 139 base::Lock* GetNSSWriteLock(); |
140 | 140 |
141 // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock | 141 // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock |
142 // is in scope. | 142 // is in scope. |
143 class CRYPTO_EXPORT AutoNSSWriteLock { | 143 class CRYPTO_EXPORT AutoNSSWriteLock { |
144 public: | 144 public: |
145 AutoNSSWriteLock(); | 145 AutoNSSWriteLock(); |
146 ~AutoNSSWriteLock(); | 146 ~AutoNSSWriteLock(); |
147 private: | 147 private: |
148 base::Lock *lock_; | 148 base::Lock *lock_; |
149 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); | 149 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); |
150 }; | 150 }; |
151 #endif // defined(USE_NSS) | 151 #endif // defined(USE_NSS_CERTS) |
152 | 152 |
153 } // namespace crypto | 153 } // namespace crypto |
154 | 154 |
155 #endif // CRYPTO_NSS_UTIL_H_ | 155 #endif // CRYPTO_NSS_UTIL_H_ |
OLD | NEW |