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

Unified Diff: base/win/scoped_gdi_object.h

Issue 1406403007: Eliminate HICON leaks caused by creating icons from bitmap image. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nullptr issue in ScopedGDIObject. Created 5 years, 1 month 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 | chrome/browser/ui/views/frame/glass_browser_frame_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/win/scoped_gdi_object.h
diff --git a/base/win/scoped_gdi_object.h b/base/win/scoped_gdi_object.h
index 57b013e2fbaae8cf80fc7f32a452b204fc4b923c..f26685cee9e0745a2a761e03711178ded046d43a 100644
--- a/base/win/scoped_gdi_object.h
+++ b/base/win/scoped_gdi_object.h
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/move.h"
namespace base {
namespace win {
@@ -16,10 +17,20 @@ namespace win {
// Like ScopedHandle but for GDI objects.
template<class T>
class ScopedGDIObject {
grt (UTC plus 2) 2015/11/06 19:49:20 can you implement this in terms of ScopedGeneric?
anpol 2015/11/06 20:28:16 Looking at ScopedGeneric briefly: * ScopedGDIObje
+ MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedGDIObject)
+
public:
- ScopedGDIObject() : object_(NULL) {}
+ ScopedGDIObject() : object_(nullptr) {}
+ ScopedGDIObject(decltype(nullptr)) : object_(nullptr) {}
+
+ // Constructor that takes ownership of an object.
explicit ScopedGDIObject(T object) : object_(object) {}
+ // Constructor that transfers ownership from another ScopedGDIObject.
+ ScopedGDIObject(ScopedGDIObject&& other) : object_(nullptr) {
+ Set(other.release());
+ }
+
~ScopedGDIObject() {
Close();
}
@@ -34,14 +45,27 @@ class ScopedGDIObject {
object_ = object;
}
+ // operator= that deletes the currently owned object, if any.
+ ScopedGDIObject& operator=(decltype(nullptr)) {
+ Set(nullptr);
+ return *this;
+ }
+
+ // operator= that takes ownership of an object.
ScopedGDIObject& operator=(T object) {
Set(object);
return *this;
}
+ // operator= that transfers ownership from another ScopedGDIObject.
+ ScopedGDIObject& operator=(ScopedGDIObject&& rhs) {
+ Set(rhs.release());
+ return *this;
+ }
+
T release() {
T object = object_;
- object_ = NULL;
+ object_ = nullptr;
return object;
}
@@ -54,7 +78,6 @@ class ScopedGDIObject {
}
T object_;
- DISALLOW_COPY_AND_ASSIGN(ScopedGDIObject);
};
// An explicit specialization for HICON because we have to call DestroyIcon()
« no previous file with comments | « no previous file | chrome/browser/ui/views/frame/glass_browser_frame_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698