Bug 1551826 - Use StaticPrefs for network.cookie.staleThreshold in nsCookie, r=ckerschb
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 15 May 2019 13:33:47 +0000
changeset 532754 b464eba7f66ca02f0e3f48d692da1c92ac871c9b
parent 532753 dc2abf442548216e7f00e90700102d820ae7091b
child 532755 52456bf79f9f9e7b26ecb5d9445d5f29fbd18627
push id11272
push userapavel@mozilla.com
push dateThu, 16 May 2019 15:28:22 +0000
treeherdermozilla-beta@2265bfc5920d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1551826
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1551826 - Use StaticPrefs for network.cookie.staleThreshold in nsCookie, r=ckerschb Differential Revision: https://phabricator.services.mozilla.com/D31218
modules/libpref/init/StaticPrefList.h
netwerk/cookie/nsCookie.cpp
netwerk/cookie/nsCookie.h
--- a/modules/libpref/init/StaticPrefList.h
+++ b/modules/libpref/init/StaticPrefList.h
@@ -2177,16 +2177,23 @@ VARCACHE_PREF(
 // Keep the old default of accepting all cookies
 // In Firefox Desktop this pref is set by browser.contentblocking.features.[standard, strict] see firefox.js for details.
 VARCACHE_PREF(
   "network.cookie.cookieBehavior",
   network_cookie_cookieBehavior,
   RelaxedAtomicInt32, 0
 )
 
+// Stale threshold for cookies in seconds.
+VARCACHE_PREF(
+  "network.cookie.staleThreshold",
+   network_cookie_staleThreshold,
+  uint32_t, 60
+)
+
 // Cookie lifetime policy. Possible values:
 // 0 - accept all cookies
 // 1 - deprecated. don't use it.
 // 2 - accept as session cookies
 // 3 - deprecated. don't use it.
 VARCACHE_PREF(
   "network.cookie.lifetimePolicy",
   network_cookie_lifetimePolicy,
--- a/netwerk/cookie/nsCookie.cpp
+++ b/netwerk/cookie/nsCookie.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/Encoding.h"
 #include "mozilla/dom/ToJSValue.h"
+#include "mozilla/StaticPrefs.h"
 #include "nsAutoPtr.h"
 #include "nsCookie.h"
 #include <stdlib.h>
 
 /******************************************************************************
  * nsCookie:
  * string helper impl
  ******************************************************************************/
@@ -121,17 +122,18 @@ size_t nsCookie::SizeOfIncludingThis(
   // members, since the strings are stored in-line with the nsCookie.
   return aMallocSizeOf(this);
 }
 
 bool nsCookie::IsStale() const {
   int64_t currentTimeInUsec = PR_Now();
 
   return currentTimeInUsec - LastAccessed() >
-         CookieStaleThreshold() * PR_USEC_PER_SEC;
+         mozilla::StaticPrefs::network_cookie_staleThreshold() *
+             PR_USEC_PER_SEC;
 }
 
 /******************************************************************************
  * nsCookie:
  * xpcom impl
  ******************************************************************************/
 
 // xpcom getters
--- a/netwerk/cookie/nsCookie.h
+++ b/netwerk/cookie/nsCookie.h
@@ -7,17 +7,16 @@
 #define nsCookie_h__
 
 #include "nsICookie.h"
 #include "nsICookie2.h"
 #include "nsString.h"
 
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/BasePrincipal.h"
-#include "mozilla/Preferences.h"
 
 using mozilla::OriginAttributes;
 
 /**
  * The nsCookie class is the main cookie storage medium for use within cookie
  * code. It implements nsICookie2, which extends nsICookie, a frozen interface
  * for xpcom access of cookie objects.
  */
@@ -50,27 +49,16 @@ class nsCookie final : public nsICookie2
         mLastAccessed(aLastAccessed),
         mCreationTime(aCreationTime),
         mIsSession(aIsSession),
         mIsSecure(aIsSecure),
         mIsHttpOnly(aIsHttpOnly),
         mOriginAttributes(aOriginAttributes),
         mSameSite(aSameSite) {}
 
-  static int CookieStaleThreshold() {
-    static bool initialized = false;
-    static int value = 60;
-    if (!initialized) {
-      mozilla::Preferences::AddIntVarCache(&value,
-                                           "network.cookie.staleThreshold", 60);
-      initialized = true;
-    }
-    return value;
-  }
-
  public:
   // Generate a unique and monotonically increasing creation time. See comment
   // in nsCookie.cpp.
   static int64_t GenerateUniqueCreationTime(int64_t aCreationTime);
 
   // public helper to create an nsCookie object. use |operator delete|
   // to destroy an object created by this method.
   static nsCookie* Create(const nsACString& aName, const nsACString& aValue,