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.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef SkPurgeableMemoryBlock_DEFINED
michael@0 9 #define SkPurgeableMemoryBlock_DEFINED
michael@0 10
michael@0 11 #include "SkTypes.h"
michael@0 12
michael@0 13 class SkPurgeableMemoryBlock : public SkNoncopyable {
michael@0 14
michael@0 15 public:
michael@0 16 /**
michael@0 17 * Whether or not this platform has an implementation for purgeable memory.
michael@0 18 */
michael@0 19 static bool IsSupported();
michael@0 20
michael@0 21 /**
michael@0 22 * Create a new purgeable memory block of 'size' bytes. Returns NULL if not supported on this
michael@0 23 * platform or on failure.
michael@0 24 * @param size Number of bytes requested.
michael@0 25 * @return A new block, or NULL on failure.
michael@0 26 */
michael@0 27 static SkPurgeableMemoryBlock* Create(size_t size);
michael@0 28
michael@0 29 #ifdef SK_DEBUG
michael@0 30 /**
michael@0 31 * Whether the platform supports one shot purge of all unpinned blocks. If so,
michael@0 32 * PurgeAllUnpinnedBlocks will be used to test a purge. Otherwise, purge will be called on
michael@0 33 * individual blocks.
michael@0 34 */
michael@0 35 static bool PlatformSupportsPurgingAllUnpinnedBlocks();
michael@0 36
michael@0 37 /**
michael@0 38 * Purge all unpinned blocks at once, if the platform supports it.
michael@0 39 */
michael@0 40 static bool PurgeAllUnpinnedBlocks();
michael@0 41
michael@0 42 // If PlatformSupportsPurgingAllUnpinnedBlocks returns true, this will not be called, so it can
michael@0 43 // simply return false.
michael@0 44 bool purge();
michael@0 45
michael@0 46 bool isPinned() const { return fPinned; }
michael@0 47 #endif
michael@0 48
michael@0 49 ~SkPurgeableMemoryBlock();
michael@0 50
michael@0 51 /**
michael@0 52 * Output parameter for pin(), stating whether the data has been retained.
michael@0 53 */
michael@0 54 enum PinResult {
michael@0 55 /**
michael@0 56 * The data has been purged, or this is the first call to pin.
michael@0 57 */
michael@0 58 kUninitialized_PinResult,
michael@0 59
michael@0 60 /**
michael@0 61 * The data has been retained. The memory contains the same data it held when unpin() was
michael@0 62 * called.
michael@0 63 */
michael@0 64 kRetained_PinResult,
michael@0 65 };
michael@0 66
michael@0 67 /**
michael@0 68 * Pin the memory for use. Must not be called while already pinned.
michael@0 69 * @param PinResult Whether the data was retained. Ignored on failure.
michael@0 70 * @return Pointer to the pinned data on success. NULL on failure.
michael@0 71 */
michael@0 72 void* pin(PinResult*);
michael@0 73
michael@0 74 /**
michael@0 75 * Unpin the data so it can be purged if necessary.
michael@0 76 */
michael@0 77 void unpin();
michael@0 78
michael@0 79 private:
michael@0 80 void* fAddr;
michael@0 81 size_t fSize;
michael@0 82 bool fPinned;
michael@0 83 #ifdef SK_BUILD_FOR_ANDROID
michael@0 84 int fFD;
michael@0 85 #endif
michael@0 86
michael@0 87 // Unimplemented default constructor is private, to prevent manual creation.
michael@0 88 SkPurgeableMemoryBlock();
michael@0 89
michael@0 90 // The correct way to create a new one is from the static Create.
michael@0 91 SkPurgeableMemoryBlock(size_t);
michael@0 92 };
michael@0 93
michael@0 94 #endif // SkPurgeableMemoryBlock_DEFINED

mercurial