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 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2011 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | #include "SkImageRef_GlobalPool.h" |
michael@0 | 9 | #include "SkImageRefPool.h" |
michael@0 | 10 | #include "SkThread.h" |
michael@0 | 11 | |
michael@0 | 12 | SK_DECLARE_STATIC_MUTEX(gGlobalPoolMutex); |
michael@0 | 13 | |
michael@0 | 14 | /* |
michael@0 | 15 | * This returns the lazily-allocated global pool. It must be called |
michael@0 | 16 | * from inside the guard mutex, so we safely only ever allocate 1. |
michael@0 | 17 | */ |
michael@0 | 18 | static SkImageRefPool* GetGlobalPool() { |
michael@0 | 19 | static SkImageRefPool* gPool; |
michael@0 | 20 | if (NULL == gPool) { |
michael@0 | 21 | gPool = SkNEW(SkImageRefPool); |
michael@0 | 22 | // call sk_atexit(...) when we have that, to free the global pool |
michael@0 | 23 | } |
michael@0 | 24 | return gPool; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | SkImageRef_GlobalPool::SkImageRef_GlobalPool(const SkImageInfo& info, |
michael@0 | 28 | SkStreamRewindable* stream, |
michael@0 | 29 | int sampleSize) |
michael@0 | 30 | : SkImageRef(info, stream, sampleSize, &gGlobalPoolMutex) { |
michael@0 | 31 | SkASSERT(&gGlobalPoolMutex == this->mutex()); |
michael@0 | 32 | SkAutoMutexAcquire ac(gGlobalPoolMutex); |
michael@0 | 33 | GetGlobalPool()->addToHead(this); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | SkImageRef_GlobalPool::~SkImageRef_GlobalPool() { |
michael@0 | 37 | SkASSERT(&gGlobalPoolMutex == this->mutex()); |
michael@0 | 38 | SkAutoMutexAcquire ac(gGlobalPoolMutex); |
michael@0 | 39 | GetGlobalPool()->detach(this); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | /* By design, onUnlockPixels() already is inside the mutex-lock, |
michael@0 | 43 | * and it is the (indirect) caller of onDecode(), therefore we can assume |
michael@0 | 44 | * that we also are already inside the mutex. Hence, we can reference |
michael@0 | 45 | * the global-pool directly. |
michael@0 | 46 | */ |
michael@0 | 47 | bool SkImageRef_GlobalPool::onDecode(SkImageDecoder* codec, SkStreamRewindable* stream, |
michael@0 | 48 | SkBitmap* bitmap, SkBitmap::Config config, |
michael@0 | 49 | SkImageDecoder::Mode mode) { |
michael@0 | 50 | if (!this->INHERITED::onDecode(codec, stream, bitmap, config, mode)) { |
michael@0 | 51 | return false; |
michael@0 | 52 | } |
michael@0 | 53 | if (mode == SkImageDecoder::kDecodePixels_Mode) { |
michael@0 | 54 | // no need to grab the mutex here, it has already been acquired. |
michael@0 | 55 | GetGlobalPool()->justAddedPixels(this); |
michael@0 | 56 | } |
michael@0 | 57 | return true; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | void SkImageRef_GlobalPool::onUnlockPixels() { |
michael@0 | 61 | this->INHERITED::onUnlockPixels(); |
michael@0 | 62 | |
michael@0 | 63 | // by design, onUnlockPixels() already is inside the mutex-lock |
michael@0 | 64 | GetGlobalPool()->canLosePixels(this); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | SkImageRef_GlobalPool::SkImageRef_GlobalPool(SkReadBuffer& buffer) |
michael@0 | 68 | : INHERITED(buffer, &gGlobalPoolMutex) { |
michael@0 | 69 | SkASSERT(&gGlobalPoolMutex == this->mutex()); |
michael@0 | 70 | SkAutoMutexAcquire ac(gGlobalPoolMutex); |
michael@0 | 71 | GetGlobalPool()->addToHead(this); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 75 | // global imagerefpool wrappers |
michael@0 | 76 | |
michael@0 | 77 | size_t SkImageRef_GlobalPool::GetRAMBudget() { |
michael@0 | 78 | SkAutoMutexAcquire ac(gGlobalPoolMutex); |
michael@0 | 79 | return GetGlobalPool()->getRAMBudget(); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | void SkImageRef_GlobalPool::SetRAMBudget(size_t size) { |
michael@0 | 83 | SkAutoMutexAcquire ac(gGlobalPoolMutex); |
michael@0 | 84 | GetGlobalPool()->setRAMBudget(size); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | size_t SkImageRef_GlobalPool::GetRAMUsed() { |
michael@0 | 88 | SkAutoMutexAcquire ac(gGlobalPoolMutex); |
michael@0 | 89 | return GetGlobalPool()->getRAMUsed(); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | void SkImageRef_GlobalPool::SetRAMUsed(size_t usage) { |
michael@0 | 93 | SkAutoMutexAcquire ac(gGlobalPoolMutex); |
michael@0 | 94 | GetGlobalPool()->setRAMUsed(usage); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | void SkImageRef_GlobalPool::DumpPool() { |
michael@0 | 98 | SkAutoMutexAcquire ac(gGlobalPoolMutex); |
michael@0 | 99 | GetGlobalPool()->dump(); |
michael@0 | 100 | } |