Chromium Code Reviews| Index: base/win/scoped_handle.h |
| diff --git a/base/win/scoped_handle.h b/base/win/scoped_handle.h |
| index 3bb0279648aef9c785a440659c2336b893606ce4..88f3342a221abdb9ee0eacef01bf05929cfa1b62 100644 |
| --- a/base/win/scoped_handle.h |
| +++ b/base/win/scoped_handle.h |
| @@ -30,16 +30,17 @@ namespace win { |
| // |
| // To explicitly close the handle: |
| // hfile.Close(); |
| -class ScopedHandle { |
| +template <class Traits> |
| +class GenericScopedHandle { |
|
Albert Bodenhamer
2012/03/02 21:14:03
If you need to change ScopedHandle it's probably w
|
| public: |
| - ScopedHandle() : handle_(NULL) { |
| + GenericScopedHandle() : handle_(NULL) { |
| } |
| - explicit ScopedHandle(HANDLE h) : handle_(NULL) { |
| + explicit GenericScopedHandle(HANDLE h) : handle_(NULL) { |
| Set(h); |
| } |
| - ~ScopedHandle() { |
| + ~GenericScopedHandle() { |
| Close(); |
| } |
| @@ -63,6 +64,11 @@ class ScopedHandle { |
| operator HANDLE() { return handle_; } |
| + HANDLE* Receive() { |
| + DCHECK(!handle_) << "Handle must be NULL"; |
| + return &handle_; |
| + } |
| + |
| HANDLE Take() { |
| // transfers ownership away from this object |
| HANDLE h = handle_; |
| @@ -72,7 +78,7 @@ class ScopedHandle { |
| void Close() { |
| if (handle_) { |
| - if (!::CloseHandle(handle_)) { |
| + if (!Traits::CloseHandle(handle_)) { |
| NOTREACHED(); |
| } |
| handle_ = NULL; |
| @@ -81,9 +87,18 @@ class ScopedHandle { |
| private: |
| HANDLE handle_; |
| - DISALLOW_COPY_AND_ASSIGN(ScopedHandle); |
| + DISALLOW_COPY_AND_ASSIGN(GenericScopedHandle); |
| }; |
| +class DefaultHandleTraits { |
| + public: |
| + static bool CloseHandle(HANDLE handle) { |
| + return ::CloseHandle(handle) != FALSE; |
| + } |
| +}; |
| + |
| +typedef GenericScopedHandle<DefaultHandleTraits> ScopedHandle; |
| + |
| } // namespace win |
| } // namespace base |