Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CRYPTO_OPENSSL_UTIL_H_ | 5 #ifndef CRYPTO_OPENSSL_UTIL_H_ |
| 6 #define CRYPTO_OPENSSL_UTIL_H_ | 6 #define CRYPTO_OPENSSL_UTIL_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "crypto/crypto_export.h" | 10 #include "crypto/crypto_export.h" |
| 11 | 11 |
| 12 namespace crypto { | 12 namespace crypto { |
| 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 they go 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 { |
|
Ryan Sleevi
2013/02/04 22:53:27
As a TODO, we should move this towards using the n
| |
| 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() { | 21 ~ScopedOpenSSL() { |
| 22 reset(NULL); | 22 reset(NULL); |
| 23 } | 23 } |
| 24 | 24 |
| 25 T* get() const { return ptr_; } | 25 T* get() const { return ptr_; } |
| 26 T* release() { | |
| 27 T* ptr = ptr_; | |
| 28 ptr_ = NULL; | |
| 29 return ptr; | |
| 30 } | |
| 26 void reset(T* ptr) { | 31 void reset(T* ptr) { |
| 27 if (ptr != ptr_) { | 32 if (ptr != ptr_) { |
| 28 if (ptr_) (*destructor)(ptr_); | 33 if (ptr_) (*destructor)(ptr_); |
| 29 ptr_ = ptr; | 34 ptr_ = ptr; |
| 30 } | 35 } |
| 31 } | 36 } |
| 32 | 37 |
| 33 private: | 38 private: |
| 34 T* ptr_; | 39 T* ptr_; |
| 35 | 40 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 | 110 |
| 106 private: | 111 private: |
| 107 const tracked_objects::Location location_; | 112 const tracked_objects::Location location_; |
| 108 | 113 |
| 109 DISALLOW_IMPLICIT_CONSTRUCTORS(OpenSSLErrStackTracer); | 114 DISALLOW_IMPLICIT_CONSTRUCTORS(OpenSSLErrStackTracer); |
| 110 }; | 115 }; |
| 111 | 116 |
| 112 } // namespace crypto | 117 } // namespace crypto |
| 113 | 118 |
| 114 #endif // CRYPTO_OPENSSL_UTIL_H_ | 119 #endif // CRYPTO_OPENSSL_UTIL_H_ |
| OLD | NEW |