[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 5 | #ifndef BASE_NSS_UTIL_H_ |
6 | #define BASE_NSS_UTIL_H_ | ||||
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame^] | 7 | #pragma once |
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 8 | |
9 | #include "base/basictypes.h" | ||||
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 10 | |
[email protected] | 6913847 | 2010-06-25 22:44:48 | [diff] [blame] | 11 | #if defined(USE_NSS) |
12 | class Lock; | ||||
13 | #endif // defined(USE_NSS) | ||||
14 | |||||
[email protected] | 41c78fa | 2010-03-22 20:08:41 | [diff] [blame] | 15 | // This file specifically doesn't depend on any NSS or NSPR headers because it |
16 | // is included by various (non-crypto) parts of chrome to call the | ||||
17 | // initialization functions. | ||||
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 18 | namespace base { |
19 | |||||
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 20 | class Time; |
21 | |||||
[email protected] | 730fb13 | 2009-09-02 22:50:25 | [diff] [blame] | 22 | // Initialize NRPR if it isn't already initialized. This function is |
23 | // thread-safe, and NSPR will only ever be initialized once. NSPR will be | ||||
24 | // properly shut down on program exit. | ||||
25 | void EnsureNSPRInit(); | ||||
26 | |||||
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 27 | // Initialize NSS if it isn't already initialized. This must be called before |
28 | // any other NSS functions. This function is thread-safe, and NSS will only | ||||
29 | // ever be initialized once. NSS will be properly shut down on program exit. | ||||
30 | void EnsureNSSInit(); | ||||
31 | |||||
[email protected] | dcce6cf | 2010-04-29 17:50:06 | [diff] [blame] | 32 | #if defined(OS_CHROMEOS) |
33 | // Open the r/w nssdb that's stored inside the user's encrypted home directory. | ||||
34 | void OpenPersistentNSSDB(); | ||||
35 | #endif | ||||
36 | |||||
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 37 | // Convert a NSS PRTime value into a base::Time object. |
38 | // We use a int64 instead of PRTime here to avoid depending on NSPR headers. | ||||
39 | Time PRTimeToBaseTime(int64 prtime); | ||||
40 | |||||
[email protected] | 6913847 | 2010-06-25 22:44:48 | [diff] [blame] | 41 | #if defined(USE_NSS) |
42 | // NSS has a bug which can cause a deadlock or stall in some cases when writing | ||||
43 | // to the certDB and keyDB. It also has a bug which causes concurrent key pair | ||||
44 | // generations to scribble over each other. To work around this, we synchronize | ||||
45 | // writes to the NSS databases with a global lock. The lock is hidden beneath a | ||||
46 | // function for easy disabling when the bug is fixed. Callers should allow for | ||||
47 | // it to return NULL in the future. | ||||
48 | // | ||||
49 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011 | ||||
50 | Lock* GetNSSWriteLock(); | ||||
51 | |||||
52 | // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock | ||||
53 | // is in scope. | ||||
54 | class AutoNSSWriteLock { | ||||
55 | public: | ||||
56 | AutoNSSWriteLock(); | ||||
57 | ~AutoNSSWriteLock(); | ||||
58 | private: | ||||
59 | Lock *lock_; | ||||
60 | DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); | ||||
61 | }; | ||||
62 | |||||
63 | #endif // defined(USE_NSS) | ||||
64 | |||||
[email protected] | bc1e07c7 | 2008-09-16 14:32:44 | [diff] [blame] | 65 | } // namespace base |
66 | |||||
[email protected] | 1b1a264a | 2010-01-14 22:36:35 | [diff] [blame] | 67 | #endif // BASE_NSS_UTIL_H_ |