Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsHtml5StreamListener_h
6 #define nsHtml5StreamListener_h
8 #include "nsIStreamListener.h"
9 #include "nsIThreadRetargetableStreamListener.h"
10 #include "nsHtml5RefPtr.h"
11 #include "nsHtml5StreamParser.h"
13 /**
14 * The purpose of this class is to reconcile the problem that
15 * nsHtml5StreamParser is a cycle collection participant, which means that it
16 * can only be refcounted on the main thread, but
17 * nsIThreadRetargetableStreamListener can be refcounted from another thread,
18 * so nsHtml5StreamParser being an nsIThreadRetargetableStreamListener was
19 * a memory corruption problem.
20 *
21 * mDelegate is an nsHtml5RefPtr, which releases the object that it points
22 * to from a runnable on the main thread. DropDelegate() is only called on
23 * the main thread. This call will finish before the main-thread derefs the
24 * nsHtml5StreamListener itself, so there is no risk of another thread making
25 * the refcount of nsHtml5StreamListener go to zero and running the destructor
26 * concurrently. Other than that, the thread-safe nsISupports implementation
27 * takes care of the destructor not running concurrently from different
28 * threads, so there is no need to have a mutex around nsHtml5RefPtr to
29 * prevent it from double-releasing nsHtml5StreamParser.
30 */
31 class nsHtml5StreamListener : public nsIStreamListener,
32 public nsIThreadRetargetableStreamListener
33 {
34 public:
35 nsHtml5StreamListener(nsHtml5StreamParser* aDelegate);
36 virtual ~nsHtml5StreamListener();
38 NS_DECL_THREADSAFE_ISUPPORTS
39 NS_DECL_NSIREQUESTOBSERVER
40 NS_DECL_NSISTREAMLISTENER
41 NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
43 inline nsHtml5StreamParser* GetDelegate()
44 {
45 return mDelegate;
46 }
48 void DropDelegate();
50 private:
51 nsHtml5RefPtr<nsHtml5StreamParser> mDelegate;
52 };
54 #endif // nsHtml5StreamListener_h