| 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
|
|
|
|
|