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
Index: mozilla/mozilla/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp
7
===================================================================
8
--- mozilla.orig/mozilla/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp 2012-02-22 14:20:22.000000000 +0000
9
+++ mozilla/mozilla/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp 2012-02-23 16:57:18.783367775 +0000
11
#include "nsNetUtil.h"
12
#include "nsISupportsPrimitives.h"
13
#include "nsIGSettingsService.h"
14
+#include "nsInterfaceHashtable.h"
16
class nsUnixSystemProxySettings : public nsISystemProxySettings {
20
nsCOMPtr<nsIGConfService> mGConf;
21
nsCOMPtr<nsIGSettingsService> mGSettings;
22
+ nsCOMPtr<nsIGSettingsCollection> mProxySettings;
23
+ nsInterfaceHashtable<nsCStringHashKey, nsIGSettingsCollection> mSchemeProxySettings;
24
bool IsProxyMode(const char* aMode);
25
nsresult SetProxyResultFromGConf(const char* aKeyBase, const char* aType, nsACString& aResult);
26
nsresult GetProxyFromGConf(const nsACString& aScheme, const nsACString& aHost, PRInt32 aPort, nsACString& aResult);
29
nsUnixSystemProxySettings::Init()
31
+ mSchemeProxySettings.Init(5);
32
mGConf = do_GetService(NS_GCONFSERVICE_CONTRACTID);
33
mGSettings = do_GetService(NS_GSETTINGSSERVICE_CONTRACTID);
35
+ mGSettings->GetCollectionForSchema(NS_LITERAL_CSTRING("org.gnome.system.proxy"),
36
+ getter_AddRefs(mProxySettings));
44
nsUnixSystemProxySettings::GetPACURI(nsACString& aResult)
47
- nsCOMPtr<nsIGSettingsCollection> proxy_settings;
48
- mGSettings->GetCollectionForSchema(NS_LITERAL_CSTRING("org.gnome.system.proxy"),
49
- getter_AddRefs(proxy_settings));
50
- if (proxy_settings) {
51
- nsCString proxyMode;
52
- // Check if mode is auto
53
- nsresult rv = proxy_settings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode);
54
- if (rv == NS_OK && proxyMode.Equals("auto")) {
55
- return proxy_settings->GetString(NS_LITERAL_CSTRING("autoconfig-url"), aResult);
57
- /* The org.gnome.system.proxy schema has been found, but auto mode is not set.
58
- * Don't try the GConf and return empty string. */
61
+ if (mProxySettings) {
62
+ nsCString proxyMode;
63
+ // Check if mode is auto
64
+ nsresult rv = mProxySettings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode);
65
+ if (rv == NS_OK && proxyMode.Equals("auto")) {
66
+ return mProxySettings->GetString(NS_LITERAL_CSTRING("autoconfig-url"), aResult);
68
+ /* The org.gnome.system.proxy schema has been found, but auto mode is not set.
69
+ * Don't try the GConf and return empty string. */
74
if (mGConf && IsProxyMode("auto")) {
76
nsUnixSystemProxySettings::SetProxyResultFromGSettings(const char* aKeyBase, const char* aType,
79
- nsCOMPtr<nsIGSettingsCollection> proxy_settings;
80
- nsresult rv = mGSettings->GetCollectionForSchema(nsDependentCString(aKeyBase),
81
- getter_AddRefs(proxy_settings));
82
- NS_ENSURE_SUCCESS(rv, rv);
83
+ nsDependentCString key(aKeyBase);
85
+ nsCOMPtr<nsIGSettingsCollection> proxy_settings = mSchemeProxySettings.Get(key);
87
+ if (!proxy_settings) {
88
+ rv = mGSettings->GetCollectionForSchema(key, getter_AddRefs(proxy_settings));
89
+ NS_ENSURE_SUCCESS(rv, rv);
91
+ mSchemeProxySettings.Put(key, proxy_settings);
95
rv = proxy_settings->GetString(NS_LITERAL_CSTRING("host"), host);
100
- nsCOMPtr<nsIGSettingsCollection> proxy_settings;
103
- rv = mGSettings->GetCollectionForSchema(NS_LITERAL_CSTRING("org.gnome.system.proxy"),
104
- getter_AddRefs(proxy_settings));
105
- NS_ENSURE_SUCCESS(rv, rv);
108
- rv = proxy_settings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode);
109
+ nsresult rv = mProxySettings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode);
110
NS_ENSURE_SUCCESS(rv, rv);
112
if (!proxyMode.Equals("manual")) {
116
nsCOMPtr<nsIArray> ignoreList;
117
- if (NS_SUCCEEDED(proxy_settings->GetStringList(NS_LITERAL_CSTRING("ignore-hosts"),
118
+ if (NS_SUCCEEDED(mProxySettings->GetStringList(NS_LITERAL_CSTRING("ignore-hosts"),
119
getter_AddRefs(ignoreList))) && ignoreList) {
121
ignoreList->GetLength(&len);
123
rv = aURI->GetPort(&port);
124
NS_ENSURE_SUCCESS(rv, rv);
127
+ if (mProxySettings) {
128
rv = GetProxyFromGSettings(scheme, host, port, aResult);