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

Unified Diff: base/files/scoped_platform_handle.cc

Issue 2705743002: Introduce base::ScopedPlatformHandle (Closed)
Patch Set: . Created 3 years, 10 months 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/files/scoped_platform_handle.cc
diff --git a/base/files/scoped_platform_handle.cc b/base/files/scoped_platform_handle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..64dc05b200de28c85fea30c4f783776d73a33a97
--- /dev/null
+++ b/base/files/scoped_platform_handle.cc
@@ -0,0 +1,67 @@
+// Copyright 2017 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 "base/files/scoped_platform_handle.h"
+
+namespace base {
+
+ScopedPlatformHandle::ScopedPlatformHandle() : ScopedPlatformHandle(nullptr) {}
+
+ScopedPlatformHandle::ScopedPlatformHandle(std::nullptr_t) {}
+
+ScopedPlatformHandle::ScopedPlatformHandle(ScopedPlatformHandle&& other) {
+ *this = std::move(other);
+}
+
+ScopedPlatformHandle::ScopedPlatformHandle(HandleType handle)
+ : handle_(handle) {}
+
+ScopedPlatformHandle::ScopedPlatformHandle(ScopedHandleType handle)
+ : handle_(std::move(handle)) {}
+
+ScopedPlatformHandle::~ScopedPlatformHandle() {}
+
+ScopedPlatformHandle& ScopedPlatformHandle::operator=(
+ ScopedPlatformHandle&& other) {
dcheng 2017/02/23 21:45:37 If you want, this and the move ctor can be = defau
+ handle_ = std::move(other.handle_);
+ return *this;
+}
+
+bool ScopedPlatformHandle::is_valid() const {
+#if defined(OS_WIN)
dcheng 2017/02/23 21:45:37 Most of the time we have files like this, we just
+ return handle_.IsValid();
+#elif defined(OS_POSIX)
+ return handle_.is_valid();
+#endif
+}
+
+void ScopedPlatformHandle::reset() {
+#if defined(OS_WIN)
+ handle_.Close();
+#elif defined(OS_POSIX)
+ handle_.reset();
+#endif
+}
+
+ScopedPlatformHandle::HandleType ScopedPlatformHandle::get() const {
+#if defined(OS_WIN)
+ return handle_.Get();
+#elif defined(OS_POSIX)
+ return handle_.get();
+#endif
+}
+
+ScopedPlatformHandle::HandleType ScopedPlatformHandle::release() {
+#if defined(OS_WIN)
+ return handle_.Take();
+#elif defined(OS_POSIX)
+ return handle_.release();
+#endif
+}
+
+ScopedPlatformHandle::ScopedHandleType ScopedPlatformHandle::Take() {
+ return ScopedHandleType(release());
+}
+
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698