# HG changeset patch # Parent 9bde0d25d76e4ef301668a8016f6edcba1662826 # User Chris Coulson Bug 716467 - Don't call g_settings_new each time we look up system proxy settings Index: mozilla/mozilla/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp =================================================================== --- mozilla.orig/mozilla/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp 2012-02-22 14:20:22.000000000 +0000 +++ mozilla/mozilla/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp 2012-02-23 16:57:18.783367775 +0000 @@ -50,6 +50,7 @@ #include "nsNetUtil.h" #include "nsISupportsPrimitives.h" #include "nsIGSettingsService.h" +#include "nsInterfaceHashtable.h" class nsUnixSystemProxySettings : public nsISystemProxySettings { public: @@ -64,6 +65,8 @@ nsCOMPtr mGConf; nsCOMPtr mGSettings; + nsCOMPtr mProxySettings; + nsInterfaceHashtable mSchemeProxySettings; bool IsProxyMode(const char* aMode); nsresult SetProxyResultFromGConf(const char* aKeyBase, const char* aType, nsACString& aResult); nsresult GetProxyFromGConf(const nsACString& aScheme, const nsACString& aHost, PRInt32 aPort, nsACString& aResult); @@ -76,8 +79,14 @@ nsresult nsUnixSystemProxySettings::Init() { + mSchemeProxySettings.Init(5); mGConf = do_GetService(NS_GCONFSERVICE_CONTRACTID); mGSettings = do_GetService(NS_GSETTINGSSERVICE_CONTRACTID); + if (mGSettings) { + mGSettings->GetCollectionForSchema(NS_LITERAL_CSTRING("org.gnome.system.proxy"), + getter_AddRefs(mProxySettings)); + } + return NS_OK; } @@ -92,22 +101,17 @@ nsresult nsUnixSystemProxySettings::GetPACURI(nsACString& aResult) { - if (mGSettings) { - nsCOMPtr proxy_settings; - mGSettings->GetCollectionForSchema(NS_LITERAL_CSTRING("org.gnome.system.proxy"), - getter_AddRefs(proxy_settings)); - if (proxy_settings) { - nsCString proxyMode; - // Check if mode is auto - nsresult rv = proxy_settings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode); - if (rv == NS_OK && proxyMode.Equals("auto")) { - return proxy_settings->GetString(NS_LITERAL_CSTRING("autoconfig-url"), aResult); - } - /* The org.gnome.system.proxy schema has been found, but auto mode is not set. - * Don't try the GConf and return empty string. */ - aResult.Truncate(); - return NS_OK; + if (mProxySettings) { + nsCString proxyMode; + // Check if mode is auto + nsresult rv = mProxySettings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode); + if (rv == NS_OK && proxyMode.Equals("auto")) { + return mProxySettings->GetString(NS_LITERAL_CSTRING("autoconfig-url"), aResult); } + /* The org.gnome.system.proxy schema has been found, but auto mode is not set. + * Don't try the GConf and return empty string. */ + aResult.Truncate(); + return NS_OK; } if (mGConf && IsProxyMode("auto")) { @@ -266,10 +270,16 @@ nsUnixSystemProxySettings::SetProxyResultFromGSettings(const char* aKeyBase, const char* aType, nsACString& aResult) { - nsCOMPtr proxy_settings; - nsresult rv = mGSettings->GetCollectionForSchema(nsDependentCString(aKeyBase), - getter_AddRefs(proxy_settings)); - NS_ENSURE_SUCCESS(rv, rv); + nsDependentCString key(aKeyBase); + + nsCOMPtr proxy_settings = mSchemeProxySettings.Get(key); + nsresult rv; + if (!proxy_settings) { + rv = mGSettings->GetCollectionForSchema(key, getter_AddRefs(proxy_settings)); + NS_ENSURE_SUCCESS(rv, rv); + + mSchemeProxySettings.Put(key, proxy_settings); + } nsCAutoString host; rv = proxy_settings->GetString(NS_LITERAL_CSTRING("host"), host); @@ -451,15 +461,8 @@ PRInt32 aPort, nsACString& aResult) { - nsCOMPtr proxy_settings; - nsresult rv; - - rv = mGSettings->GetCollectionForSchema(NS_LITERAL_CSTRING("org.gnome.system.proxy"), - getter_AddRefs(proxy_settings)); - NS_ENSURE_SUCCESS(rv, rv); - nsCString proxyMode; - rv = proxy_settings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode); + nsresult rv = mProxySettings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode); NS_ENSURE_SUCCESS(rv, rv); if (!proxyMode.Equals("manual")) { @@ -468,7 +471,7 @@ } nsCOMPtr ignoreList; - if (NS_SUCCEEDED(proxy_settings->GetStringList(NS_LITERAL_CSTRING("ignore-hosts"), + if (NS_SUCCEEDED(mProxySettings->GetStringList(NS_LITERAL_CSTRING("ignore-hosts"), getter_AddRefs(ignoreList))) && ignoreList) { PRUint32 len = 0; ignoreList->GetLength(&len); @@ -525,7 +528,7 @@ rv = aURI->GetPort(&port); NS_ENSURE_SUCCESS(rv, rv); - if (mGSettings) { + if (mProxySettings) { rv = GetProxyFromGSettings(scheme, host, port, aResult); if (rv == NS_OK) return rv;