gfx/skia/trunk/src/lazy/SkDiscardableMemoryPool.h

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 /*
     2  * Copyright 2013 Google Inc.
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     8 #ifndef SkDiscardableMemoryPool_DEFINED
     9 #define SkDiscardableMemoryPool_DEFINED
    11 #include "SkDiscardableMemory.h"
    12 #include "SkTInternalLList.h"
    13 #include "SkThread.h"
    15 class SkPoolDiscardableMemory;
    17 #ifdef SK_DEBUG
    18     #define LAZY_CACHE_STATS 1
    19 #elif !defined(LAZY_CACHE_STATS)
    20     #define LAZY_CACHE_STATS 0
    21 #endif
    23 /**
    24  *  This non-global pool can be used for unit tests to verify that the
    25  *  pool works.
    26  */
    27 class SkDiscardableMemoryPool : public SkDiscardableMemory::Factory {
    28 public:
    29     /**
    30      *  Without mutex, will be not be thread safe.
    31      */
    32     SkDiscardableMemoryPool(size_t budget, SkBaseMutex* mutex = NULL);
    33     virtual ~SkDiscardableMemoryPool();
    35     virtual SkDiscardableMemory* create(size_t bytes) SK_OVERRIDE;
    37     size_t getRAMUsed();
    38     void setRAMBudget(size_t budget);
    40     /** purges all unlocked DMs */
    41     void dumpPool();
    43     #if LAZY_CACHE_STATS
    44     int          fCacheHits;
    45     int          fCacheMisses;
    46     #endif  // LAZY_CACHE_STATS
    48 private:
    49     SkBaseMutex* fMutex;
    50     size_t       fBudget;
    51     size_t       fUsed;
    52     SkTInternalLList<SkPoolDiscardableMemory> fList;
    54     /** Function called to free memory if needed */
    55     void dumpDownTo(size_t budget);
    56     /** called by SkDiscardableMemoryPool upon destruction */
    57     void free(SkPoolDiscardableMemory* dm);
    58     /** called by SkDiscardableMemoryPool::lock() */
    59     bool lock(SkPoolDiscardableMemory* dm);
    60     /** called by SkDiscardableMemoryPool::unlock() */
    61     void unlock(SkPoolDiscardableMemory* dm);
    63     friend class SkPoolDiscardableMemory;
    65     typedef SkDiscardableMemory::Factory INHERITED;
    66 };
    68 /**
    69  *  Returns (and creates if needed) a threadsafe global
    70  *  SkDiscardableMemoryPool.
    71  */
    72 SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool();
    74 #if !defined(SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE)
    75 #define SK_DEFAULT_GLOBAL_DISCARDABLE_MEMORY_POOL_SIZE (128 * 1024 * 1024)
    76 #endif
    78 #endif  // SkDiscardableMemoryPool_DEFINED

mercurial