Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef CacheIOThread__h__ |
michael@0 | 6 | #define CacheIOThread__h__ |
michael@0 | 7 | |
michael@0 | 8 | #include "nsIThreadInternal.h" |
michael@0 | 9 | #include "nsISupportsImpl.h" |
michael@0 | 10 | #include "prthread.h" |
michael@0 | 11 | #include "nsTArray.h" |
michael@0 | 12 | #include "nsAutoPtr.h" |
michael@0 | 13 | #include "mozilla/Monitor.h" |
michael@0 | 14 | |
michael@0 | 15 | class nsIRunnable; |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | namespace net { |
michael@0 | 19 | |
michael@0 | 20 | class CacheIOThread : public nsIThreadObserver |
michael@0 | 21 | { |
michael@0 | 22 | public: |
michael@0 | 23 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 24 | NS_DECL_NSITHREADOBSERVER |
michael@0 | 25 | |
michael@0 | 26 | CacheIOThread(); |
michael@0 | 27 | virtual ~CacheIOThread(); |
michael@0 | 28 | |
michael@0 | 29 | enum ELevel { |
michael@0 | 30 | OPEN_PRIORITY, |
michael@0 | 31 | READ_PRIORITY, |
michael@0 | 32 | OPEN, |
michael@0 | 33 | READ, |
michael@0 | 34 | MANAGEMENT, |
michael@0 | 35 | WRITE, |
michael@0 | 36 | CLOSE, |
michael@0 | 37 | INDEX, |
michael@0 | 38 | EVICT, |
michael@0 | 39 | LAST_LEVEL, |
michael@0 | 40 | |
michael@0 | 41 | // This is actually executed as the first level, but we want this enum |
michael@0 | 42 | // value merely as an indicator while other values are used as indexes |
michael@0 | 43 | // to the queue array. Hence put at end and not as the first. |
michael@0 | 44 | XPCOM_LEVEL |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | nsresult Init(); |
michael@0 | 48 | nsresult Dispatch(nsIRunnable* aRunnable, uint32_t aLevel); |
michael@0 | 49 | // Makes sure that any previously posted event to OPEN or OPEN_PRIORITY |
michael@0 | 50 | // levels (such as file opennings and dooms) are executed before aRunnable |
michael@0 | 51 | // that is intended to evict stuff from the cache. |
michael@0 | 52 | nsresult DispatchAfterPendingOpens(nsIRunnable* aRunnable); |
michael@0 | 53 | bool IsCurrentThread(); |
michael@0 | 54 | |
michael@0 | 55 | /** |
michael@0 | 56 | * Callable only on this thread, checks if there is an event waiting in |
michael@0 | 57 | * the event queue with a higher execution priority. If so, the result |
michael@0 | 58 | * is true and the current event handler should break it's work and return |
michael@0 | 59 | * from Run() method immediately. The event handler will be rerun again |
michael@0 | 60 | * when all more priority events are processed. Events pending after this |
michael@0 | 61 | * handler (i.e. the one that called YieldAndRerun()) will not execute sooner |
michael@0 | 62 | * then this handler is executed w/o a call to YieldAndRerun(). |
michael@0 | 63 | */ |
michael@0 | 64 | static bool YieldAndRerun() |
michael@0 | 65 | { |
michael@0 | 66 | return sSelf ? sSelf->YieldInternal() : false; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | nsresult Shutdown(); |
michael@0 | 70 | already_AddRefed<nsIEventTarget> Target(); |
michael@0 | 71 | |
michael@0 | 72 | // Memory reporting |
michael@0 | 73 | size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const; |
michael@0 | 74 | size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const; |
michael@0 | 75 | |
michael@0 | 76 | private: |
michael@0 | 77 | static void ThreadFunc(void* aClosure); |
michael@0 | 78 | void ThreadFunc(); |
michael@0 | 79 | void LoopOneLevel(uint32_t aLevel); |
michael@0 | 80 | bool EventsPending(uint32_t aLastLevel = LAST_LEVEL); |
michael@0 | 81 | nsresult DispatchInternal(nsIRunnable* aRunnable, uint32_t aLevel); |
michael@0 | 82 | bool YieldInternal(); |
michael@0 | 83 | |
michael@0 | 84 | static CacheIOThread* sSelf; |
michael@0 | 85 | |
michael@0 | 86 | mozilla::Monitor mMonitor; |
michael@0 | 87 | PRThread* mThread; |
michael@0 | 88 | nsCOMPtr<nsIThread> mXPCOMThread; |
michael@0 | 89 | uint32_t mLowestLevelWaiting; |
michael@0 | 90 | uint32_t mCurrentlyExecutingLevel; |
michael@0 | 91 | nsTArray<nsRefPtr<nsIRunnable> > mEventQueue[LAST_LEVEL]; |
michael@0 | 92 | |
michael@0 | 93 | bool mHasXPCOMEvents; |
michael@0 | 94 | bool mRerunCurrentEvent; |
michael@0 | 95 | bool mShutdown; |
michael@0 | 96 | }; |
michael@0 | 97 | |
michael@0 | 98 | } // net |
michael@0 | 99 | } // mozilla |
michael@0 | 100 | |
michael@0 | 101 | #endif |