Bug 1660755 [wpt PR 25207] - [scroll-animations] Allow null source in ScrollTimeline...
[gecko.git] / ipc / glue / BrowserProcessSubThread.h
blob03e56f617f5507282f94669ea8dc3d75bbcfd9c5
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/. */
7 #ifndef mozilla_ipc_BrowserProcessSubThread_h
8 #define mozilla_ipc_BrowserProcessSubThread_h
10 #include "base/thread.h"
11 #include "mozilla/StaticMutex.h"
13 #include "nsDebug.h"
15 namespace mozilla {
16 namespace ipc {
18 // Copied from browser_process_impl.cc, modified slightly.
19 class BrowserProcessSubThread : public base::Thread {
20 public:
21 // An enumeration of the well-known threads.
22 enum ID {
23 IO,
25 // This identifier does not represent a thread. Instead it counts
26 // the number of well-known threads. Insert new well-known
27 // threads before this identifier.
28 ID_COUNT
31 explicit BrowserProcessSubThread(ID aId);
32 ~BrowserProcessSubThread();
34 static MessageLoop* GetMessageLoop(ID identifier);
36 protected:
37 virtual void Init() override;
38 virtual void CleanUp() override;
40 private:
41 // The identifier of this thread. Only one thread can exist with a given
42 // identifier at a given time.
43 ID mIdentifier;
45 // This lock protects |browser_threads_|. Do not read or modify that array
46 // without holding this lock. Do not block while holding this lock.
48 static StaticMutex sLock;
50 // An array of the ChromeThread objects. This array is protected by |lock_|.
51 // The threads are not owned by this array. Typically, the threads are owned
52 // on the UI thread by the g_browser_process object. ChromeThreads remove
53 // themselves from this array upon destruction.
54 static BrowserProcessSubThread* sBrowserThreads[ID_COUNT];
57 inline void AssertIOThread() {
58 NS_ASSERTION(MessageLoop::TYPE_IO == MessageLoop::current()->type(),
59 "should be on the IO thread!");
62 } // namespace ipc
63 } // namespace mozilla
65 #endif // mozilla_ipc_BrowserProcessSubThread_h