| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 BASE_SCOPED_NSS_TYPES_H_ | 5 #ifndef BASE_SCOPED_NSS_TYPES_H_ |
| 6 #define BASE_SCOPED_NSS_TYPES_H_ | 6 #define BASE_SCOPED_NSS_TYPES_H_ |
| 7 | 7 |
| 8 #include <nss.h> | 8 #include <nss.h> |
| 9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
| 10 | 10 |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 | 14 |
| 15 template <typename Type, void (*Destroyer)(Type*)> | |
| 16 struct NSSDestroyer { | |
| 17 void operator()(Type* ptr) const { | |
| 18 if (ptr) | |
| 19 Destroyer(ptr); | |
| 20 } | |
| 21 }; | |
| 22 | |
| 23 template <typename Type, void (*Destroyer)(Type*, PRBool), PRBool freeit> | 15 template <typename Type, void (*Destroyer)(Type*, PRBool), PRBool freeit> |
| 24 struct NSSDestroyer1 { | 16 void NSSDestroyer1(Type* ptr) { |
| 25 void operator()(Type* ptr) const { | 17 Destroyer(ptr, freeit); |
| 26 if (ptr) | 18 } |
| 27 Destroyer(ptr, freeit); | |
| 28 } | |
| 29 }; | |
| 30 | 19 |
| 31 // Define some convenient scopers around NSS pointers. | 20 // Define some convenient scopers around NSS pointers. |
| 32 typedef scoped_ptr_malloc< | 21 typedef scoped_ptr_malloc< |
| 33 PK11Context, NSSDestroyer1<PK11Context, | 22 PK11Context, NSSDestroyer1<PK11Context, |
| 34 PK11_DestroyContext, | 23 PK11_DestroyContext, |
| 35 PR_TRUE> > ScopedPK11Context; | 24 PR_TRUE> > ScopedPK11Context; |
| 36 typedef scoped_ptr_malloc< | 25 typedef scoped_ptr_malloc<PK11SlotInfo, PK11_FreeSlot> ScopedPK11Slot; |
| 37 PK11SlotInfo, NSSDestroyer<PK11SlotInfo, PK11_FreeSlot> > ScopedPK11Slot; | 26 typedef scoped_ptr_malloc<PK11SymKey, PK11_FreeSymKey> ScopedPK11SymKey; |
| 38 typedef scoped_ptr_malloc< | |
| 39 PK11SymKey, NSSDestroyer<PK11SymKey, PK11_FreeSymKey> > ScopedPK11SymKey; | |
| 40 typedef scoped_ptr_malloc< | 27 typedef scoped_ptr_malloc< |
| 41 SECAlgorithmID, NSSDestroyer1<SECAlgorithmID, | 28 SECAlgorithmID, NSSDestroyer1<SECAlgorithmID, |
| 42 SECOID_DestroyAlgorithmID, | 29 SECOID_DestroyAlgorithmID, |
| 43 PR_TRUE> > ScopedSECAlgorithmID; | 30 PR_TRUE> > ScopedSECAlgorithmID; |
| 44 typedef scoped_ptr_malloc< | 31 typedef scoped_ptr_malloc< |
| 45 SECItem, NSSDestroyer1<SECItem, | 32 SECItem, NSSDestroyer1<SECItem, |
| 46 SECITEM_FreeItem, | 33 SECITEM_FreeItem, |
| 47 PR_TRUE> > ScopedSECItem; | 34 PR_TRUE> > ScopedSECItem; |
| 48 | 35 |
| 49 } // namespace base | 36 } // namespace base |
| 50 | 37 |
| 51 #endif // BASE_SCOPED_NSS_TYPES_H_ | 38 #endif // BASE_SCOPED_NSS_TYPES_H_ |
| OLD | NEW |