summaryrefslogtreecommitdiffstats
path: root/net/proxy
diff options
context:
space:
mode:
authorbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-20 20:30:26 +0000
committerbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-20 20:30:26 +0000
commit4cf80f0b37d56e04e2880b8edbec3acfe9960752 (patch)
tree698a30a1a16a815d502e295d33fb06c2e1f1a345 /net/proxy
parented495fc6183037582e4aa339459eee0a12ddd453 (diff)
downloadchromium_src-4cf80f0b37d56e04e2880b8edbec3acfe9960752.zip
chromium_src-4cf80f0b37d56e04e2880b8edbec3acfe9960752.tar.gz
chromium_src-4cf80f0b37d56e04e2880b8edbec3acfe9960752.tar.bz2
LBYL on GSettings
Fixes a regression from r85968. On my Ubuntu 10.10 box, g_settings_new does not fail gracefully if the schema is not found: it calls an assert. This checks if the schema exists first. The docs for g_settings_list_schemas specify not to modify or release the return value. BUG=83376 TEST=by hand and trybots Review URL: http://codereview.chromium.org/6990008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86140 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy')
-rw-r--r--net/proxy/proxy_config_service_linux.cc25
1 files changed, 20 insertions, 5 deletions
diff --git a/net/proxy/proxy_config_service_linux.cc b/net/proxy/proxy_config_service_linux.cc
index c575584..3e60dc4 100644
--- a/net/proxy/proxy_config_service_linux.cc
+++ b/net/proxy/proxy_config_service_linux.cc
@@ -522,6 +522,16 @@ class SettingGetterImplGSettings
#endif
}
+ bool SchemaExists(const char* schema_name) {
+ const gchar* const* schemas = g_settings_list_schemas();
+ while (*schemas) {
+ if (strcmp(schema_name, reinterpret_cast<const char*>(schemas)) == 0)
+ return true;
+ schemas++;
+ }
+ return false;
+ }
+
// LoadAndCheckVersion() must be called *before* Init()!
bool LoadAndCheckVersion(base::Environment* env);
@@ -530,8 +540,9 @@ class SettingGetterImplGSettings
DCHECK(MessageLoop::current() == glib_default_loop);
DCHECK(!client_);
DCHECK(!loop_);
- client_ = g_settings_new("org.gnome.system.proxy");
- if (!client_) {
+
+ if (!SchemaExists("org.gnome.system.proxy") ||
+ !(client_ = g_settings_new("org.gnome.system.proxy"))) {
// It's not clear whether/when this can return NULL.
LOG(ERROR) << "Unable to create a gsettings client";
return false;
@@ -677,6 +688,7 @@ class SettingGetterImplGSettings
gchar* (*g_settings_get_string)(GSettings* settings, const gchar* key);
gint (*g_settings_get_int)(GSettings* settings, const gchar* key);
gchar** (*g_settings_get_strv)(GSettings* settings, const gchar* key);
+ const gchar* const* (*g_settings_list_schemas)();
// The library handle.
void* gio_handle_;
@@ -805,7 +817,9 @@ bool SettingGetterImplGSettings::LoadAndCheckVersion(
!LoadSymbol("g_settings_get_int",
reinterpret_cast<void**>(&g_settings_get_int)) ||
!LoadSymbol("g_settings_get_strv",
- reinterpret_cast<void**>(&g_settings_get_strv))) {
+ reinterpret_cast<void**>(&g_settings_get_strv)) ||
+ !LoadSymbol("g_settings_list_schemas",
+ reinterpret_cast<void**>(&g_settings_list_schemas))) {
VLOG(1) << "Cannot load gsettings API. Will fall back to gconf.";
dlclose(gio_handle_);
gio_handle_ = NULL;
@@ -813,8 +827,9 @@ bool SettingGetterImplGSettings::LoadAndCheckVersion(
}
#endif
- GSettings* client = g_settings_new("org.gnome.system.proxy");
- if (!client) {
+ GSettings* client;
+ if (!SchemaExists("org.gnome.system.proxy") ||
+ !(client = g_settings_new("org.gnome.system.proxy"))) {
VLOG(1) << "Cannot create gsettings client. Will fall back to gconf.";
return false;
}