2
# Parent 9bde0d25d76e4ef301668a8016f6edcba1662826
3
# User Chris Coulson <chris.coulson@canonical.com>
4
Bug 716467 - Don't call g_settings_new each time we look up system proxy settings
6
diff --git a/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp b/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp
7
--- a/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp
8
+++ b/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp
10
#include "nsReadableUtils.h"
11
#include "nsArrayUtils.h"
14
#include "nsPrintfCString.h"
15
#include "nsNetUtil.h"
16
#include "nsISupportsPrimitives.h"
17
#include "nsIGSettingsService.h"
18
+#include "nsInterfaceHashtable.h"
20
class nsUnixSystemProxySettings : public nsISystemProxySettings {
23
NS_DECL_NSISYSTEMPROXYSETTINGS
25
nsUnixSystemProxySettings() {}
29
~nsUnixSystemProxySettings() {}
31
nsCOMPtr<nsIGConfService> mGConf;
32
nsCOMPtr<nsIGSettingsService> mGSettings;
33
+ nsCOMPtr<nsIGSettingsCollection> mProxySettings;
34
+ nsInterfaceHashtable<nsCStringHashKey, nsIGSettingsCollection> mSchemeProxySettings;
35
bool IsProxyMode(const char* aMode);
36
nsresult SetProxyResultFromGConf(const char* aKeyBase, const char* aType, nsACString& aResult);
37
nsresult GetProxyFromGConf(const nsACString& aScheme, const nsACString& aHost, PRInt32 aPort, nsACString& aResult);
38
nsresult GetProxyFromGSettings(const nsACString& aScheme, const nsACString& aHost, PRInt32 aPort, nsACString& aResult);
39
nsresult SetProxyResultFromGSettings(const char* aKeyBase, const char* aType, nsACString& aResult);
42
NS_IMPL_ISUPPORTS1(nsUnixSystemProxySettings, nsISystemProxySettings)
45
nsUnixSystemProxySettings::Init()
47
+ mSchemeProxySettings.Init(5);
48
mGConf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
49
mGSettings = do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
51
+ mGSettings->GetCollectionForSchema(NS_LITERAL_CSTRING("org.gnome.system.proxy"),
52
+ getter_AddRefs(mProxySettings));
59
nsUnixSystemProxySettings::IsProxyMode(const char* aMode)
62
return NS_SUCCEEDED(mGConf->GetString(NS_LITERAL_CSTRING("/system/proxy/mode"), mode)) &&
63
mode.EqualsASCII(aMode);
67
nsUnixSystemProxySettings::GetPACURI(nsACString& aResult)
70
- nsCOMPtr<nsIGSettingsCollection> proxy_settings;
71
- mGSettings->GetCollectionForSchema(NS_LITERAL_CSTRING("org.gnome.system.proxy"),
72
- getter_AddRefs(proxy_settings));
73
- if (proxy_settings) {
74
- nsCString proxyMode;
75
- // Check if mode is auto
76
- nsresult rv = proxy_settings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode);
77
- if (rv == NS_OK && proxyMode.Equals("auto")) {
78
- return proxy_settings->GetString(NS_LITERAL_CSTRING("autoconfig-url"), aResult);
80
- /* The org.gnome.system.proxy schema has been found, but auto mode is not set.
81
- * Don't try the GConf and return empty string. */
84
+ if (mProxySettings) {
85
+ nsCString proxyMode;
86
+ // Check if mode is auto
87
+ nsresult rv = mProxySettings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode);
88
+ if (rv == NS_OK && proxyMode.Equals("auto")) {
89
+ return mProxySettings->GetString(NS_LITERAL_CSTRING("autoconfig-url"), aResult);
91
+ /* The org.gnome.system.proxy schema has been found, but auto mode is not set.
92
+ * Don't try the GConf and return empty string. */
97
if (mGConf && IsProxyMode("auto")) {
98
return mGConf->GetString(NS_LITERAL_CSTRING("/system/proxy/autoconfig_url"),
101
// Return an empty string when auto mode is not set.
103
@@ -261,20 +265,26 @@ nsUnixSystemProxySettings::SetProxyResul
104
SetProxyResult(aType, host, port, aResult);
109
nsUnixSystemProxySettings::SetProxyResultFromGSettings(const char* aKeyBase, const char* aType,
112
- nsCOMPtr<nsIGSettingsCollection> proxy_settings;
113
- nsresult rv = mGSettings->GetCollectionForSchema(nsDependentCString(aKeyBase),
114
- getter_AddRefs(proxy_settings));
115
- NS_ENSURE_SUCCESS(rv, rv);
116
+ nsDependentCString key(aKeyBase);
118
+ nsCOMPtr<nsIGSettingsCollection> proxy_settings = mSchemeProxySettings.Get(key);
120
+ if (!proxy_settings) {
121
+ rv = mGSettings->GetCollectionForSchema(key, getter_AddRefs(proxy_settings));
122
+ NS_ENSURE_SUCCESS(rv, rv);
124
+ mSchemeProxySettings.Put(key, proxy_settings);
128
rv = proxy_settings->GetString(NS_LITERAL_CSTRING("host"), host);
129
NS_ENSURE_SUCCESS(rv, rv);
131
return NS_ERROR_FAILURE;
134
@@ -446,35 +456,27 @@ nsUnixSystemProxySettings::GetProxyFromG
138
nsUnixSystemProxySettings::GetProxyFromGSettings(const nsACString& aScheme,
139
const nsACString& aHost,
143
- nsCOMPtr<nsIGSettingsCollection> proxy_settings;
146
- rv = mGSettings->GetCollectionForSchema(NS_LITERAL_CSTRING("org.gnome.system.proxy"),
147
- getter_AddRefs(proxy_settings));
152
- rv = proxy_settings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode);
153
+ nsresult rv = mProxySettings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode);
154
NS_ENSURE_SUCCESS(rv, rv);
156
if (!proxyMode.Equals("manual")) {
157
aResult.AppendLiteral("DIRECT");
161
nsCOMPtr<nsIArray> ignoreList;
162
- if (NS_SUCCEEDED(proxy_settings->GetStringList(NS_LITERAL_CSTRING("ignore-hosts"),
163
+ if (NS_SUCCEEDED(mProxySettings->GetStringList(NS_LITERAL_CSTRING("ignore-hosts"),
164
getter_AddRefs(ignoreList))) && ignoreList) {
166
ignoreList->GetLength(&len);
167
for (PRUint32 i = 0; i < len; ++i) {
168
nsCOMPtr<nsISupportsCString> str = do_QueryElementAt(ignoreList, i);
171
if (NS_SUCCEEDED(str->GetData(s)) && !s.IsEmpty()) {
172
@@ -521,17 +523,17 @@ nsUnixSystemProxySettings::GetProxyForUR
174
rv = aURI->GetHost(host);
175
NS_ENSURE_SUCCESS(rv, rv);
178
rv = aURI->GetPort(&port);
179
NS_ENSURE_SUCCESS(rv, rv);
182
+ if (mProxySettings) {
183
rv = GetProxyFromGSettings(scheme, host, port, aResult);
188
return GetProxyFromGConf(scheme, host, port, aResult);
190
return GetProxyFromEnvironment(scheme, host, port, aResult);