From 8bb11bfbd163870aab9a1c002dd581a0157a9b2a Mon Sep 17 00:00:00 2001 From: Chris Coulson Date: Thu, 23 Feb 2012 21:16:15 -0500 Subject: [PATCH] Bug 716467 - Don't call g_settings_new each time we look up system proxy settings. r=karlt --- .../unixproxy/nsUnixSystemProxySettings.cpp | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp b/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp index f24b9b9d4a55..87e3949eace4 100644 --- a/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp +++ b/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp @@ -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 @@ private: 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 @@ NS_IMPL_ISUPPORTS1(nsUnixSystemProxySettings, nsISystemProxySettings) 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 @@ nsUnixSystemProxySettings::IsProxyMode(const char* aMode) 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 @@ nsresult 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,16 +461,8 @@ nsUnixSystemProxySettings::GetProxyFromGSettings(const nsACString& aScheme, PRInt32 aPort, nsACString& aResult) { - nsCOMPtr proxy_settings; - nsresult rv; - - rv = mGSettings->GetCollectionForSchema(NS_LITERAL_CSTRING("org.gnome.system.proxy"), - getter_AddRefs(proxy_settings)); - if (NS_FAILED(rv)) - return 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")) { @@ -469,7 +471,7 @@ nsUnixSystemProxySettings::GetProxyFromGSettings(const nsACString& aScheme, } 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); @@ -526,7 +528,7 @@ nsUnixSystemProxySettings::GetProxyForURI(nsIURI* aURI, nsACString& aResult) 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;