Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef TRANSFRMX_LIST_H |
michael@0 | 7 | #define TRANSFRMX_LIST_H |
michael@0 | 8 | |
michael@0 | 9 | #include "txCore.h" |
michael@0 | 10 | |
michael@0 | 11 | class txListIterator; |
michael@0 | 12 | |
michael@0 | 13 | /** |
michael@0 | 14 | * Represents an ordered list of Object pointers. Modeled after a Java 2 List. |
michael@0 | 15 | **/ |
michael@0 | 16 | class txList : public txObject { |
michael@0 | 17 | |
michael@0 | 18 | friend class txListIterator; |
michael@0 | 19 | |
michael@0 | 20 | public: |
michael@0 | 21 | |
michael@0 | 22 | /** |
michael@0 | 23 | * Creates an empty txList |
michael@0 | 24 | **/ |
michael@0 | 25 | txList(); |
michael@0 | 26 | |
michael@0 | 27 | /** |
michael@0 | 28 | * txList destructor, object references will not be deleted. |
michael@0 | 29 | **/ |
michael@0 | 30 | ~txList(); |
michael@0 | 31 | |
michael@0 | 32 | /** |
michael@0 | 33 | * Returns the number of items in this txList |
michael@0 | 34 | **/ |
michael@0 | 35 | int32_t getLength(); |
michael@0 | 36 | |
michael@0 | 37 | /** |
michael@0 | 38 | * Returns true if there are no items in this txList |
michael@0 | 39 | */ |
michael@0 | 40 | inline bool isEmpty() |
michael@0 | 41 | { |
michael@0 | 42 | return itemCount == 0; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * Adds the given Object to the list |
michael@0 | 47 | **/ |
michael@0 | 48 | nsresult add(void* objPtr); |
michael@0 | 49 | |
michael@0 | 50 | /* |
michael@0 | 51 | * Removes all the objects from the list |
michael@0 | 52 | */ |
michael@0 | 53 | void clear(); |
michael@0 | 54 | |
michael@0 | 55 | protected: |
michael@0 | 56 | |
michael@0 | 57 | struct ListItem { |
michael@0 | 58 | ListItem* nextItem; |
michael@0 | 59 | ListItem* prevItem; |
michael@0 | 60 | void* objPtr; |
michael@0 | 61 | }; |
michael@0 | 62 | |
michael@0 | 63 | /** |
michael@0 | 64 | * Removes the given ListItem pointer from the list |
michael@0 | 65 | **/ |
michael@0 | 66 | ListItem* remove(ListItem* sItem); |
michael@0 | 67 | |
michael@0 | 68 | private: |
michael@0 | 69 | txList(const txList& aOther); // not implemented |
michael@0 | 70 | |
michael@0 | 71 | ListItem* firstItem; |
michael@0 | 72 | ListItem* lastItem; |
michael@0 | 73 | int32_t itemCount; |
michael@0 | 74 | |
michael@0 | 75 | nsresult insertAfter(void* objPtr, ListItem* sItem); |
michael@0 | 76 | nsresult insertBefore(void* objPtr, ListItem* sItem); |
michael@0 | 77 | }; |
michael@0 | 78 | |
michael@0 | 79 | |
michael@0 | 80 | |
michael@0 | 81 | /** |
michael@0 | 82 | * An Iterator for the txList Class |
michael@0 | 83 | **/ |
michael@0 | 84 | class txListIterator { |
michael@0 | 85 | |
michael@0 | 86 | public: |
michael@0 | 87 | /** |
michael@0 | 88 | * Creates a new txListIterator for the given txList |
michael@0 | 89 | * @param list, the txList to create an Iterator for |
michael@0 | 90 | **/ |
michael@0 | 91 | txListIterator(txList* list); |
michael@0 | 92 | |
michael@0 | 93 | /** |
michael@0 | 94 | * Adds the Object pointer to the txList pointed to by this txListIterator. |
michael@0 | 95 | * The Object pointer is inserted as the next item in the txList |
michael@0 | 96 | * based on the current position within the txList |
michael@0 | 97 | * @param objPtr the Object pointer to add to the list |
michael@0 | 98 | **/ |
michael@0 | 99 | nsresult addAfter(void* objPtr); |
michael@0 | 100 | |
michael@0 | 101 | /** |
michael@0 | 102 | * Adds the Object pointer to the txList pointed to by this txListIterator. |
michael@0 | 103 | * The Object pointer is inserted as the previous item in the txList |
michael@0 | 104 | * based on the current position within the txList |
michael@0 | 105 | * @param objPtr the Object pointer to add to the list |
michael@0 | 106 | **/ |
michael@0 | 107 | nsresult addBefore(void* objPtr); |
michael@0 | 108 | |
michael@0 | 109 | /** |
michael@0 | 110 | * Returns true if a successful call to the next() method can be made |
michael@0 | 111 | * @return true if a successful call to the next() method can be made, |
michael@0 | 112 | * otherwise false |
michael@0 | 113 | **/ |
michael@0 | 114 | bool hasNext(); |
michael@0 | 115 | |
michael@0 | 116 | /** |
michael@0 | 117 | * Returns the next Object pointer from the list |
michael@0 | 118 | **/ |
michael@0 | 119 | void* next(); |
michael@0 | 120 | |
michael@0 | 121 | /** |
michael@0 | 122 | * Returns the previous Object pointer from the list |
michael@0 | 123 | **/ |
michael@0 | 124 | void* previous(); |
michael@0 | 125 | |
michael@0 | 126 | /** |
michael@0 | 127 | * Returns the current Object |
michael@0 | 128 | **/ |
michael@0 | 129 | void* current(); |
michael@0 | 130 | |
michael@0 | 131 | /** |
michael@0 | 132 | * Removes the Object last returned by the next() or previous() methods; |
michael@0 | 133 | * @return the removed Object pointer |
michael@0 | 134 | **/ |
michael@0 | 135 | void* remove(); |
michael@0 | 136 | |
michael@0 | 137 | /** |
michael@0 | 138 | * Resets the current location within the txList to the beginning of the txList |
michael@0 | 139 | **/ |
michael@0 | 140 | void reset(); |
michael@0 | 141 | |
michael@0 | 142 | /** |
michael@0 | 143 | * Resets the current location within the txList to the end of the txList |
michael@0 | 144 | **/ |
michael@0 | 145 | void resetToEnd(); |
michael@0 | 146 | |
michael@0 | 147 | private: |
michael@0 | 148 | |
michael@0 | 149 | //-- points to the current list item |
michael@0 | 150 | txList::ListItem* currentItem; |
michael@0 | 151 | |
michael@0 | 152 | //-- points to the list to iterator over |
michael@0 | 153 | txList* list; |
michael@0 | 154 | |
michael@0 | 155 | //-- we've moved off the end of the list |
michael@0 | 156 | bool atEndOfList; |
michael@0 | 157 | }; |
michael@0 | 158 | |
michael@0 | 159 | typedef txList List; |
michael@0 | 160 | |
michael@0 | 161 | #endif |