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

Unified Diff: base/win/scoped_handle.h

Issue 9516010: Added PrinterDriverInfo and PrintBackend::GetPrinterDriverInfo for windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 10 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
« no previous file with comments | « no previous file | printing/backend/print_backend.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | printing/backend/print_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698