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

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: Add move semantics to 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
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..e61cc6208cb13f901a84912f0d27ab1f4ab52859 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 {
+ MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedGDIObject)
+
public:
+ // Constructor that defaults to initializing with NULL.
ScopedGDIObject() : object_(NULL) {}
+
+ // Constructor that takes ownership of an object.
sky 2015/11/03 17:23:15 This comment is useful as it clearly documents own
explicit ScopedGDIObject(T object) : object_(object) {}
+ // Constructor that allows construction from an rvalue.
+ ScopedGDIObject(ScopedGDIObject&& other) : object_(NULL) {
sky 2015/11/03 17:23:14 If you can, make these nullptr.
+ Set(other.release());
+ }
+
~ScopedGDIObject() {
Close();
}
@@ -34,11 +45,18 @@ class ScopedGDIObject {
object_ = object;
}
+ // operator= that takes ownership of an object.
ScopedGDIObject& operator=(T object) {
Set(object);
return *this;
}
+ // operator= that allows assignment from an rvalue.
+ ScopedGDIObject& operator=(ScopedGDIObject&& rhs) {
+ Set(rhs.release());
+ return *this;
+ }
+
T release() {
T object = object_;
object_ = NULL;
@@ -54,7 +72,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') | ui/views/win/hwnd_message_handler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698