Bug 1361500 - (2) Move e10s check after profile load r?ehsan
Since user-provided values for the e10s prefs won't be loaded
until the profile's prefs.js file is loaded, we need to wait for
this to occur. The simplest way to do this while keeping the
logic neatly inside nsRFPService seemed to be to add an observer,
but another option would be to just directly call _tzset at the
right time during start-up, or add a static method in nsRFPService
doing this that we could call. This would avoid the overhead of an
observer, but since I don't know how significant that overhead
is I just went with the observer for now.
MozReview-Commit-ID: 6yhvwEoADDy
--- a/toolkit/components/resistfingerprinting/nsRFPService.cpp
+++ b/toolkit/components/resistfingerprinting/nsRFPService.cpp
@@ -24,16 +24,17 @@
#include "prenv.h"
#include "js/Date.h"
using namespace mozilla;
#define RESIST_FINGERPRINTING_PREF "privacy.resistFingerprinting"
+#define PROFILE_INITIALIZED_TOPIC "profile-initial-state"
NS_IMPL_ISUPPORTS(nsRFPService, nsIObserver)
static StaticRefPtr<nsRFPService> sRFPService;
static bool sInitialized = false;
Atomic<bool, ReleaseAcquire> nsRFPService::sPrivacyResistFingerprinting;
static uint32_t kResolutionUSec = 100000;
@@ -103,44 +104,37 @@ nsRFPService::Init()
nsresult rv;
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
NS_ENSURE_TRUE(obs, NS_ERROR_NOT_AVAILABLE);
rv = obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
NS_ENSURE_SUCCESS(rv, rv);
+#if defined(XP_WIN)
+ rv = obs->AddObserver(this, PROFILE_INITIALIZED_TOPIC, false);
+ NS_ENSURE_SUCCESS(rv, rv);
+#endif
+
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
NS_ENSURE_TRUE(prefs, NS_ERROR_NOT_AVAILABLE);
rv = prefs->AddObserver(RESIST_FINGERPRINTING_PREF, this, false);
NS_ENSURE_SUCCESS(rv, rv);
// We backup the original TZ value here.
const char* tzValue = PR_GetEnv("TZ");
if (tzValue) {
mInitialTZValue = nsCString(tzValue);
}
// Call UpdatePref() here to cache the value of 'privacy.resistFingerprinting'
// and set the timezone.
UpdatePref();
-#if defined(XP_WIN)
- // If we're e10s, then we don't need to run this, since the child process will
- // simply inherit the environment variable from the parent process, in which
- // case it's unnecessary to call _tzset().
- if (XRE_IsParentProcess() && !XRE_IsE10sParentProcess()) {
- // Windows does not follow POSIX. Updates to the TZ environment variable
- // are not reflected immediately on that platform as they are on UNIX
- // systems without this call.
- _tzset();
- }
-#endif
-
return rv;
}
void
nsRFPService::UpdatePref()
{
MOZ_ASSERT(NS_IsMainThread());
sPrivacyResistFingerprinting = Preferences::GetBool(RESIST_FINGERPRINTING_PREF);
@@ -208,11 +202,30 @@ nsRFPService::Observe(nsISupports* aObje
}
#endif
}
}
if (!strcmp(NS_XPCOM_SHUTDOWN_OBSERVER_ID, aTopic)) {
StartShutdown();
}
+#if defined(XP_WIN)
+ else if (!strcmp(PROFILE_INITIALIZED_TOPIC, aTopic)) {
+ // If we're e10s, then we don't need to run this, since the child process will
+ // simply inherit the environment variable from the parent process, in which
+ // case it's unnecessary to call _tzset().
+ if (XRE_IsParentProcess() && !XRE_IsE10sParentProcess()) {
+ // Windows does not follow POSIX. Updates to the TZ environment variable
+ // are not reflected immediately on that platform as they are on UNIX
+ // systems without this call.
+ _tzset();
+ }
+
+ nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
+ NS_ENSURE_TRUE(obs, NS_ERROR_NOT_AVAILABLE);
+
+ nsresult rv = obs->RemoveObserver(this, PROFILE_INITIALIZED_TOPIC);
+ NS_ENSURE_SUCCESS(rv, rv);
+ }
+#endif
return NS_OK;
}