Sat, 03 Jan 2015 20:18:00 +0100
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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef MOZILLA_ATOMICREFCOUNTEDWITHFINALIZE_H_ |
michael@0 | 7 | #define MOZILLA_ATOMICREFCOUNTEDWITHFINALIZE_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/RefPtr.h" |
michael@0 | 10 | #include "mozilla/NullPtr.h" |
michael@0 | 11 | |
michael@0 | 12 | namespace mozilla { |
michael@0 | 13 | |
michael@0 | 14 | template<typename T> |
michael@0 | 15 | class AtomicRefCountedWithFinalize |
michael@0 | 16 | { |
michael@0 | 17 | protected: |
michael@0 | 18 | AtomicRefCountedWithFinalize() |
michael@0 | 19 | : mRecycleCallback(nullptr) |
michael@0 | 20 | , mRefCount(0) |
michael@0 | 21 | {} |
michael@0 | 22 | |
michael@0 | 23 | ~AtomicRefCountedWithFinalize() {} |
michael@0 | 24 | |
michael@0 | 25 | public: |
michael@0 | 26 | void AddRef() { |
michael@0 | 27 | MOZ_ASSERT(mRefCount >= 0); |
michael@0 | 28 | ++mRefCount; |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | void Release() { |
michael@0 | 32 | MOZ_ASSERT(mRefCount > 0); |
michael@0 | 33 | // Read mRecycleCallback early so that it does not get set to |
michael@0 | 34 | // deleted memory, if the object is goes away. |
michael@0 | 35 | RecycleCallback recycleCallback = mRecycleCallback; |
michael@0 | 36 | int currCount = --mRefCount; |
michael@0 | 37 | if (0 == currCount) { |
michael@0 | 38 | // Recycle listeners must call ClearRecycleCallback |
michael@0 | 39 | // before releasing their strong reference. |
michael@0 | 40 | MOZ_ASSERT(mRecycleCallback == nullptr); |
michael@0 | 41 | #ifdef DEBUG |
michael@0 | 42 | mRefCount = detail::DEAD; |
michael@0 | 43 | #endif |
michael@0 | 44 | T* derived = static_cast<T*>(this); |
michael@0 | 45 | derived->Finalize(); |
michael@0 | 46 | delete derived; |
michael@0 | 47 | } else if (1 == currCount && recycleCallback) { |
michael@0 | 48 | T* derived = static_cast<T*>(this); |
michael@0 | 49 | recycleCallback(derived, mClosure); |
michael@0 | 50 | } |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | typedef void (*RecycleCallback)(T* aObject, void* aClosure); |
michael@0 | 54 | /** |
michael@0 | 55 | * Set a callback responsible for recycling this object |
michael@0 | 56 | * before it is finalized. |
michael@0 | 57 | */ |
michael@0 | 58 | void SetRecycleCallback(RecycleCallback aCallback, void* aClosure) |
michael@0 | 59 | { |
michael@0 | 60 | mRecycleCallback = aCallback; |
michael@0 | 61 | mClosure = aClosure; |
michael@0 | 62 | } |
michael@0 | 63 | void ClearRecycleCallback() { SetRecycleCallback(nullptr, nullptr); } |
michael@0 | 64 | |
michael@0 | 65 | private: |
michael@0 | 66 | RecycleCallback mRecycleCallback; |
michael@0 | 67 | void *mClosure; |
michael@0 | 68 | Atomic<int> mRefCount; |
michael@0 | 69 | }; |
michael@0 | 70 | |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | #endif |