Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/plugins/ipc/FunctionBrokerThread.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2
 * vim: sw=4 ts=4 et :
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_plugins_functionbrokerthread_h
8
#define mozilla_plugins_functionbrokerthread_h
9
10
#include "nsThreadManager.h"
11
12
namespace mozilla {
13
namespace plugins {
14
15
class FunctionBrokerThread
16
{
17
public:
18
  void Dispatch(already_AddRefed<nsIRunnable>&& aRunnable)
19
0
  {
20
0
    mThread->Dispatch(std::move(aRunnable), nsIEventTarget::NS_DISPATCH_NORMAL);
21
0
  }
22
23
  bool IsOnThread()
24
0
  {
25
0
    bool on;
26
0
    return NS_SUCCEEDED(mThread->IsOnCurrentThread(&on)) && on;
27
0
  }
28
29
  static FunctionBrokerThread* Create()
30
0
  {
31
0
    MOZ_RELEASE_ASSERT(NS_IsMainThread());
32
0
    nsCOMPtr<nsIThread> thread;
33
0
    if (NS_FAILED(NS_NewNamedThread("Function Broker", getter_AddRefs(thread)))) {
34
0
      return nullptr;
35
0
    }
36
0
    return new FunctionBrokerThread(thread);
37
0
  }
38
39
  ~FunctionBrokerThread()
40
0
  {
41
0
    MOZ_RELEASE_ASSERT(NS_IsMainThread());
42
0
    mThread->Shutdown();
43
0
  }
44
45
private:
46
  explicit FunctionBrokerThread(nsIThread* aThread) : mThread(aThread)
47
0
  {
48
0
    MOZ_ASSERT(mThread);
49
0
  }
50
51
  nsCOMPtr<nsIThread> mThread;
52
};
53
54
} // namespace plugins
55
} // namespace mozilla
56
57
#endif // mozilla_plugins_functionbrokerthread_h