Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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. | |
| 4 | |
| 5 #include "base/files/scoped_platform_handle.h" | |
| 6 | |
| 7 namespace base { | |
| 8 | |
| 9 ScopedPlatformHandle::ScopedPlatformHandle() : ScopedPlatformHandle(nullptr) {} | |
| 10 | |
| 11 ScopedPlatformHandle::ScopedPlatformHandle(std::nullptr_t) {} | |
| 12 | |
| 13 ScopedPlatformHandle::ScopedPlatformHandle(ScopedPlatformHandle&& other) { | |
| 14 *this = std::move(other); | |
| 15 } | |
| 16 | |
| 17 ScopedPlatformHandle::ScopedPlatformHandle(HandleType handle) | |
| 18 : handle_(handle) {} | |
| 19 | |
| 20 ScopedPlatformHandle::ScopedPlatformHandle(ScopedHandleType handle) | |
| 21 : handle_(std::move(handle)) {} | |
| 22 | |
| 23 ScopedPlatformHandle::~ScopedPlatformHandle() {} | |
| 24 | |
| 25 ScopedPlatformHandle& ScopedPlatformHandle::operator=( | |
| 26 ScopedPlatformHandle&& other) { | |
|
dcheng
2017/02/23 21:45:37
If you want, this and the move ctor can be = defau
| |
| 27 handle_ = std::move(other.handle_); | |
| 28 return *this; | |
| 29 } | |
| 30 | |
| 31 bool ScopedPlatformHandle::is_valid() const { | |
| 32 #if defined(OS_WIN) | |
|
dcheng
2017/02/23 21:45:37
Most of the time we have files like this, we just
| |
| 33 return handle_.IsValid(); | |
| 34 #elif defined(OS_POSIX) | |
| 35 return handle_.is_valid(); | |
| 36 #endif | |
| 37 } | |
| 38 | |
| 39 void ScopedPlatformHandle::reset() { | |
| 40 #if defined(OS_WIN) | |
| 41 handle_.Close(); | |
| 42 #elif defined(OS_POSIX) | |
| 43 handle_.reset(); | |
| 44 #endif | |
| 45 } | |
| 46 | |
| 47 ScopedPlatformHandle::HandleType ScopedPlatformHandle::get() const { | |
| 48 #if defined(OS_WIN) | |
| 49 return handle_.Get(); | |
| 50 #elif defined(OS_POSIX) | |
| 51 return handle_.get(); | |
| 52 #endif | |
| 53 } | |
| 54 | |
| 55 ScopedPlatformHandle::HandleType ScopedPlatformHandle::release() { | |
| 56 #if defined(OS_WIN) | |
| 57 return handle_.Take(); | |
| 58 #elif defined(OS_POSIX) | |
| 59 return handle_.release(); | |
| 60 #endif | |
| 61 } | |
| 62 | |
| 63 ScopedPlatformHandle::ScopedHandleType ScopedPlatformHandle::Take() { | |
| 64 return ScopedHandleType(release()); | |
| 65 } | |
| 66 | |
| 67 } // namespace base | |
| OLD | NEW |