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