From edf2446e7fc35186b96fa79ef23100d488beff3d Mon Sep 17 00:00:00 2001 From: "jam@chromium.org" Date: Mon, 22 Sep 2008 22:40:21 +0000 Subject: My base changes to the plugin code. Review URL: http://codereview.chromium.org/3197 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2460 0039d316-1c4b-4281-b951-d872f2087c98 --- base/scoped_handle.h | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'base') diff --git a/base/scoped_handle.h b/base/scoped_handle.h index 49c9833..5f12af1 100644 --- a/base/scoped_handle.h +++ b/base/scoped_handle.h @@ -105,16 +105,26 @@ class ScopedFindFileHandle { // CreateCompatibleDC. For an HDC returned by GetDC, use ReleaseDC instead. class ScopedHDC { public: + ScopedHDC() : hdc_(NULL) { } explicit ScopedHDC(HDC h) : hdc_(h) { } ~ScopedHDC() { - if (hdc_) - DeleteDC(hdc_); + Close(); + } + + void Set(HDC h) { + Close(); + hdc_ = h; } operator HDC() { return hdc_; } private: + void Close() { + if (hdc_) + DeleteDC(hdc_); + } + HDC hdc_; DISALLOW_EVIL_CONSTRUCTORS(ScopedHDC); }; @@ -122,16 +132,26 @@ class ScopedHDC { // Like ScopedHandle but for HBITMAP. class ScopedBitmap { public: + ScopedBitmap() : hbitmap_(NULL) { } explicit ScopedBitmap(HBITMAP h) : hbitmap_(h) { } ~ScopedBitmap() { - if (hbitmap_) - DeleteObject(hbitmap_); + Close(); + } + + void Set(HBITMAP h) { + Close(); + hbitmap_ = h; } operator HBITMAP() { return hbitmap_; } private: + void Close() { + if (hbitmap_) + DeleteObject(hbitmap_); + } + HBITMAP hbitmap_; DISALLOW_EVIL_CONSTRUCTORS(ScopedBitmap); }; -- cgit v1.1