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

Side by Side Diff: chrome/browser/ui/libgtkui/gconf_listener.cc

Issue 2707313002: Gtk: Change NULL to nullptr (Closed)
Patch Set: Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "chrome/browser/ui/libgtkui/gconf_listener.h" 5 #include "chrome/browser/ui/libgtkui/gconf_listener.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 25 matching lines...) Expand all
36 36
37 const char kDefaultButtonString[] = ":minimize,maximize,close"; 37 const char kDefaultButtonString[] = ":minimize,maximize,close";
38 38
39 } // namespace 39 } // namespace
40 40
41 namespace libgtkui { 41 namespace libgtkui {
42 42
43 // Public interface: 43 // Public interface:
44 44
45 GConfListener::GConfListener(GtkUi* delegate) 45 GConfListener::GConfListener(GtkUi* delegate)
46 : delegate_(delegate), client_(NULL) { 46 : delegate_(delegate), client_(nullptr) {
47 std::unique_ptr<base::Environment> env(base::Environment::Create()); 47 std::unique_ptr<base::Environment> env(base::Environment::Create());
48 base::nix::DesktopEnvironment de = 48 base::nix::DesktopEnvironment de =
49 base::nix::GetDesktopEnvironment(env.get()); 49 base::nix::GetDesktopEnvironment(env.get());
50 if (de == base::nix::DESKTOP_ENVIRONMENT_GNOME || 50 if (de == base::nix::DESKTOP_ENVIRONMENT_GNOME ||
51 de == base::nix::DESKTOP_ENVIRONMENT_UNITY || 51 de == base::nix::DESKTOP_ENVIRONMENT_UNITY ||
52 ui::GuessWindowManager() == ui::WM_METACITY) { 52 ui::GuessWindowManager() == ui::WM_METACITY) {
53 client_ = gconf_client_get_default(); 53 client_ = gconf_client_get_default();
54 // If we fail to get a context, that's OK, since we'll just fallback on 54 // If we fail to get a context, that's OK, since we'll just fallback on
55 // not receiving gconf keys. 55 // not receiving gconf keys.
56 if (client_) { 56 if (client_) {
57 // Register that we're interested in the values of this directory. 57 // Register that we're interested in the values of this directory.
58 GError* error = NULL; 58 GError* error = nullptr;
59 gconf_client_add_dir(client_, kMetacityGeneral, 59 gconf_client_add_dir(client_, kMetacityGeneral,
60 GCONF_CLIENT_PRELOAD_ONELEVEL, &error); 60 GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
61 if (HandleGError(error, kMetacityGeneral)) 61 if (HandleGError(error, kMetacityGeneral))
62 return; 62 return;
63 63
64 // Get the initial value of the keys we're interested in. 64 // Get the initial value of the keys we're interested in.
65 GetAndRegister(kButtonLayoutKey, 65 GetAndRegister(kButtonLayoutKey,
66 base::Bind(&GConfListener::ParseAndStoreButtonValue, 66 base::Bind(&GConfListener::ParseAndStoreButtonValue,
67 base::Unretained(this))); 67 base::Unretained(this)));
68 GetAndRegister(kMiddleClickActionKey, 68 GetAndRegister(kMiddleClickActionKey,
69 base::Bind(&GConfListener::ParseAndStoreMiddleClickValue, 69 base::Bind(&GConfListener::ParseAndStoreMiddleClickValue,
70 base::Unretained(this))); 70 base::Unretained(this)));
71 } 71 }
72 } 72 }
73 } 73 }
74 74
75 GConfListener::~GConfListener() { 75 GConfListener::~GConfListener() {
76 } 76 }
77 77
78 // Private: 78 // Private:
79 79
80 void GConfListener::GetAndRegister( 80 void GConfListener::GetAndRegister(
81 const char* key_to_subscribe, 81 const char* key_to_subscribe,
82 const base::Callback<void(GConfValue*)>& initial_setter) { 82 const base::Callback<void(GConfValue*)>& initial_setter) {
83 GError* error = NULL; 83 GError* error = nullptr;
84 GConfValue* gconf_value = gconf_client_get(client_, key_to_subscribe, 84 GConfValue* gconf_value = gconf_client_get(client_, key_to_subscribe,
85 &error); 85 &error);
86 if (HandleGError(error, key_to_subscribe)) 86 if (HandleGError(error, key_to_subscribe))
87 return; 87 return;
88 initial_setter.Run(gconf_value); 88 initial_setter.Run(gconf_value);
89 if (gconf_value) 89 if (gconf_value)
90 gconf_value_free(gconf_value); 90 gconf_value_free(gconf_value);
91 91
92 // Register to get notifies about changes to this key. 92 // Register to get notifies about changes to this key.
93 gconf_client_notify_add( 93 gconf_client_notify_add(
94 client_, key_to_subscribe, 94 client_, key_to_subscribe,
95 reinterpret_cast<void (*)(GConfClient*, guint, GConfEntry*, void*)>( 95 reinterpret_cast<void (*)(GConfClient*, guint, GConfEntry*, void*)>(
96 OnChangeNotificationThunk), 96 OnChangeNotificationThunk),
97 this, NULL, &error); 97 this, nullptr, &error);
98 if (HandleGError(error, key_to_subscribe)) 98 if (HandleGError(error, key_to_subscribe))
99 return; 99 return;
100 } 100 }
101 101
102 void GConfListener::OnChangeNotification(GConfClient* client, 102 void GConfListener::OnChangeNotification(GConfClient* client,
103 guint cnxn_id, 103 guint cnxn_id,
104 GConfEntry* entry) { 104 GConfEntry* entry) {
105 if (strcmp(gconf_entry_get_key(entry), kButtonLayoutKey) == 0) { 105 if (strcmp(gconf_entry_get_key(entry), kButtonLayoutKey) == 0) {
106 GConfValue* gconf_value = gconf_entry_get_value(entry); 106 GConfValue* gconf_value = gconf_entry_get_value(entry);
107 ParseAndStoreButtonValue(gconf_value); 107 ParseAndStoreButtonValue(gconf_value);
108 } else if (strcmp(gconf_entry_get_key(entry), kMiddleClickActionKey) == 0) { 108 } else if (strcmp(gconf_entry_get_key(entry), kMiddleClickActionKey) == 0) {
109 GConfValue* gconf_value = gconf_entry_get_value(entry); 109 GConfValue* gconf_value = gconf_entry_get_value(entry);
110 ParseAndStoreMiddleClickValue(gconf_value); 110 ParseAndStoreMiddleClickValue(gconf_value);
111 } 111 }
112 } 112 }
113 113
114 bool GConfListener::HandleGError(GError* error, const char* key) { 114 bool GConfListener::HandleGError(GError* error, const char* key) {
115 if (error != NULL) { 115 if (error != nullptr) {
116 LOG(ERROR) << "Error with gconf key '" << key << "': " << error->message; 116 LOG(ERROR) << "Error with gconf key '" << key << "': " << error->message;
117 g_error_free(error); 117 g_error_free(error);
118 g_object_unref(client_); 118 g_object_unref(client_);
119 client_ = NULL; 119 client_ = nullptr;
120 return true; 120 return true;
121 } 121 }
122 return false; 122 return false;
123 } 123 }
124 124
125 void GConfListener::ParseAndStoreButtonValue(GConfValue* gconf_value) { 125 void GConfListener::ParseAndStoreButtonValue(GConfValue* gconf_value) {
126 std::string button_string; 126 std::string button_string;
127 if (gconf_value) { 127 if (gconf_value) {
128 const char* value = gconf_value_get_string(gconf_value); 128 const char* value = gconf_value_get_string(gconf_value);
129 button_string = value ? value : kDefaultButtonString; 129 button_string = value ? value : kDefaultButtonString;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // value, we want to default to no action if the user has explicitly 178 // value, we want to default to no action if the user has explicitly
179 // chose an action that we don't implement. 179 // chose an action that we don't implement.
180 action = views::LinuxUI::MIDDLE_CLICK_ACTION_NONE; 180 action = views::LinuxUI::MIDDLE_CLICK_ACTION_NONE;
181 } 181 }
182 } 182 }
183 183
184 delegate_->SetNonClientMiddleClickAction(action); 184 delegate_->SetNonClientMiddleClickAction(action);
185 } 185 }
186 186
187 } // namespace libgtkui 187 } // namespace libgtkui
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtkui/gconf_listener.h ('k') | chrome/browser/ui/libgtkui/gtk_event_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698