NeckoTargetHolder.h (1392B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set sw=2 ts=8 et tw=80 : */ 3 4 /* This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 7 8 #ifndef mozilla_net_NeckoTargetHolder_h 9 #define mozilla_net_NeckoTargetHolder_h 10 11 #include "nsIEventTarget.h" 12 #include "nsThreadUtils.h" 13 14 namespace mozilla { 15 namespace net { 16 17 // A helper class that implements GetNeckoTarget(). Basically, all e10s child 18 // channels should inherit this class in order to get a labeled event target. 19 class NeckoTargetHolder { 20 public: 21 explicit NeckoTargetHolder(nsISerialEventTarget* aNeckoTarget) 22 : mNeckoTarget(aNeckoTarget) {} 23 24 protected: 25 virtual ~NeckoTargetHolder() = default; 26 // Get event target for processing network events. 27 virtual already_AddRefed<nsISerialEventTarget> GetNeckoTarget(); 28 // When |mNeckoTarget| is not null, use it to dispatch the runnable. 29 // Otherwise, dispatch the runnable to the main thread. 30 nsresult Dispatch( 31 already_AddRefed<nsIRunnable>&& aRunnable, 32 nsIEventTarget::DispatchFlags aDispatchFlags = NS_DISPATCH_NORMAL); 33 34 // EventTarget for labeling networking events. 35 nsCOMPtr<nsISerialEventTarget> mNeckoTarget; 36 }; 37 38 } // namespace net 39 } // namespace mozilla 40 41 #endif