Backed out 10 changesets (bug 1803810) for xpcshell failures on test_import_global...
[gecko.git] / netwerk / ipc / NeckoTargetHolder.h
blob254d6f138f4080f8adb21ce5d6fb7461ad276d9a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et tw=80 : */
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/. */
8 #ifndef mozilla_net_NeckoTargetHolder_h
9 #define mozilla_net_NeckoTargetHolder_h
11 #include "nsIEventTarget.h"
12 #include "nsThreadUtils.h"
14 namespace mozilla {
15 namespace net {
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) {}
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(already_AddRefed<nsIRunnable>&& aRunnable,
31 uint32_t aDispatchFlags = NS_DISPATCH_NORMAL);
33 // EventTarget for labeling networking events.
34 nsCOMPtr<nsISerialEventTarget> mNeckoTarget;
37 } // namespace net
38 } // namespace mozilla
40 #endif