Chromium Code Reviews| 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_WIN_SCOPED_HANDLE_H_ | 5 #ifndef BASE_WIN_SCOPED_HANDLE_H_ |
| 6 #define BASE_WIN_SCOPED_HANDLE_H_ | 6 #define BASE_WIN_SCOPED_HANDLE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 | 34 |
| 35 ~GenericScopedHandle() { | 35 ~GenericScopedHandle() { |
| 36 Close(); | 36 Close(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool IsValid() const { | 39 bool IsValid() const { |
| 40 return Traits::IsHandleValid(handle_); | 40 return Traits::IsHandleValid(handle_); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void Set(Handle handle) { | 43 void Set(Handle handle) { |
| 44 if (handle_ != handle) { | 44 if (!Traits::IsSame(handle_, handle)) { |
| 45 Close(); | 45 Close(); |
| 46 | 46 |
| 47 if (Traits::IsHandleValid(handle)) { | 47 if (Traits::IsHandleValid(handle)) { |
| 48 handle_ = handle; | 48 handle_ = handle; |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 Handle Get() const { | 53 Handle Get() const { |
| 54 return handle_; | 54 return handle_; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 // Closes the handle. | 94 // Closes the handle. |
| 95 static bool CloseHandle(HANDLE handle) { | 95 static bool CloseHandle(HANDLE handle) { |
| 96 return ::CloseHandle(handle) != FALSE; | 96 return ::CloseHandle(handle) != FALSE; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Returns true if the handle value is valid. | 99 // Returns true if the handle value is valid. |
| 100 static bool IsHandleValid(HANDLE handle) { | 100 static bool IsHandleValid(HANDLE handle) { |
| 101 return handle != NULL && handle != INVALID_HANDLE_VALUE; | 101 return handle != NULL && handle != INVALID_HANDLE_VALUE; |
| 102 } | 102 } |
| 103 | 103 |
| 104 // Returns true if the handle values are the same. | |
| 105 static bool IsSame(HANDLE lhs, HANDLE rhs) { | |
|
alexeypa (please no reviews)
2012/03/15 02:41:31
We will be able to avoid changing all instances of
erikwright (departed)
2012/03/15 03:29:17
I thought about listing this as one of my proposed
| |
| 106 return lhs == rhs; | |
| 107 } | |
| 108 | |
| 104 // Returns NULL handle value. | 109 // Returns NULL handle value. |
| 105 static HANDLE NullHandle() { | 110 static HANDLE NullHandle() { |
| 106 return NULL; | 111 return NULL; |
| 107 } | 112 } |
| 108 | 113 |
| 109 private: | 114 private: |
| 110 DISALLOW_IMPLICIT_CONSTRUCTORS(HandleTraits); | 115 DISALLOW_IMPLICIT_CONSTRUCTORS(HandleTraits); |
| 111 }; | 116 }; |
| 112 | 117 |
| 113 typedef GenericScopedHandle<HandleTraits> ScopedHandle; | 118 typedef GenericScopedHandle<HandleTraits> ScopedHandle; |
| 114 | 119 |
| 115 } // namespace win | 120 } // namespace win |
| 116 } // namespace base | 121 } // namespace base |
| 117 | 122 |
| 118 #endif // BASE_SCOPED_HANDLE_WIN_H_ | 123 #endif // BASE_SCOPED_HANDLE_WIN_H_ |
| OLD | NEW |