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 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef PlayingRefChangeHandler_h__
8 #define PlayingRefChangeHandler_h__
10 #include "nsThreadUtils.h"
11 #include "AudioNodeStream.h"
13 namespace mozilla {
14 namespace dom {
16 class PlayingRefChangeHandler : public nsRunnable
17 {
18 public:
19 enum ChangeType { ADDREF, RELEASE };
20 PlayingRefChangeHandler(AudioNodeStream* aStream, ChangeType aChange)
21 : mStream(aStream)
22 , mChange(aChange)
23 {
24 }
26 NS_IMETHOD Run()
27 {
28 nsRefPtr<AudioNode> node;
29 {
30 // No need to keep holding the lock for the whole duration of this
31 // function, since we're holding a strong reference to it, so if
32 // we can obtain the reference, we will hold the node alive in
33 // this function.
34 MutexAutoLock lock(mStream->Engine()->NodeMutex());
35 node = mStream->Engine()->Node();
36 }
37 if (node) {
38 if (mChange == ADDREF) {
39 node->MarkActive();
40 } else if (mChange == RELEASE) {
41 node->MarkInactive();
42 }
43 }
44 return NS_OK;
45 }
47 private:
48 nsRefPtr<AudioNodeStream> mStream;
49 ChangeType mChange;
50 };
52 }
53 }
55 #endif