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" |
| 11 #include "base/gtest_prod_util.h" |
11 #include "base/location.h" | 12 #include "base/location.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/move.h" | 15 #include "base/move.h" |
15 | 16 |
16 // TODO(rvargas): remove this with the rest of the verifier. | 17 // TODO(rvargas): remove this with the rest of the verifier. |
17 #if defined(COMPILER_MSVC) | 18 #if defined(COMPILER_MSVC) |
18 #include <intrin.h> | 19 #include <intrin.h> |
19 #define BASE_WIN_GET_CALLER _ReturnAddress() | 20 #define BASE_WIN_GET_CALLER _ReturnAddress() |
20 #elif defined(COMPILER_GCC) | 21 #elif defined(COMPILER_GCC) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 if (Traits::IsHandleValid(handle_)) { | 102 if (Traits::IsHandleValid(handle_)) { |
102 Verifier::StopTracking(handle_, this, BASE_WIN_GET_CALLER, | 103 Verifier::StopTracking(handle_, this, BASE_WIN_GET_CALLER, |
103 tracked_objects::GetProgramCounter()); | 104 tracked_objects::GetProgramCounter()); |
104 | 105 |
105 Traits::CloseHandle(handle_); | 106 Traits::CloseHandle(handle_); |
106 handle_ = Traits::NullHandle(); | 107 handle_ = Traits::NullHandle(); |
107 } | 108 } |
108 } | 109 } |
109 | 110 |
110 private: | 111 private: |
| 112 FRIEND_TEST_ALL_PREFIXES(ScopedHandleTest, ActiveVerifierWrongOwner); |
| 113 FRIEND_TEST_ALL_PREFIXES(ScopedHandleTest, ActiveVerifierUntrackedHandle); |
111 Handle handle_; | 114 Handle handle_; |
112 }; | 115 }; |
113 | 116 |
114 #undef BASE_WIN_GET_CALLER | 117 #undef BASE_WIN_GET_CALLER |
115 | 118 |
116 // The traits class for Win32 handles that can be closed via CloseHandle() API. | 119 // The traits class for Win32 handles that can be closed via CloseHandle() API. |
117 class HandleTraits { | 120 class HandleTraits { |
118 public: | 121 public: |
119 typedef HANDLE Handle; | 122 typedef HANDLE Handle; |
120 | 123 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // This should be called whenever the OS is closing a handle, if extended | 176 // This should be called whenever the OS is closing a handle, if extended |
174 // verification of improper handle closing is desired. If |handle| is being | 177 // verification of improper handle closing is desired. If |handle| is being |
175 // tracked by the handle verifier and ScopedHandle is not the one closing it, | 178 // tracked by the handle verifier and ScopedHandle is not the one closing it, |
176 // a CHECK is generated. | 179 // a CHECK is generated. |
177 void BASE_EXPORT OnHandleBeingClosed(HANDLE handle); | 180 void BASE_EXPORT OnHandleBeingClosed(HANDLE handle); |
178 | 181 |
179 } // namespace win | 182 } // namespace win |
180 } // namespace base | 183 } // namespace base |
181 | 184 |
182 #endif // BASE_WIN_SCOPED_HANDLE_H_ | 185 #endif // BASE_WIN_SCOPED_HANDLE_H_ |
OLD | NEW |