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 | * Copyright 2014 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 GrOrderedSet_DEFINED |
michael@0 | 9 | #define GrOrderedSet_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "GrRedBlackTree.h" |
michael@0 | 12 | |
michael@0 | 13 | template <typename T, typename C = GrLess<T> > |
michael@0 | 14 | class GrOrderedSet : public SkNoncopyable { |
michael@0 | 15 | public: |
michael@0 | 16 | /** |
michael@0 | 17 | * Creates an empty set |
michael@0 | 18 | */ |
michael@0 | 19 | GrOrderedSet() : fComp() {} |
michael@0 | 20 | ~GrOrderedSet() {} |
michael@0 | 21 | |
michael@0 | 22 | class Iter; |
michael@0 | 23 | |
michael@0 | 24 | /** |
michael@0 | 25 | * @return true if there are no items in the set, false otherwise. |
michael@0 | 26 | */ |
michael@0 | 27 | bool empty() const { return fRBTree.empty(); } |
michael@0 | 28 | |
michael@0 | 29 | /** |
michael@0 | 30 | * @return the number of items in the set. |
michael@0 | 31 | */ |
michael@0 | 32 | int count() const { return fRBTree.count(); } |
michael@0 | 33 | |
michael@0 | 34 | /** |
michael@0 | 35 | * Removes all items in the set |
michael@0 | 36 | */ |
michael@0 | 37 | void reset() { fRBTree.reset(); } |
michael@0 | 38 | |
michael@0 | 39 | /** |
michael@0 | 40 | * Adds an element to set if it does not already exists in the set. |
michael@0 | 41 | * @param t the item to add |
michael@0 | 42 | * @return an iterator to added element or matching element already in set |
michael@0 | 43 | */ |
michael@0 | 44 | Iter insert(const T& t); |
michael@0 | 45 | |
michael@0 | 46 | /** |
michael@0 | 47 | * Removes the item indicated by an iterator. The iterator will not be valid |
michael@0 | 48 | * afterwards. |
michael@0 | 49 | * @param iter iterator of item to remove. Must be valid (not end()). |
michael@0 | 50 | */ |
michael@0 | 51 | void remove(const Iter& iter); |
michael@0 | 52 | |
michael@0 | 53 | /** |
michael@0 | 54 | * @return an iterator to the first item in sorted order, or end() if empty |
michael@0 | 55 | */ |
michael@0 | 56 | Iter begin(); |
michael@0 | 57 | |
michael@0 | 58 | /** |
michael@0 | 59 | * Gets the last valid iterator. This is always valid, even on an empty. |
michael@0 | 60 | * However, it can never be dereferenced. Useful as a loop terminator. |
michael@0 | 61 | * @return an iterator that is just beyond the last item in sorted order. |
michael@0 | 62 | */ |
michael@0 | 63 | Iter end(); |
michael@0 | 64 | |
michael@0 | 65 | /** |
michael@0 | 66 | * @return an iterator that to the last item in sorted order, or end() if |
michael@0 | 67 | * empty. |
michael@0 | 68 | */ |
michael@0 | 69 | Iter last(); |
michael@0 | 70 | |
michael@0 | 71 | /** |
michael@0 | 72 | * Finds an occurrence of an item. |
michael@0 | 73 | * @param t the item to find. |
michael@0 | 74 | * @return an iterator to a set element equal to t or end() if none exists. |
michael@0 | 75 | */ |
michael@0 | 76 | Iter find(const T& t); |
michael@0 | 77 | |
michael@0 | 78 | private: |
michael@0 | 79 | GrRedBlackTree<T, C> fRBTree; |
michael@0 | 80 | |
michael@0 | 81 | const C fComp; |
michael@0 | 82 | }; |
michael@0 | 83 | |
michael@0 | 84 | template <typename T, typename C> |
michael@0 | 85 | class GrOrderedSet<T,C>::Iter { |
michael@0 | 86 | public: |
michael@0 | 87 | Iter() {} |
michael@0 | 88 | Iter(const Iter& i) { fTreeIter = i.fTreeIter; } |
michael@0 | 89 | Iter& operator =(const Iter& i) { |
michael@0 | 90 | fTreeIter = i.fTreeIter; |
michael@0 | 91 | return *this; |
michael@0 | 92 | } |
michael@0 | 93 | const T& operator *() const { return *fTreeIter; } |
michael@0 | 94 | bool operator ==(const Iter& i) const { |
michael@0 | 95 | return fTreeIter == i.fTreeIter; |
michael@0 | 96 | } |
michael@0 | 97 | bool operator !=(const Iter& i) const { return !(*this == i); } |
michael@0 | 98 | Iter& operator ++() { |
michael@0 | 99 | ++fTreeIter; |
michael@0 | 100 | return *this; |
michael@0 | 101 | } |
michael@0 | 102 | Iter& operator --() { |
michael@0 | 103 | --fTreeIter; |
michael@0 | 104 | return *this; |
michael@0 | 105 | } |
michael@0 | 106 | const typename GrRedBlackTree<T,C>::Iter& getTreeIter() const { |
michael@0 | 107 | return fTreeIter; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | private: |
michael@0 | 111 | friend class GrOrderedSet; |
michael@0 | 112 | explicit Iter(typename GrRedBlackTree<T, C>::Iter iter) { |
michael@0 | 113 | fTreeIter = iter; |
michael@0 | 114 | } |
michael@0 | 115 | typename GrRedBlackTree<T,C>::Iter fTreeIter; |
michael@0 | 116 | }; |
michael@0 | 117 | |
michael@0 | 118 | template <typename T, typename C> |
michael@0 | 119 | typename GrOrderedSet<T,C>::Iter GrOrderedSet<T,C>::begin() { |
michael@0 | 120 | return Iter(fRBTree.begin()); |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | template <typename T, typename C> |
michael@0 | 124 | typename GrOrderedSet<T,C>::Iter GrOrderedSet<T,C>::end() { |
michael@0 | 125 | return Iter(fRBTree.end()); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | template <typename T, typename C> |
michael@0 | 129 | typename GrOrderedSet<T,C>::Iter GrOrderedSet<T,C>::last() { |
michael@0 | 130 | return Iter(fRBTree.last()); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | template <typename T, typename C> |
michael@0 | 134 | typename GrOrderedSet<T,C>::Iter GrOrderedSet<T,C>::find(const T& t) { |
michael@0 | 135 | return Iter(fRBTree.find(t)); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | template <typename T, typename C> |
michael@0 | 139 | typename GrOrderedSet<T,C>::Iter GrOrderedSet<T,C>::insert(const T& t) { |
michael@0 | 140 | if (fRBTree.find(t) == fRBTree.end()) { |
michael@0 | 141 | return Iter(fRBTree.insert(t)); |
michael@0 | 142 | } else { |
michael@0 | 143 | return Iter(fRBTree.find(t)); |
michael@0 | 144 | } |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | template <typename T, typename C> |
michael@0 | 148 | void GrOrderedSet<T,C>::remove(const typename GrOrderedSet<T,C>::Iter& iter) { |
michael@0 | 149 | if (this->end() != iter) { |
michael@0 | 150 | fRBTree.remove(iter.getTreeIter()); |
michael@0 | 151 | } |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | #endif |