Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3428)

Unified Diff: base/mac/scoped_ioplugininterface.h

Issue 1551943002: Rewrite most of the scopers in //base/mac to use ScopedTypeRef or ScopedGeneric. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix iOS Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698