1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_dom_DispatcherTrait_h
8 #define mozilla_dom_DispatcherTrait_h
9 
10 #include "mozilla/AlreadyAddRefed.h"
11 #include "mozilla/TaskCategory.h"
12 #include "ErrorList.h"
13 
14 class nsIRunnable;
15 class nsISerialEventTarget;
16 
17 namespace mozilla {
18 class AbstractThread;
19 namespace dom {
20 // This trait should be attached to classes like nsIGlobalObject and
21 // Document that have a DocGroup attached to them. The methods here
22 // should delegate to the DocGroup. We can't use the
23 // Dispatcher class directly because it inherits from nsISupports.
24 class DispatcherTrait {
25  public:
26   // This method may or may not be safe off of the main thread. For Document it
27   // is safe. For nsIGlobalWindow it is not safe.
28   virtual nsresult Dispatch(TaskCategory aCategory,
29                             already_AddRefed<nsIRunnable>&& aRunnable);
30 
31   // This method may or may not be safe off of the main thread. For Document it
32   // is safe. For nsIGlobalWindow it is not safe. The nsISerialEventTarget can
33   // always be used off the main thread.
34   virtual nsISerialEventTarget* EventTargetFor(TaskCategory aCategory) const;
35 
36   // Must be called on the main thread. The AbstractThread can always be used
37   // off the main thread.
38   virtual AbstractThread* AbstractMainThreadFor(TaskCategory aCategory);
39 };
40 
41 }  // namespace dom
42 }  // namespace mozilla
43 
44 #endif  // mozilla_dom_DispatcherTrait_h
45