Bug 1361500 - (2) Move e10s check after profile load r?ehsan draft
authorDoug Thayer <dothayer@mozilla.com>
Thu, 06 Jul 2017 09:14:02 -0700
changeset 605038 5b8c0d593b1e04538fce16a62a647d103158b42e
parent 605037 b6586918650b4cec02277445710e5c97c7892ad6
child 636374 47d7e83df84af3dbd087bb481bf592775e5e7570
push id67278
push userbmo:dothayer@mozilla.com
push dateThu, 06 Jul 2017 22:48:19 +0000
reviewersehsan
bugs1361500
milestone56.0a1
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
toolkit/components/resistfingerprinting/nsRFPService.cpp
--- 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;
 }