diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 22:50:25 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-02 22:50:25 +0000 |
commit | 730fb13db106c6e9b29314b10221959bc4706650 (patch) | |
tree | 40801770d2db9afe260134b3ad4a93edf0b7b804 /base | |
parent | d1f2e93ff399c077d58e02c3799bb2bd817735fa (diff) | |
download | chromium_src-730fb13db106c6e9b29314b10221959bc4706650.zip chromium_src-730fb13db106c6e9b29314b10221959bc4706650.tar.gz chromium_src-730fb13db106c6e9b29314b10221959bc4706650.tar.bz2 |
linux: call PR_Init on UI thread
It complains about being shutdown on the wrong thread otherwise.
BUG=18410
Review URL: http://codereview.chromium.org/178062
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25259 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/nss_init.cc | 32 | ||||
-rw-r--r-- | base/nss_init.h | 7 | ||||
-rw-r--r-- | base/singleton.h | 4 |
3 files changed, 31 insertions, 12 deletions
diff --git a/base/nss_init.cc b/base/nss_init.cc index e25232c..7fed04c 100644 --- a/base/nss_init.cc +++ b/base/nss_init.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -56,9 +56,27 @@ SECMODModule *InitDefaultRootCerts() { return NULL; } +// A singleton to initialize/deinitialize NSPR. +// Separate from the NSS singleton because we initialize NSPR on the UI thread. +class NSPRInitSingleton { + public: + NSPRInitSingleton() { + PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); + } + + ~NSPRInitSingleton() { + PRStatus prstatus = PR_Cleanup(); + if (prstatus != PR_SUCCESS) { + LOG(ERROR) << "PR_Cleanup failed; was NSPR initialized on wrong thread?"; + } + } +}; + class NSSInitSingleton { public: NSSInitSingleton() { + base::EnsureNSPRInit(); + SECStatus status; std::string database_dir = GetDefaultConfigDirectory(); if (!database_dir.empty()) { @@ -139,14 +157,6 @@ class NSSInitSingleton { } PL_ArenaFinish(); - - PRStatus prstatus = PR_Cleanup(); - if (prstatus != PR_SUCCESS) { - // We LOG(ERROR) here because this failure is bad: it indicates - // NSPR isn't initialized and cleaned up on the same thread. - LOG(ERROR) << "PR_Cleanup failed; see " - "http://code.google.com/p/chromium/issues/detail?id=18410"; - } } private: @@ -157,6 +167,10 @@ class NSSInitSingleton { namespace base { +void EnsureNSPRInit() { + Singleton<NSPRInitSingleton>::get(); +} + void EnsureNSSInit() { Singleton<NSSInitSingleton>::get(); } diff --git a/base/nss_init.h b/base/nss_init.h index 181d292..cd8ee77 100644 --- a/base/nss_init.h +++ b/base/nss_init.h @@ -1,4 +1,4 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,6 +7,11 @@ namespace base { +// Initialize NRPR if it isn't already initialized. This function is +// thread-safe, and NSPR will only ever be initialized once. NSPR will be +// properly shut down on program exit. +void EnsureNSPRInit(); + // Initialize NSS if it isn't already initialized. This must be called before // any other NSS functions. This function is thread-safe, and NSS will only // ever be initialized once. NSS will be properly shut down on program exit. diff --git a/base/singleton.h b/base/singleton.h index afc2f0d..3272fce 100644 --- a/base/singleton.h +++ b/base/singleton.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -70,7 +70,7 @@ struct LeakySingletonTraits : public DefaultSingletonTraits<Type> { // // On every platform, if Traits::RAE is true, the singleton will be destroyed at // process exit. More precisely it uses base::AtExitManager which requires an -// object of this type to be instanciated. AtExitManager mimics the semantics +// object of this type to be instantiated. AtExitManager mimics the semantics // of atexit() such as LIFO order but under Windows is safer to call. For more // information see at_exit.h. // |