gfx/skia/trunk/src/core/SkPtrRecorder.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 /*
michael@0 3 * Copyright 2008 The Android Open Source Project
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
michael@0 9
michael@0 10 #ifndef SkPtrSet_DEFINED
michael@0 11 #define SkPtrSet_DEFINED
michael@0 12
michael@0 13 #include "SkRefCnt.h"
michael@0 14 #include "SkFlattenable.h"
michael@0 15 #include "SkTDArray.h"
michael@0 16
michael@0 17 /**
michael@0 18 * Maintains a set of ptrs, assigning each a unique ID [1...N]. Duplicate ptrs
michael@0 19 * return the same ID (since its a set). Subclasses can override inPtr()
michael@0 20 * and decPtr(). incPtr() is called each time a unique ptr is added ot the
michael@0 21 * set. decPtr() is called on each ptr when the set is destroyed or reset.
michael@0 22 */
michael@0 23 class SkPtrSet : public SkRefCnt {
michael@0 24 public:
michael@0 25 SK_DECLARE_INST_COUNT(SkPtrSet)
michael@0 26
michael@0 27 /**
michael@0 28 * Search for the specified ptr in the set. If it is found, return its
michael@0 29 * 32bit ID [1..N], or if not found, return 0. Always returns 0 for NULL.
michael@0 30 */
michael@0 31 uint32_t find(void*) const;
michael@0 32
michael@0 33 /**
michael@0 34 * Add the specified ptr to the set, returning a unique 32bit ID for it
michael@0 35 * [1...N]. Duplicate ptrs will return the same ID.
michael@0 36 *
michael@0 37 * If the ptr is NULL, it is not added, and 0 is returned.
michael@0 38 */
michael@0 39 uint32_t add(void*);
michael@0 40
michael@0 41 /**
michael@0 42 * Return the number of (non-null) ptrs in the set.
michael@0 43 */
michael@0 44 int count() const { return fList.count(); }
michael@0 45
michael@0 46 /**
michael@0 47 * Copy the ptrs in the set into the specified array (allocated by the
michael@0 48 * caller). The ptrs are assgined to the array based on their corresponding
michael@0 49 * ID. e.g. array[ptr.ID - 1] = ptr.
michael@0 50 *
michael@0 51 * incPtr() and decPtr() are not called during this operation.
michael@0 52 */
michael@0 53 void copyToArray(void* array[]) const;
michael@0 54
michael@0 55 /**
michael@0 56 * Call decPtr() on each ptr in the set, and the reset the size of the set
michael@0 57 * to 0.
michael@0 58 */
michael@0 59 void reset();
michael@0 60
michael@0 61 protected:
michael@0 62 virtual void incPtr(void*) {}
michael@0 63 virtual void decPtr(void*) {}
michael@0 64
michael@0 65 private:
michael@0 66 struct Pair {
michael@0 67 void* fPtr; // never NULL
michael@0 68 uint32_t fIndex; // 1...N
michael@0 69 };
michael@0 70
michael@0 71 // we store the ptrs in sorted-order (using Cmp) so that we can efficiently
michael@0 72 // detect duplicates when add() is called. Hence we need to store the
michael@0 73 // ptr and its ID/fIndex explicitly, since the ptr's position in the array
michael@0 74 // is not related to its "index".
michael@0 75 SkTDArray<Pair> fList;
michael@0 76
michael@0 77 static bool Less(const Pair& a, const Pair& b);
michael@0 78
michael@0 79 typedef SkRefCnt INHERITED;
michael@0 80 };
michael@0 81
michael@0 82 /**
michael@0 83 * Templated wrapper for SkPtrSet, just meant to automate typecasting
michael@0 84 * parameters to and from void* (which the base class expects).
michael@0 85 */
michael@0 86 template <typename T> class SkTPtrSet : public SkPtrSet {
michael@0 87 public:
michael@0 88 uint32_t find(T ptr) {
michael@0 89 return this->INHERITED::find((void*)ptr);
michael@0 90 }
michael@0 91 uint32_t add(T ptr) {
michael@0 92 return this->INHERITED::add((void*)ptr);
michael@0 93 }
michael@0 94
michael@0 95 void copyToArray(T* array) const {
michael@0 96 this->INHERITED::copyToArray((void**)array);
michael@0 97 }
michael@0 98
michael@0 99 private:
michael@0 100 typedef SkPtrSet INHERITED;
michael@0 101 };
michael@0 102
michael@0 103 /**
michael@0 104 * Subclass of SkTPtrSet specialed to call ref() and unref() when the
michael@0 105 * base class's incPtr() and decPtr() are called. This makes it a valid owner
michael@0 106 * of each ptr, which is released when the set is reset or destroyed.
michael@0 107 */
michael@0 108 class SkRefCntSet : public SkTPtrSet<SkRefCnt*> {
michael@0 109 public:
michael@0 110 virtual ~SkRefCntSet();
michael@0 111
michael@0 112 protected:
michael@0 113 // overrides
michael@0 114 virtual void incPtr(void*);
michael@0 115 virtual void decPtr(void*);
michael@0 116 };
michael@0 117
michael@0 118 class SkFactorySet : public SkTPtrSet<SkFlattenable::Factory> {};
michael@0 119
michael@0 120 /**
michael@0 121 * Similar to SkFactorySet, but only allows Factorys that have registered names.
michael@0 122 * Also has a function to return the next added Factory's name.
michael@0 123 */
michael@0 124 class SkNamedFactorySet : public SkRefCnt {
michael@0 125 public:
michael@0 126 SK_DECLARE_INST_COUNT(SkNamedFactorySet)
michael@0 127
michael@0 128 SkNamedFactorySet();
michael@0 129
michael@0 130 /**
michael@0 131 * Find the specified Factory in the set. If it is not already in the set,
michael@0 132 * and has registered its name, add it to the set, and return its index.
michael@0 133 * If the Factory has no registered name, return 0.
michael@0 134 */
michael@0 135 uint32_t find(SkFlattenable::Factory);
michael@0 136
michael@0 137 /**
michael@0 138 * If new Factorys have been added to the set, return the name of the first
michael@0 139 * Factory added after the Factory name returned by the last call to this
michael@0 140 * function.
michael@0 141 */
michael@0 142 const char* getNextAddedFactoryName();
michael@0 143 private:
michael@0 144 int fNextAddedFactory;
michael@0 145 SkFactorySet fFactorySet;
michael@0 146 SkTDArray<const char*> fNames;
michael@0 147
michael@0 148 typedef SkRefCnt INHERITED;
michael@0 149 };
michael@0 150
michael@0 151 #endif

mercurial