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 "crypto/crypto_export.h" | 10 #include "crypto/crypto_export.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. | 122 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. |
123 CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64 prtime); | 123 CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64 prtime); |
124 | 124 |
125 // Convert a base::Time object into a PRTime value. | 125 // Convert a base::Time object into a PRTime value. |
126 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. | 126 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. |
127 CRYPTO_EXPORT int64 BaseTimeToPRTime(base::Time time); | 127 CRYPTO_EXPORT int64 BaseTimeToPRTime(base::Time time); |
128 | 128 |
129 #if defined(USE_NSS) | 129 #if defined(USE_NSS) |
130 // Exposed for unittests only. | 130 // Exposed for unittests only. |
131 // TODO(mattm): when https://bugzilla.mozilla.org/show_bug.cgi?id=588269 is | 131 // TODO(mattm): when https://bugzilla.mozilla.org/show_bug.cgi?id=588269 is |
132 // fixed, switch back to using a separate userdb for each test. (Maybe refactor | 132 // fixed, switch back to using a separate userdb for each test. |
133 // to provide a ScopedTestNSSDB instead of open/close methods.) | 133 // NOTE: due to NSS bug 588269, mentioned above, opened NSSDB can not be closed |
134 CRYPTO_EXPORT bool OpenTestNSSDB(); | 134 // automatically though this object is out of scope. After this bug is fixed, |
135 // NOTE: due to NSS bug 588269, mentioned above, there is no CloseTestNSSDB. | 135 // we should add unit test to close and reopen a database. |
Ryan Sleevi
2012/10/16 18:19:02
high-level comment nit: Don't use "we" in comments
Takashi Toyoshima
2012/10/17 04:58:53
Done.
| |
136 class CRYPTO_EXPORT ScopedTestNSSDB { | |
Ryan Sleevi
2012/10/16 18:19:02
CRYPTO_EXPORT_PRIVATE , I believe.
Takashi Toyoshima
2012/10/17 04:58:53
Done.
| |
137 public: | |
138 ScopedTestNSSDB(); | |
139 ~ScopedTestNSSDB(); | |
140 | |
141 bool is_open() { return is_open_; } | |
142 | |
143 private: | |
144 bool is_open_; | |
Ryan Sleevi
2012/10/16 18:19:02
DISALLOW_COPY_AND_ASSIGN(...)
Takashi Toyoshima
2012/10/17 04:58:53
Done.
| |
145 }; | |
136 | 146 |
137 // NSS has a bug which can cause a deadlock or stall in some cases when writing | 147 // NSS has a bug which can cause a deadlock or stall in some cases when writing |
138 // to the certDB and keyDB. It also has a bug which causes concurrent key pair | 148 // to the certDB and keyDB. It also has a bug which causes concurrent key pair |
139 // generations to scribble over each other. To work around this, we synchronize | 149 // generations to scribble over each other. To work around this, we synchronize |
140 // writes to the NSS databases with a global lock. The lock is hidden beneath a | 150 // writes to the NSS databases with a global lock. The lock is hidden beneath a |
141 // function for easy disabling when the bug is fixed. Callers should allow for | 151 // function for easy disabling when the bug is fixed. Callers should allow for |
142 // it to return NULL in the future. | 152 // it to return NULL in the future. |
143 // | 153 // |
144 // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011 | 154 // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011 |
145 base::Lock* GetNSSWriteLock(); | 155 base::Lock* GetNSSWriteLock(); |
146 | 156 |
147 // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock | 157 // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock |
148 // is in scope. | 158 // is in scope. |
149 class CRYPTO_EXPORT AutoNSSWriteLock { | 159 class CRYPTO_EXPORT AutoNSSWriteLock { |
150 public: | 160 public: |
151 AutoNSSWriteLock(); | 161 AutoNSSWriteLock(); |
152 ~AutoNSSWriteLock(); | 162 ~AutoNSSWriteLock(); |
153 private: | 163 private: |
154 base::Lock *lock_; | 164 base::Lock *lock_; |
155 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); | 165 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); |
156 }; | 166 }; |
157 | 167 |
158 #endif // defined(USE_NSS) | 168 #endif // defined(USE_NSS) |
159 | 169 |
160 } // namespace crypto | 170 } // namespace crypto |
161 | 171 |
162 #endif // CRYPTO_NSS_UTIL_H_ | 172 #endif // CRYPTO_NSS_UTIL_H_ |
OLD | NEW |