gfx/skia/trunk/src/lazy/SkPurgeableMemoryBlock.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 SkPurgeableMemoryBlock_DEFINED
     9 #define SkPurgeableMemoryBlock_DEFINED
    11 #include "SkTypes.h"
    13 class SkPurgeableMemoryBlock : public SkNoncopyable {
    15 public:
    16     /**
    17      *  Whether or not this platform has an implementation for purgeable memory.
    18      */
    19     static bool IsSupported();
    21     /**
    22      *  Create a new purgeable memory block of 'size' bytes. Returns NULL if not supported on this
    23      *  platform or on failure.
    24      *  @param size Number of bytes requested.
    25      *  @return A new block, or NULL on failure.
    26      */
    27     static SkPurgeableMemoryBlock* Create(size_t size);
    29 #ifdef SK_DEBUG
    30     /**
    31      *  Whether the platform supports one shot purge of all unpinned blocks. If so,
    32      *  PurgeAllUnpinnedBlocks will be used to test a purge. Otherwise, purge will be called on
    33      *  individual blocks.
    34      */
    35     static bool PlatformSupportsPurgingAllUnpinnedBlocks();
    37     /**
    38      *  Purge all unpinned blocks at once, if the platform supports it.
    39      */
    40     static bool PurgeAllUnpinnedBlocks();
    42     // If PlatformSupportsPurgingAllUnpinnedBlocks returns true, this will not be called, so it can
    43     // simply return false.
    44     bool purge();
    46     bool isPinned() const { return fPinned; }
    47 #endif
    49     ~SkPurgeableMemoryBlock();
    51     /**
    52      *  Output parameter for pin(), stating whether the data has been retained.
    53      */
    54     enum PinResult {
    55         /**
    56          *  The data has been purged, or this is the first call to pin.
    57          */
    58         kUninitialized_PinResult,
    60         /**
    61          *  The data has been retained. The memory contains the same data it held when unpin() was
    62          *  called.
    63          */
    64         kRetained_PinResult,
    65     };
    67     /**
    68      *  Pin the memory for use. Must not be called while already pinned.
    69      *  @param PinResult Whether the data was retained. Ignored on failure.
    70      *  @return Pointer to the pinned data on success. NULL on failure.
    71      */
    72     void* pin(PinResult*);
    74     /**
    75      *  Unpin the data so it can be purged if necessary.
    76      */
    77     void unpin();
    79 private:
    80     void*       fAddr;
    81     size_t      fSize;
    82     bool        fPinned;
    83 #ifdef SK_BUILD_FOR_ANDROID
    84     int         fFD;
    85 #endif
    87     // Unimplemented default constructor is private, to prevent manual creation.
    88     SkPurgeableMemoryBlock();
    90     // The correct way to create a new one is from the static Create.
    91     SkPurgeableMemoryBlock(size_t);
    92 };
    94 #endif // SkPurgeableMemoryBlock_DEFINED

mercurial