Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Side by Side Diff: base/win/scoped_handle.h

Issue 510633002: Improve the ScopedHandle verifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comment to the lock Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/win/scoped_handle.cc » ('j') | chrome/chrome_dll.gypi » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 94 }
95 return temp; 95 return temp;
96 } 96 }
97 97
98 // Explicitly closes the owned handle. 98 // Explicitly closes the owned handle.
99 void Close() { 99 void Close() {
100 if (Traits::IsHandleValid(handle_)) { 100 if (Traits::IsHandleValid(handle_)) {
101 Verifier::StopTracking(handle_, this, BASE_WIN_GET_CALLER, 101 Verifier::StopTracking(handle_, this, BASE_WIN_GET_CALLER,
102 tracked_objects::GetProgramCounter()); 102 tracked_objects::GetProgramCounter());
103 103
104 if (!Traits::CloseHandle(handle_)) 104 Traits::CloseHandle(handle_);
105 CHECK(false);
106
107 handle_ = Traits::NullHandle(); 105 handle_ = Traits::NullHandle();
108 } 106 }
109 } 107 }
110 108
111 private: 109 private:
112 Handle handle_; 110 Handle handle_;
113 }; 111 };
114 112
115 #undef BASE_WIN_GET_CALLER 113 #undef BASE_WIN_GET_CALLER
116 114
117 // The traits class for Win32 handles that can be closed via CloseHandle() API. 115 // The traits class for Win32 handles that can be closed via CloseHandle() API.
118 class HandleTraits { 116 class HandleTraits {
119 public: 117 public:
120 typedef HANDLE Handle; 118 typedef HANDLE Handle;
121 119
122 // Closes the handle. 120 // Closes the handle.
123 static bool CloseHandle(HANDLE handle) { 121 static bool BASE_EXPORT CloseHandle(HANDLE handle);
124 return ::CloseHandle(handle) != FALSE;
125 }
126 122
127 // Returns true if the handle value is valid. 123 // Returns true if the handle value is valid.
128 static bool IsHandleValid(HANDLE handle) { 124 static bool IsHandleValid(HANDLE handle) {
129 return handle != NULL && handle != INVALID_HANDLE_VALUE; 125 return handle != NULL && handle != INVALID_HANDLE_VALUE;
130 } 126 }
131 127
132 // Returns NULL handle value. 128 // Returns NULL handle value.
133 static HANDLE NullHandle() { 129 static HANDLE NullHandle() {
134 return NULL; 130 return NULL;
135 } 131 }
(...skipping 25 matching lines...) Expand all
161 const void* pc1, const void* pc2); 157 const void* pc1, const void* pc2);
162 static void StopTracking(HANDLE handle, const void* owner, 158 static void StopTracking(HANDLE handle, const void* owner,
163 const void* pc1, const void* pc2); 159 const void* pc1, const void* pc2);
164 160
165 private: 161 private:
166 DISALLOW_IMPLICIT_CONSTRUCTORS(VerifierTraits); 162 DISALLOW_IMPLICIT_CONSTRUCTORS(VerifierTraits);
167 }; 163 };
168 164
169 typedef GenericScopedHandle<HandleTraits, VerifierTraits> ScopedHandle; 165 typedef GenericScopedHandle<HandleTraits, VerifierTraits> ScopedHandle;
170 166
167 // This function may be called by the embedder to disable the use of
168 // VerifierTraits at runtime. It has no effect if DummyVerifierTraits is used
169 // for ScopedHandle.
170 void BASE_EXPORT DisableHandleVerifier();
171
172 // This should be called whenever the OS is closing a handle, if extended
173 // verification of improper handle closing is desired. If |handle| is being
174 // tracked by the handle verifier and ScopedHandle is not the one closing it,
175 // a CHECK is generated.
176 void BASE_EXPORT OnHandleBeingClosed(HANDLE handle);
177
171 } // namespace win 178 } // namespace win
172 } // namespace base 179 } // namespace base
173 180
174 #endif // BASE_SCOPED_HANDLE_WIN_H_ 181 #endif // BASE_SCOPED_HANDLE_WIN_H_
OLDNEW
« no previous file with comments | « no previous file | base/win/scoped_handle.cc » ('j') | chrome/chrome_dll.gypi » ('J')

Powered by Google App Engine
This is Rietveld 408576698