Bug 716467 - Don't call g_settings_new each time we look up system proxy settings. r=karlt

This commit is contained in:
Chris Coulson 2012-02-23 21:16:15 -05:00
Родитель 4822651d7f
Коммит 8bb11bfbd1
1 изменённых файлов: 32 добавлений и 30 удалений

Просмотреть файл

@ -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<nsIGConfService> mGConf;
nsCOMPtr<nsIGSettingsService> mGSettings;
nsCOMPtr<nsIGSettingsCollection> mProxySettings;
nsInterfaceHashtable<nsCStringHashKey, nsIGSettingsCollection> 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<nsIGSettingsCollection> 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<nsIGSettingsCollection> proxy_settings;
nsresult rv = mGSettings->GetCollectionForSchema(nsDependentCString(aKeyBase),
getter_AddRefs(proxy_settings));
NS_ENSURE_SUCCESS(rv, rv);
nsDependentCString key(aKeyBase);
nsCOMPtr<nsIGSettingsCollection> 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<nsIGSettingsCollection> 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<nsIArray> 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;