OLD | NEW |
---|---|
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
wtc
2009/09/02 01:17:17
This should be 2008-2009.
| |
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 #include "base/nss_init.h" | 5 #include "base/nss_init.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <nss.h> | 8 #include <nss.h> |
9 #include <plarena.h> | 9 #include <plarena.h> |
10 #include <prerror.h> | 10 #include <prerror.h> |
11 #include <prinit.h> | 11 #include <prinit.h> |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 SECMODModule *root = SECMOD_LoadUserModule(modparams, NULL, PR_FALSE); | 49 SECMODModule *root = SECMOD_LoadUserModule(modparams, NULL, PR_FALSE); |
50 if (root) | 50 if (root) |
51 return root; | 51 return root; |
52 | 52 |
53 // Aw, snap. Can't find/load root cert shared library. | 53 // Aw, snap. Can't find/load root cert shared library. |
54 // This will make it hard to talk to anybody via https. | 54 // This will make it hard to talk to anybody via https. |
55 NOTREACHED(); | 55 NOTREACHED(); |
56 return NULL; | 56 return NULL; |
57 } | 57 } |
58 | 58 |
59 // A singleton to initialize/deinitialize NSPR. | |
60 // Separate from the NSS singleton because we initialize it on the UI thread. | |
wtc
2009/09/02 01:17:17
Nit: it => NSPR (otherwise it's not clear what "it
| |
61 class NSPRInitSingleton { | |
62 public: | |
63 NSPRInitSingleton() { | |
64 PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0); | |
65 } | |
66 | |
67 ~NSPRInitSingleton() { | |
68 PRStatus prstatus = PR_Cleanup(); | |
69 if (prstatus != PR_SUCCESS) { | |
70 LOG(ERROR) << "PR_Cleanup failed; " | |
71 "Is NSPR getting destroyed on wrong thread?"; | |
wtc
2009/09/02 01:17:17
Since Singleton destructors run on the main thread
| |
72 } | |
73 } | |
74 }; | |
75 | |
59 class NSSInitSingleton { | 76 class NSSInitSingleton { |
60 public: | 77 public: |
61 NSSInitSingleton() { | 78 NSSInitSingleton() { |
62 SECStatus status; | 79 SECStatus status; |
wtc
2009/09/02 01:17:17
We should call EnsureNSPRInit here, so that the un
| |
63 std::string database_dir = GetDefaultConfigDirectory(); | 80 std::string database_dir = GetDefaultConfigDirectory(); |
64 if (!database_dir.empty()) { | 81 if (!database_dir.empty()) { |
65 // Initialize with a persistant database (~/.pki/nssdb). | 82 // Initialize with a persistant database (~/.pki/nssdb). |
66 // Use "sql:" which can be shared by multiple processes safely. | 83 // Use "sql:" which can be shared by multiple processes safely. |
67 status = NSS_InitReadWrite( | 84 status = NSS_InitReadWrite( |
68 StringPrintf("sql:%s", database_dir.c_str()).c_str()); | 85 StringPrintf("sql:%s", database_dir.c_str()).c_str()); |
69 } else { | 86 } else { |
70 LOG(WARNING) << "Initialize NSS without using a persistent database " | 87 LOG(WARNING) << "Initialize NSS without using a persistent database " |
71 << "(~/.pki/nssdb)."; | 88 << "(~/.pki/nssdb)."; |
72 status = NSS_NoDB_Init("."); | 89 status = NSS_NoDB_Init("."); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 | 149 |
133 SECStatus status = NSS_Shutdown(); | 150 SECStatus status = NSS_Shutdown(); |
134 if (status != SECSuccess) { | 151 if (status != SECSuccess) { |
135 // We LOG(INFO) because this failure is relatively harmless | 152 // We LOG(INFO) because this failure is relatively harmless |
136 // (leaking, but we're shutting down anyway). | 153 // (leaking, but we're shutting down anyway). |
137 LOG(INFO) << "NSS_Shutdown failed; see " | 154 LOG(INFO) << "NSS_Shutdown failed; see " |
138 "http://code.google.com/p/chromium/issues/detail?id=4609"; | 155 "http://code.google.com/p/chromium/issues/detail?id=4609"; |
139 } | 156 } |
140 | 157 |
141 PL_ArenaFinish(); | 158 PL_ArenaFinish(); |
142 | |
143 PRStatus prstatus = PR_Cleanup(); | |
144 if (prstatus != PR_SUCCESS) { | |
145 // We LOG(ERROR) here because this failure is bad: it indicates | |
146 // NSPR isn't initialized and cleaned up on the same thread. | |
147 LOG(ERROR) << "PR_Cleanup failed; see " | |
148 "http://code.google.com/p/chromium/issues/detail?id=18410"; | |
149 } | |
150 } | 159 } |
151 | 160 |
152 private: | 161 private: |
153 SECMODModule *root_; | 162 SECMODModule *root_; |
154 }; | 163 }; |
155 | 164 |
156 } // namespace | 165 } // namespace |
157 | 166 |
158 namespace base { | 167 namespace base { |
159 | 168 |
169 void EnsureNSPRInit() { | |
170 Singleton<NSPRInitSingleton>::get(); | |
171 } | |
172 | |
160 void EnsureNSSInit() { | 173 void EnsureNSSInit() { |
161 Singleton<NSSInitSingleton>::get(); | 174 Singleton<NSSInitSingleton>::get(); |
162 } | 175 } |
163 | 176 |
164 } // namespace base | 177 } // namespace base |
OLD | NEW |