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_OPENSSL_UTIL_H_ | 5 #ifndef BASE_OPENSSL_UTIL_H_ |
6 #define BASE_OPENSSL_UTIL_H_ | 6 #define BASE_OPENSSL_UTIL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/tracked.h" | 10 #include "base/tracked.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 | 13 |
14 // A helper class that takes care of destroying OpenSSL objects when it goes out | 14 // A helper class that takes care of destroying OpenSSL objects when it goes out |
15 // of scope. | 15 // of scope. |
16 template <typename T, void (*destructor)(T*)> | 16 template <typename T, void (*destructor)(T*)> |
17 class ScopedOpenSSL { | 17 class ScopedOpenSSL { |
18 public: | 18 public: |
19 ScopedOpenSSL() : ptr_(NULL) { } | 19 ScopedOpenSSL() : ptr_(NULL) { } |
20 explicit ScopedOpenSSL(T* ptr) : ptr_(ptr) { } | 20 explicit ScopedOpenSSL(T* ptr) : ptr_(ptr) { } |
21 ~ScopedOpenSSL() { if (ptr_) (*destructor)(ptr_); } | 21 ~ScopedOpenSSL() { |
| 22 reset(NULL); |
| 23 } |
22 | 24 |
23 T* get() const { return ptr_; } | 25 T* get() const { return ptr_; } |
24 void reset(T* ptr) { | 26 void reset(T* ptr) { |
25 if (ptr != ptr_) { | 27 if (ptr != ptr_) { |
26 if (ptr_) (*destructor)(ptr_); | 28 if (ptr_) (*destructor)(ptr_); |
27 ptr_ = ptr; | 29 ptr_ = ptr; |
28 } | 30 } |
29 } | 31 } |
30 | 32 |
31 private: | 33 private: |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 104 |
103 private: | 105 private: |
104 const tracked_objects::Location location_; | 106 const tracked_objects::Location location_; |
105 | 107 |
106 DISALLOW_IMPLICIT_CONSTRUCTORS(OpenSSLErrStackTracer); | 108 DISALLOW_IMPLICIT_CONSTRUCTORS(OpenSSLErrStackTracer); |
107 }; | 109 }; |
108 | 110 |
109 } // namespace base | 111 } // namespace base |
110 | 112 |
111 #endif // BASE_OPENSSL_UTIL_H_ | 113 #endif // BASE_OPENSSL_UTIL_H_ |
OLD | NEW |