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.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsAutoPtr.h"
7 #include "nsCOMPtr.h"
8 #include "nsCycleCollectionParticipant.h"
9 #include "nsISupportsUtils.h"
10 #include "nsTransactionItem.h"
11 #include "nsTransactionStack.h"
12 #include "nscore.h"
14 nsTransactionStack::nsTransactionStack(nsTransactionStack::Type aType)
15 : mType(aType)
16 {
17 }
19 nsTransactionStack::~nsTransactionStack()
20 {
21 Clear();
22 }
24 void
25 nsTransactionStack::Push(nsTransactionItem *aTransaction)
26 {
27 if (!aTransaction) {
28 return;
29 }
31 // The stack's bottom is the front of the deque, and the top is the back.
32 mDeque.push_back(aTransaction);
33 }
35 already_AddRefed<nsTransactionItem>
36 nsTransactionStack::Pop()
37 {
38 if (mDeque.empty()) {
39 return nullptr;
40 }
41 nsRefPtr<nsTransactionItem> ret = mDeque.back().forget();
42 mDeque.pop_back();
43 return ret.forget();
44 }
46 already_AddRefed<nsTransactionItem>
47 nsTransactionStack::PopBottom()
48 {
49 if (mDeque.empty()) {
50 return nullptr;
51 }
52 nsRefPtr<nsTransactionItem> ret = mDeque.front().forget();
53 mDeque.pop_front();
54 return ret.forget();
55 }
57 already_AddRefed<nsTransactionItem>
58 nsTransactionStack::Peek()
59 {
60 if (mDeque.empty()) {
61 return nullptr;
62 }
63 nsRefPtr<nsTransactionItem> ret = mDeque.back();
64 return ret.forget();
65 }
67 already_AddRefed<nsTransactionItem>
68 nsTransactionStack::GetItem(int32_t aIndex)
69 {
70 if (aIndex < 0 || aIndex >= static_cast<int32_t>(mDeque.size())) {
71 return nullptr;
72 }
73 nsRefPtr<nsTransactionItem> ret = mDeque[aIndex];
74 return ret.forget();
75 }
77 void
78 nsTransactionStack::Clear()
79 {
80 while (!mDeque.empty()) {
81 nsRefPtr<nsTransactionItem> tx = mType == FOR_UNDO ? Pop() : PopBottom();
82 };
83 }
85 void
86 nsTransactionStack::DoTraverse(nsCycleCollectionTraversalCallback &cb)
87 {
88 int32_t size = mDeque.size();
89 for (int32_t i = 0; i < size; ++i) {
90 nsTransactionItem* item = mDeque[i];
91 if (item) {
92 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "transaction stack mDeque[i]");
93 cb.NoteNativeChild(item, NS_CYCLE_COLLECTION_PARTICIPANT(nsTransactionItem));
94 }
95 }
96 }