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

Side by Side Diff: ui/base/glib/scoped_gobject.h

Issue 2854773002: Gtk3: Fix black patches on GtkFileChooser dialogs (Closed)
Patch Set: . Created 3 years, 7 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/libgtkui/native_theme_gtk3.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef UI_BASE_GLIB_SCOPED_GOBJECT_H_ 5 #ifndef UI_BASE_GLIB_SCOPED_GOBJECT_H_
6 #define UI_BASE_GLIB_SCOPED_GOBJECT_H_ 6 #define UI_BASE_GLIB_SCOPED_GOBJECT_H_
7 7
8 // Similar in spirit to a std::unique_ptr. 8 // Similar in spirit to a std::unique_ptr.
9 template <typename T> 9 template <typename T>
10 class ScopedGObject { 10 class ScopedGObject {
(...skipping 12 matching lines...) Expand all
23 23
24 ScopedGObject<T>& operator=(const ScopedGObject<T>& other) = delete; 24 ScopedGObject<T>& operator=(const ScopedGObject<T>& other) = delete;
25 25
26 ScopedGObject<T>& operator=(ScopedGObject<T>&& other) { 26 ScopedGObject<T>& operator=(ScopedGObject<T>&& other) {
27 reset(); 27 reset();
28 obj_ = other.obj_; 28 obj_ = other.obj_;
29 other.obj_ = nullptr; 29 other.obj_ = nullptr;
30 return *this; 30 return *this;
31 } 31 }
32 32
33 T* get() { return obj_; }
34
33 operator T*() { return obj_; } 35 operator T*() { return obj_; }
34 36
35 void reset(T* obj = nullptr) { 37 void reset(T* obj = nullptr) {
36 Unref(); 38 Unref();
37 obj_ = obj; 39 obj_ = obj;
38 Ref(); 40 Ref();
39 } 41 }
40 42
41 private: 43 private:
42 void Ref() { 44 void Ref() {
43 // Remove the floating reference from |obj_| if it has one. 45 // Remove the floating reference from |obj_| if it has one.
44 if (obj_ && g_object_is_floating(obj_)) 46 if (obj_ && g_object_is_floating(obj_))
45 g_object_ref_sink(obj_); 47 g_object_ref_sink(obj_);
46 } 48 }
47 49
48 // This function is necessary so that libgtkui can overload it in 50 // This function is necessary so that libgtkui can overload it in
49 // the case of T = GtkStyleContext. 51 // the case of T = GtkStyleContext.
50 void Unref() { 52 void Unref() {
51 if (obj_) 53 if (obj_)
52 g_object_unref(obj_); 54 g_object_unref(obj_);
53 } 55 }
54 56
55 T* obj_; 57 T* obj_;
56 }; 58 };
57 59
58 #endif // UI_BASE_GLIB_SCOPED_GOBJECT_H_ 60 #endif // UI_BASE_GLIB_SCOPED_GOBJECT_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtkui/native_theme_gtk3.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698