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 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 public: | 42 public: |
43 typedef typename Traits::Handle Handle; | 43 typedef typename Traits::Handle Handle; |
44 | 44 |
45 GenericScopedHandle() : handle_(Traits::NullHandle()) {} | 45 GenericScopedHandle() : handle_(Traits::NullHandle()) {} |
46 | 46 |
47 explicit GenericScopedHandle(Handle handle) : handle_(Traits::NullHandle()) { | 47 explicit GenericScopedHandle(Handle handle) : handle_(Traits::NullHandle()) { |
48 Set(handle); | 48 Set(handle); |
49 } | 49 } |
50 | 50 |
51 // Move constructor for C++03 move emulation of this type. | 51 // Move constructor for C++03 move emulation of this type. |
52 GenericScopedHandle(RValue& other) : handle_(Traits::NullHandle()) { | 52 GenericScopedHandle(RValue other) : handle_(Traits::NullHandle()) { |
53 Set(other.Take()); | 53 if (this != other.object) { |
Jeffrey Yasskin
2012/10/12 20:34:47
I think this can never be false.
awong
2012/10/12 20:44:12
Oops. This was a error during a revert. Fixed.
| |
54 Set(other.object->Take()); | |
55 } | |
54 } | 56 } |
55 | 57 |
56 ~GenericScopedHandle() { | 58 ~GenericScopedHandle() { |
57 Close(); | 59 Close(); |
58 } | 60 } |
59 | 61 |
60 bool IsValid() const { | 62 bool IsValid() const { |
61 return Traits::IsHandleValid(handle_); | 63 return Traits::IsHandleValid(handle_); |
62 } | 64 } |
63 | 65 |
64 // Move operator= for C++03 move emulation of this type. | 66 // Move operator= for C++03 move emulation of this type. |
65 GenericScopedHandle& operator=(RValue& other) { | 67 GenericScopedHandle& operator=(RValue other) { |
66 if (this != &other) { | 68 Set(other.object->Take()); |
67 Set(other.Take()); | |
68 } | |
69 return *this; | 69 return *this; |
70 } | 70 } |
71 | 71 |
72 void Set(Handle handle) { | 72 void Set(Handle handle) { |
73 if (handle_ != handle) { | 73 if (handle_ != handle) { |
74 Close(); | 74 Close(); |
75 | 75 |
76 if (Traits::IsHandleValid(handle)) { | 76 if (Traits::IsHandleValid(handle)) { |
77 handle_ = handle; | 77 handle_ = handle; |
78 Verifier::StartTracking(handle, this, BASE_WIN_GET_CALLER, | 78 Verifier::StartTracking(handle, this, BASE_WIN_GET_CALLER, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 private: | 179 private: |
180 DISALLOW_IMPLICIT_CONSTRUCTORS(VerifierTraits); | 180 DISALLOW_IMPLICIT_CONSTRUCTORS(VerifierTraits); |
181 }; | 181 }; |
182 | 182 |
183 typedef GenericScopedHandle<HandleTraits, VerifierTraits> ScopedHandle; | 183 typedef GenericScopedHandle<HandleTraits, VerifierTraits> ScopedHandle; |
184 | 184 |
185 } // namespace win | 185 } // namespace win |
186 } // namespace base | 186 } // namespace base |
187 | 187 |
188 #endif // BASE_SCOPED_HANDLE_WIN_H_ | 188 #endif // BASE_SCOPED_HANDLE_WIN_H_ |
OLD | NEW |