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

Unified Diff: base/win/scoped_handle.h

Issue 10453082: Base: Add a handle verifier to ScopedHandle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: base/win/scoped_handle.h
===================================================================
--- base/win/scoped_handle.h (revision 139138)
+++ base/win/scoped_handle.h (working copy)
@@ -8,7 +8,9 @@
#include <windows.h>
+#include "base/base_export.h"
#include "base/basictypes.h"
+#include "base/location.h"
#include "base/logging.h"
namespace base {
@@ -21,7 +23,7 @@
// and INVALID_HANDLE_VALUE (-1) for Win32 handles.
// - Receive() method allows to receive a handle value from a function that
// takes a raw handle pointer only.
-template <class Traits>
+template <class Traits, class Verifier>
class GenericScopedHandle {
public:
typedef typename Traits::Handle Handle;
@@ -46,6 +48,8 @@
if (Traits::IsHandleValid(handle)) {
handle_ = handle;
+ Verifier::StartTracking(handle, this,
+ tracked_objects::GetProgramCounter());
}
}
}
@@ -60,6 +64,10 @@
Handle* Receive() {
DCHECK(!Traits::IsHandleValid(handle_)) << "Handle must be NULL";
+
+ // We cannot track this case :(. Just tell the verifier about it.
+ Verifier::StartTracking(INVALID_HANDLE_VALUE, this,
+ tracked_objects::GetProgramCounter());
return &handle_;
}
@@ -67,6 +75,7 @@
Handle Take() {
Handle temp = handle_;
handle_ = Traits::NullHandle();
+ Verifier::StopTracking(temp, this, tracked_objects::GetProgramCounter());
return temp;
}
@@ -76,6 +85,8 @@
if (!Traits::CloseHandle(handle_)) {
CHECK(false);
}
+ Verifier::StopTracking(handle_, this,
+ tracked_objects::GetProgramCounter());
handle_ = Traits::NullHandle();
}
}
@@ -110,8 +121,32 @@
DISALLOW_IMPLICIT_CONSTRUCTORS(HandleTraits);
};
-typedef GenericScopedHandle<HandleTraits> ScopedHandle;
+// Do-nothing verifier.
+class DummyVerifierTraits {
+ public:
+ typedef HANDLE Handle;
+ static void StartTracking(HANDLE handle, const void* owner, const void* pc) {}
+ static void StopTracking(HANDLE handle, const void* owner, const void* pc) {}
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(DummyVerifierTraits);
+};
+
+// Performs actual run-time tracking.
+class BASE_EXPORT VerifierTraits {
+ public:
+ typedef HANDLE Handle;
+
+ static void StartTracking(HANDLE handle, const void* owner, const void* pc);
+ static void StopTracking(HANDLE handle, const void* owner, const void* pc);
+
+ private:
+ DISALLOW_IMPLICIT_CONSTRUCTORS(VerifierTraits);
+};
+
+typedef GenericScopedHandle<HandleTraits, DummyVerifierTraits> ScopedHandle;
+
} // namespace win
} // namespace base
« no previous file with comments | « base/base.gypi ('k') | base/win/scoped_handle.cc » ('j') | base/win/scoped_handle.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698