xpcom/threads/nsMemoryPressure.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include "nsMemoryPressure.h"
     8 #include "mozilla/Assertions.h"
     9 #include "mozilla/Atomics.h"
    11 #include "nsThreadUtils.h"
    13 using namespace mozilla;
    15 static Atomic<int32_t, Relaxed> sMemoryPressurePending;
    16 static_assert(MemPressure_None == 0,
    17               "Bad static initialization with the default constructor.");
    19 MemoryPressureState
    20 NS_GetPendingMemoryPressure()
    21 {
    22   int32_t value = sMemoryPressurePending.exchange(MemPressure_None);
    23   return MemoryPressureState(value);
    24 }
    26 void
    27 NS_DispatchEventualMemoryPressure(MemoryPressureState state)
    28 {
    29   /*
    30    * A new memory pressure event erases an ongoing memory pressure, but an
    31    * existing "new" memory pressure event takes precedence over a new "ongoing"
    32    * memory pressure event.
    33    */
    34   switch (state) {
    35     case MemPressure_None:
    36       sMemoryPressurePending = MemPressure_None;
    37       break;
    38     case MemPressure_New:
    39       sMemoryPressurePending = MemPressure_New;
    40       break;
    41     case MemPressure_Ongoing:
    42       sMemoryPressurePending.compareExchange(MemPressure_None, MemPressure_Ongoing);
    43       break;
    44   }
    45 }
    47 nsresult
    48 NS_DispatchMemoryPressure(MemoryPressureState state)
    49 {
    50   NS_DispatchEventualMemoryPressure(state);
    51   nsCOMPtr<nsIRunnable> event = new nsRunnable;
    52   return NS_DispatchToMainThread(event);
    53 }

mercurial