summaryrefslogtreecommitdiffstats
path: root/mojo/public/utility/scoped_handle.cc
diff options
context:
space:
mode:
Diffstat (limited to 'mojo/public/utility/scoped_handle.cc')
-rw-r--r--mojo/public/utility/scoped_handle.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/mojo/public/utility/scoped_handle.cc b/mojo/public/utility/scoped_handle.cc
new file mode 100644
index 0000000..cba4b8a
--- /dev/null
+++ b/mojo/public/utility/scoped_handle.cc
@@ -0,0 +1,25 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/utility/scoped_handle.h"
+
+namespace mojo {
+
+ScopedHandle::ScopedHandle(Handle handle) : handle_(handle) {
+}
+
+ScopedHandle::~ScopedHandle() {
+ if (handle_.value == kInvalidHandle.value)
+ return;
+ Close(handle_);
+ Release();
+}
+
+Handle ScopedHandle::Release() {
+ Handle temp = handle_;
+ handle_ = kInvalidHandle;
+ return temp;
+}
+
+} // namespace mojo