| 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 BASE_MAC_SCOPED_MACH_PORT_H_ | 5 #ifndef BASE_MAC_SCOPED_MACH_PORT_H_ |
| 6 #define BASE_MAC_SCOPED_MACH_PORT_H_ | 6 #define BASE_MAC_SCOPED_MACH_PORT_H_ |
| 7 | 7 |
| 8 #include <mach/mach.h> | 8 #include <mach/mach.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 namespace mac { | 14 namespace mac { |
| 15 | 15 |
| 16 // A class for managing the life of a Mach port, releasing via | 16 // A class for managing the life of a Mach port, releasing via |
| 17 // mach_port_deallocate either its send and/or receive rights. | 17 // mach_port_deallocate either its send and/or receive rights. |
| 18 class BASE_EXPORT ScopedMachPort { | 18 class BASE_EXPORT ScopedMachPort { |
| 19 public: | 19 public: |
| 20 // Creates a scoper by taking ownership of the port. | 20 // Creates a scoper by taking ownership of the port. |
| 21 explicit ScopedMachPort(mach_port_t port); | 21 explicit ScopedMachPort(mach_port_t port); |
| 22 | 22 |
| 23 ~ScopedMachPort(); | 23 ~ScopedMachPort(); |
| 24 | 24 |
| 25 void reset(mach_port_t port = MACH_PORT_NULL); |
| 26 |
| 25 operator mach_port_t() const { | 27 operator mach_port_t() const { |
| 26 return port_; | 28 return port_; |
| 27 } | 29 } |
| 28 | 30 |
| 29 mach_port_t get() const { | 31 mach_port_t get() const { |
| 30 return port_; | 32 return port_; |
| 31 } | 33 } |
| 32 | 34 |
| 33 private: | 35 private: |
| 34 mach_port_t port_; | 36 mach_port_t port_; |
| 35 | 37 |
| 36 DISALLOW_COPY_AND_ASSIGN(ScopedMachPort); | 38 DISALLOW_COPY_AND_ASSIGN(ScopedMachPort); |
| 37 }; | 39 }; |
| 38 | 40 |
| 39 } // namespace mac | 41 } // namespace mac |
| 40 } // namespace base | 42 } // namespace base |
| 41 | 43 |
| 42 #endif // BASE_MAC_SCOPED_MACH_PORT_H_ | 44 #endif // BASE_MAC_SCOPED_MACH_PORT_H_ |
| OLD | NEW |