blob: b869e46390693b498013ccdf9855d070a3e31e74 [file] [log] [blame]
[email protected]1b1a264a2010-01-14 22:36:351// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]bc1e07c72008-09-16 14:32:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]1b1a264a2010-01-14 22:36:355#ifndef BASE_NSS_UTIL_H_
6#define BASE_NSS_UTIL_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]1b1a264a2010-01-14 22:36:358
9#include "base/basictypes.h"
[email protected]bc1e07c72008-09-16 14:32:4410
[email protected]69138472010-06-25 22:44:4811#if defined(USE_NSS)
12class Lock;
13#endif // defined(USE_NSS)
14
[email protected]41c78fa2010-03-22 20:08:4115// 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]bc1e07c72008-09-16 14:32:4418namespace base {
19
[email protected]1b1a264a2010-01-14 22:36:3520class Time;
21
[email protected]730fb132009-09-02 22:50:2522// 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.
25void EnsureNSPRInit();
26
[email protected]bc1e07c72008-09-16 14:32:4427// 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.
30void EnsureNSSInit();
31
[email protected]dcce6cf2010-04-29 17:50:0632#if defined(OS_CHROMEOS)
33// Open the r/w nssdb that's stored inside the user's encrypted home directory.
34void OpenPersistentNSSDB();
35#endif
36
[email protected]1b1a264a2010-01-14 22:36:3537// 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.
39Time PRTimeToBaseTime(int64 prtime);
40
[email protected]69138472010-06-25 22:44:4841#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
50Lock* GetNSSWriteLock();
51
52// A helper class that acquires the NSS write Lock while the AutoNSSWriteLock
53// is in scope.
54class 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]bc1e07c72008-09-16 14:32:4465} // namespace base
66
[email protected]1b1a264a2010-01-14 22:36:3567#endif // BASE_NSS_UTIL_H_