Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 nsHtml5StreamListener_h |
michael@0 | 6 | #define nsHtml5StreamListener_h |
michael@0 | 7 | |
michael@0 | 8 | #include "nsIStreamListener.h" |
michael@0 | 9 | #include "nsIThreadRetargetableStreamListener.h" |
michael@0 | 10 | #include "nsHtml5RefPtr.h" |
michael@0 | 11 | #include "nsHtml5StreamParser.h" |
michael@0 | 12 | |
michael@0 | 13 | /** |
michael@0 | 14 | * The purpose of this class is to reconcile the problem that |
michael@0 | 15 | * nsHtml5StreamParser is a cycle collection participant, which means that it |
michael@0 | 16 | * can only be refcounted on the main thread, but |
michael@0 | 17 | * nsIThreadRetargetableStreamListener can be refcounted from another thread, |
michael@0 | 18 | * so nsHtml5StreamParser being an nsIThreadRetargetableStreamListener was |
michael@0 | 19 | * a memory corruption problem. |
michael@0 | 20 | * |
michael@0 | 21 | * mDelegate is an nsHtml5RefPtr, which releases the object that it points |
michael@0 | 22 | * to from a runnable on the main thread. DropDelegate() is only called on |
michael@0 | 23 | * the main thread. This call will finish before the main-thread derefs the |
michael@0 | 24 | * nsHtml5StreamListener itself, so there is no risk of another thread making |
michael@0 | 25 | * the refcount of nsHtml5StreamListener go to zero and running the destructor |
michael@0 | 26 | * concurrently. Other than that, the thread-safe nsISupports implementation |
michael@0 | 27 | * takes care of the destructor not running concurrently from different |
michael@0 | 28 | * threads, so there is no need to have a mutex around nsHtml5RefPtr to |
michael@0 | 29 | * prevent it from double-releasing nsHtml5StreamParser. |
michael@0 | 30 | */ |
michael@0 | 31 | class nsHtml5StreamListener : public nsIStreamListener, |
michael@0 | 32 | public nsIThreadRetargetableStreamListener |
michael@0 | 33 | { |
michael@0 | 34 | public: |
michael@0 | 35 | nsHtml5StreamListener(nsHtml5StreamParser* aDelegate); |
michael@0 | 36 | virtual ~nsHtml5StreamListener(); |
michael@0 | 37 | |
michael@0 | 38 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 39 | NS_DECL_NSIREQUESTOBSERVER |
michael@0 | 40 | NS_DECL_NSISTREAMLISTENER |
michael@0 | 41 | NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER |
michael@0 | 42 | |
michael@0 | 43 | inline nsHtml5StreamParser* GetDelegate() |
michael@0 | 44 | { |
michael@0 | 45 | return mDelegate; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | void DropDelegate(); |
michael@0 | 49 | |
michael@0 | 50 | private: |
michael@0 | 51 | nsHtml5RefPtr<nsHtml5StreamParser> mDelegate; |
michael@0 | 52 | }; |
michael@0 | 53 | |
michael@0 | 54 | #endif // nsHtml5StreamListener_h |