Bug 1442313 part 1. Make xpc::IsInAutomation a bit faster. r=bholley
☠☠ backed out by accb1b3cf593 ☠ ☠
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 01 Mar 2018 14:24:17 -0500
changeset 762208 8fc2c103027ba37bd50dec5e2fe8b79d3d68c28c
parent 762207 cf67ac6f58d0fc08af06d9bd6f0247e9288e0568
child 762209 9788a46b8874dbc1a785e9eef091a9fc2e0b4f36
push id101102
push userbmo:jkt@mozilla.com
push dateThu, 01 Mar 2018 22:11:20 +0000
reviewersbholley
bugs1442313
milestone60.0a1
Bug 1442313 part 1. Make xpc::IsInAutomation a bit faster. r=bholley MozReview-Commit-ID: HTs3RwEOmZ4
js/xpconnect/src/xpcpublic.h
--- a/js/xpconnect/src/xpcpublic.h
+++ b/js/xpconnect/src/xpcpublic.h
@@ -672,20 +672,26 @@ AreNonLocalConnectionsDisabled()
         }
     }
     return disabledForTest;
 }
 
 inline bool
 IsInAutomation()
 {
-    const char* prefName =
-      "security.turn_off_all_security_so_that_viruses_can_take_over_this_computer";
-    return mozilla::Preferences::GetBool(prefName) &&
-        AreNonLocalConnectionsDisabled();
+    static bool sAutomationPrefIsSet;
+    static bool sPrefCacheAdded = false;
+    if (!sPrefCacheAdded) {
+        mozilla::Preferences::AddBoolVarCache(
+          &sAutomationPrefIsSet,
+          "security.turn_off_all_security_so_that_viruses_can_take_over_this_computer",
+          false);
+        sPrefCacheAdded = true;
+    }
+    return sAutomationPrefIsSet && AreNonLocalConnectionsDisabled();
 }
 
 void
 CreateCooperativeContext();
 
 void
 DestroyCooperativeContext();