Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / base / mac / scoped_ioplugininterface.h
blob503980c3ef8c7b42fd0f61d01f1a3b5a1e161f81
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
3 // found in the LICENSE file.
5 #ifndef BASE_MAC_SCOPED_IOPLUGININTERFACE_H_
6 #define BASE_MAC_SCOPED_IOPLUGININTERFACE_H_
8 #include <IOKit/IOKitLib.h>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
13 namespace base {
14 namespace mac {
16 // Just like ScopedCFTypeRef but for IOCFPlugInInterface and friends
17 // (IOUSBInterfaceStruct and IOUSBDeviceStruct320 in particular).
18 template<typename T>
19 class ScopedIOPluginInterface {
20 public:
21 typedef T** InterfaceT;
22 typedef InterfaceT element_type;
24 explicit ScopedIOPluginInterface(InterfaceT object = NULL)
25 : object_(object) {
28 ~ScopedIOPluginInterface() {
29 if (object_)
30 (*object_)->Release(object_);
33 void reset(InterfaceT object = NULL) {
34 if (object_)
35 (*object_)->Release(object_);
36 object_ = object;
39 bool operator==(InterfaceT that) const {
40 return object_ == that;
43 bool operator!=(InterfaceT that) const {
44 return object_ != that;
47 operator InterfaceT() const {
48 return object_;
51 InterfaceT get() const {
52 return object_;
55 void swap(ScopedIOPluginInterface& that) {
56 InterfaceT temp = that.object_;
57 that.object_ = object_;
58 object_ = temp;
61 InterfaceT release() WARN_UNUSED_RESULT {
62 InterfaceT temp = object_;
63 object_ = NULL;
64 return temp;
67 private:
68 InterfaceT object_;
70 DISALLOW_COPY_AND_ASSIGN(ScopedIOPluginInterface);
73 } // namespace mac
74 } // namespace base
76 #endif // BASE_MAC_SCOPED_IOPLUGININTERFACE_H_