Index: base/mac/scoped_ioplugininterface.h |
diff --git a/base/mac/scoped_ioplugininterface.h b/base/mac/scoped_ioplugininterface.h |
index 400757046fa1a8e677ba6f0ef69d4b7976ee0666..872da8eaa53d266a490be0e9d4fd045e2914f5fb 100644 |
--- a/base/mac/scoped_ioplugininterface.h |
+++ b/base/mac/scoped_ioplugininterface.h |
@@ -7,68 +7,30 @@ |
#include <IOKit/IOKitLib.h> |
-#include "base/compiler_specific.h" |
-#include "base/macros.h" |
+#include "base/mac/scoped_typeref.h" |
namespace base { |
namespace mac { |
-// Just like ScopedCFTypeRef but for IOCFPlugInInterface and friends |
-// (IOUSBInterfaceStruct and IOUSBDeviceStruct320 in particular). |
-template<typename T> |
-class ScopedIOPluginInterface { |
- public: |
- typedef T** InterfaceT; |
- typedef InterfaceT element_type; |
- |
- explicit ScopedIOPluginInterface(InterfaceT object = NULL) |
- : object_(object) { |
- } |
- |
- ~ScopedIOPluginInterface() { |
- if (object_) |
- (*object_)->Release(object_); |
- } |
- |
- void reset(InterfaceT object = NULL) { |
- if (object_) |
- (*object_)->Release(object_); |
- object_ = object; |
- } |
- |
- bool operator==(InterfaceT that) const { |
- return object_ == that; |
- } |
- |
- bool operator!=(InterfaceT that) const { |
- return object_ != that; |
- } |
- |
- operator InterfaceT() const { |
- return object_; |
- } |
+namespace internal { |
- InterfaceT get() const { |
- return object_; |
- } |
- |
- void swap(ScopedIOPluginInterface& that) { |
- InterfaceT temp = that.object_; |
- that.object_ = object_; |
- object_ = temp; |
- } |
- |
- InterfaceT release() WARN_UNUSED_RESULT { |
- InterfaceT temp = object_; |
- object_ = NULL; |
- return temp; |
+template <typename T> |
+struct ScopedIOPluginInterfaceTraits { |
+ static T InvalidValue() { return nullptr; } |
+ static T Retain(T t) { |
+ (*t)->AddRef(t); |
+ return t; |
} |
+ static void Release(T t) { (*t)->Release(t); } |
+}; |
- private: |
- InterfaceT object_; |
+} // namespace internal |
- DISALLOW_COPY_AND_ASSIGN(ScopedIOPluginInterface); |
-}; |
+// Just like ScopedCFTypeRef but for IOCFPlugInInterface and friends |
+// (IOUSBInterfaceStruct and IOUSBDeviceStruct320 in particular). |
+template <typename T> |
+using ScopedIOPluginInterface = |
+ ScopedTypeRef<T**, internal::ScopedIOPluginInterfaceTraits<T**>>; |
} // namespace mac |
} // namespace base |