Files
palemoon27/xpcom/threads/AbstractThread.cpp
T
roytam1 2828386673 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1247182 - Add an nsCSSRuleProcessor constructor that takes ownership of the given sheet array. r=birtles (07fd64f305)
- Bug 1260983 - Update animation properties when the style context changes; r=heycam (f68f67fc24)
- Bug 1160342 - Implement marquee using mutation observers, r=smaug (f8be96bfd8)
- Bug 1219842 - Enable a bunch of mochitest-plain tests under e10s. r=mrbkap (40aa7c1fce)
- Bug 1249061 - Improve property/attribute handling for marquees. r=smaug (1189869b3d)
- Bug 1266324 - Rename style const macro for unicode-bidi:bidi-override to be consistent with other style consts. r=jfkthame (24ded3fb69)
- Bug 1189894 - remove Atomics.h IntrinsicAddSub hack; r=erahm (d68fcf1801)
- Bug 1247338 - really make Atomic's constructor constexpr; r=Waldo (948c372b36)
- Bug 1266294 - Remove unnecessary compiler version checks for gcc <= 4.8.0 in mfbt. r=froydnj (8739fa352b)
- Bug 1260247. In chaos mode randomly decide to start a new image load even if the image is in the image cache when allowed by spec. r=seth (0d9dd4a1e9)
- Bug 1266294 - Remove unnecessary compiler version checks for gcc <= 4.8.0 in mfbt. r=froydnj (c230e51053)
- Bug 1209100 - Back out bug 1165185 on inbound. (af5f585393)
- Bug 1263342 - don't use REFCOUNTED_VIRTUAL_TYPENAME for mfbt FunctionImplBase. r=froydnj (f02a160c0b)
- Bug 1262577 - allow comparing mozilla::function with nullptr. r=froydnj (515a90b79a)
- Bug 1232418 - Allow mozilla::Tuple to support equality comparison; r=Waldo (1e8cb10660)
- Bug 1262663 - Clean up UniquePtr return documentation. r=Waldo (e92392b74e)
- Bug 1254831 - Fix compiler errors when SHOW_BOUNDING_BOX #ifdef is enabled. r=fredw (c0982211e8)
- Bug 1161169: Clean up usage of mContentParent and clearly identify it as specifically for async plugin init; r=billm,jimm (2ed3b9f96d)
- Bug 1164931 - Clear hangs when they're over (r=mrbkap) (f8de731e19)
- Bug 1250046 - Remove Shumway references from IPC. r=jmathies (7d7305c309)
- Bug 1254831 - Invalidate mfracs when linethickness changes. r=fredw (ff3d2bf6d0)
- Bug 1256943: Ensure that BLOCKED_ON_PLUGIN_MODULE_INIT_MS is being recorded in e10s chrome; r=jimm (ab879d7aec)
- Bug 1248821 - Force Flash to windowless mode regardless of sandbox level. r=jimm (007d45d5ef)
- Bug 1253434 - Avoid trying to capture plugin windows that have a zero width or height and a positive value for the other dim. r=aklotz (7a4995e8a5)
- Bug 1254829 - Calling TerminateProcess for WindowsXP to bypass DLL detach handler, r=bsmedberg (c04377e7b9)
- Bug 1263499 - unify the QuickExit function, r=bsmedberg (eeefdd7c2b)
- Bug 1246763 - Refactor GMP info file parsing into helper class. r=gerald (b4544c7370)
- Bug 1247556 - Use GMPInfoFileParser in GMPParent::ReadGMPMetaData(). r=gerald (6369ea568b)
- Bug 1247763 - Remove info file parsing from GMP child process. r=gerald (4454d25162)
- Bug 1258220 - Disable Adobe GMP if SSE2 isn't supported. r=gerald (55aba6b28a)
- Bug 1245789 - Make GMPParent::Init() return a promise, so it can be async. r=gerald (34ecae588a)
- Bug 1245789 - Add GMPAdapter which can be passed to GMPLoader to adapt non GMP library to GMP API. r=gerald (11f1734a6a)
- Bug 1245789 - Send name of GMPAdapter over to GMP process in StartPlugin message. r=gerald (a7b2df2c0d)
- Bug 1231633 - give scalar mLoadReplace a default value. r=bz (a7d1293b26)
- Bug 1245743 - Don't push new timeline markers while popping markers. r=vporof (f6efe5651e)
- Bug 1255459 - Use AutoRestore in ObservedDocShell::PopMarkers. r=smaug (d5fa90046e)
- Bug 1244897 - Use TimerlineConsumers in PopProfileTimelineMarkers to ensure that all methods acquire TimelineConsumers Mutex. r=vporof (39485ada73)
- Bug 1253516 - Do not acquire a lock that protects data that is not used; r=vporof (773337acce)
- Bug 1262970 - Change PRINCIPAL_HANDLE_NONE to a nullptr #define. r=froydnj (df470bc91c)
- Bug 1068596 - Pass SHARE_DELETE when opening a file so the file can be deleted without waiting for GC. r=roc (5b7d146cb8)
- Bug 1262970 - Allow nsMainThreadPtrHandle to be constructed by and compared to nullptr. r=froydnj (dbf01e5191)
- Bug 1249904: Use content-range values to determine length if content-length is unknown. r=roc (38a1388ea5)
- Bug 1251044: P1. Use content-range values to determine content's length. r=roc (72fb7f2a37)
- Bug 1251044: P2. Remove dead code and generalise the use of content-range header. r=roc (81d8dbf6f0)
- Bug 1228677 - Do not enforce CORS when loading file for MediaResource. r=cpearce (7d042fd6c2)
- Bug 1142272 - platformAPI memory leak, delete on return false. r=erahm (a7932ba850)
- Bug 1149616 - Fix the calculation of slots count in Read/WriteBuffer. r=bechen (6a2d010b3b)
- Bug 1262473 - don't needlessly construct nsAutoCString temporaries when serializing GMPVideoCodec; r=cpearce (7734560bb5)
- Bug 1245789 - Handle unencrypted samples in encrypted media. r=gerald Some encrypted MP4 files lack subsample info for some samples, so we need this check to prevent us crashing on such files. (6cf556699c)
- Bug 1245789 - Load Widevine CDM with sandbox level USER_RESTRICTED instead of USER_LOCKDOWN. r=bobowen (fd1ffd40a4)
- Bug 1245789 - Store GMPCapabilities by value, rather than on the heap. r=gerald (06c1737a4b)
- non-EME bits of Bug 1245789 - Parse Chrome CDM manifest in GMPService.addPluginDir (4116c843bd)
- Bug 1245789 - Whitelist functions needed by Widevine CDM in GMP child processes. r=jed (e525178fe5)
- Bug 1245789 - Ensure Widevine's nodeId are always unique and not permitted persistent storage. r=gerald (562e5b389b)
- Bug 1245789 - Push detection of WMF decoding for clearkey into GMPParent to simplify request media key system access logic. r=gerald (feffe136ba)
- Bug 1245789 - Make XPCOMThreadWrapper::GetCurrent() work. r=bholley (4e04f099cc)
- Bug 1245789 - Change GMPParent::InitPromise to instead use GenericPromise as defined in MozPromise.h. r=gerald (7c7c0f15d4)
- Bug 1158773: Use the same initial and delayed integrity level for Windows content sandbox level 0. r=tabraldes (2d6607e8a8)
- Bug 1219369: In Windows debug builds allow write access to TEMP for logging purposes. r=tabraldes (61737cff53)
- Bug 1166669: Enable process-level mitigations for the Windows content process sandbox. r=tabraldes (da06c34ceb)
- Bug 1197943: Turn off MITIGATION_STRICT_HANDLE_CHECKS for NPAPI process sandbox for causing hangs. r=aklotz (d31b767cd0)
- Bug 1245789 - Ensure GMPs have finished loading from MOZ_GMP_PATH before GMPServiceParent::GetContentParentFrom returns. r=gerald (361156a95b)
- Bug 1245789 - Ensure GMP service has added all plugins before running GMP remove tests. r=gerald (53616c6f09)
- Bug 1245789 - Expose AsyncAddPluginDirectory on GMPServiceParent. r=gerald (2a0fcd39ee)
- Bug 1183433 - Remove G-M-PServiceParent::AbortAsyncShutdown declaration, as it's not defined nor used anywhere. r=cpearce (b8f29f61dd)
- bit of Bug 1185392 - Use a separate mutex to protect mAsyncShutdownPluginStatesMutex, as mMutex could already be held when trying to update the states. r=cpearce (2be59fc7c9)
2024-06-18 09:37:48 +08:00

164 lines
5.3 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/AbstractThread.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/Maybe.h"
#include "mozilla/MozPromise.h" // We initialize the MozPromise logging in this file.
#include "mozilla/StaticPtr.h"
#include "mozilla/StateWatching.h" // We initialize the StateWatching logging in this file.
#include "mozilla/TaskQueue.h"
#include "mozilla/TaskDispatcher.h"
#include "mozilla/unused.h"
#include "nsThreadUtils.h"
#include "nsContentUtils.h"
#include "nsServiceManagerUtils.h"
namespace mozilla {
LazyLogModule gMozPromiseLog("MozPromise");
LazyLogModule gStateWatchingLog("StateWatching");
StaticRefPtr<AbstractThread> sMainThread;
MOZ_THREAD_LOCAL(AbstractThread*) AbstractThread::sCurrentThreadTLS;
class XPCOMThreadWrapper : public AbstractThread
{
public:
explicit XPCOMThreadWrapper(nsIThread* aTarget, bool aRequireTailDispatch)
: AbstractThread(aRequireTailDispatch)
, mTarget(aTarget)
{
// Our current mechanism of implementing tail dispatch is appshell-specific.
// This is because a very similar mechanism already exists on the main
// thread, and we want to avoid making event dispatch on the main thread
// more complicated than it already is.
//
// If you need to use tail dispatch on other XPCOM threads, you'll need to
// implement an nsIThreadObserver to fire the tail dispatcher at the
// appropriate times.
MOZ_ASSERT_IF(aRequireTailDispatch,
NS_IsMainThread() && NS_GetCurrentThread() == aTarget);
}
virtual void Dispatch(already_AddRefed<nsIRunnable> aRunnable,
DispatchFailureHandling aFailureHandling = AssertDispatchSuccess,
DispatchReason aReason = NormalDispatch) override
{
nsCOMPtr<nsIRunnable> r = aRunnable;
AbstractThread* currentThread;
if (aReason != TailDispatch && (currentThread = GetCurrent()) && RequiresTailDispatch(currentThread)) {
currentThread->TailDispatcher().AddTask(this, r.forget(), aFailureHandling);
return;
}
nsresult rv = mTarget->Dispatch(r, NS_DISPATCH_NORMAL);
MOZ_DIAGNOSTIC_ASSERT(aFailureHandling == DontAssertDispatchSuccess || NS_SUCCEEDED(rv));
Unused << rv;
}
virtual bool IsCurrentThreadIn() override
{
// Compare NSPR threads so that this works after shutdown when
// NS_GetCurrentThread starts returning null.
PRThread* thread = nullptr;
mTarget->GetPRThread(&thread);
bool in = PR_GetCurrentThread() == thread;
MOZ_ASSERT(in == (GetCurrent() == this));
return in;
}
void FireTailDispatcher()
{
MOZ_DIAGNOSTIC_ASSERT(mTailDispatcher.isSome());
mTailDispatcher.ref().DrainDirectTasks();
mTailDispatcher.reset();
}
virtual TaskDispatcher& TailDispatcher() override
{
MOZ_ASSERT(this == sMainThread); // See the comment in the constructor.
MOZ_ASSERT(IsCurrentThreadIn());
if (!mTailDispatcher.isSome()) {
mTailDispatcher.emplace(/* aIsTailDispatcher = */ true);
nsCOMPtr<nsIRunnable> event = NS_NewRunnableMethod(this, &XPCOMThreadWrapper::FireTailDispatcher);
nsContentUtils::RunInStableState(event.forget());
}
return mTailDispatcher.ref();
}
virtual nsIThread* AsXPCOMThread() override { return mTarget; }
private:
RefPtr<nsIThread> mTarget;
Maybe<AutoTaskDispatcher> mTailDispatcher;
};
bool
AbstractThread::RequiresTailDispatch(AbstractThread* aThread) const
{
// We require tail dispatch if both the source and destination
// threads support it.
return SupportsTailDispatch() && aThread->SupportsTailDispatch();
}
AbstractThread*
AbstractThread::MainThread()
{
MOZ_ASSERT(sMainThread);
return sMainThread;
}
void
AbstractThread::InitStatics()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!sMainThread);
nsCOMPtr<nsIThread> mainThread;
NS_GetMainThread(getter_AddRefs(mainThread));
MOZ_DIAGNOSTIC_ASSERT(mainThread);
sMainThread = new XPCOMThreadWrapper(mainThread.get(), /* aRequireTailDispatch = */ true);
ClearOnShutdown(&sMainThread);
if (!sCurrentThreadTLS.init()) {
MOZ_CRASH();
}
sCurrentThreadTLS.set(sMainThread);
}
void
AbstractThread::DispatchStateChange(already_AddRefed<nsIRunnable> aRunnable)
{
GetCurrent()->TailDispatcher().AddStateChangeTask(this, Move(aRunnable));
}
/* static */ void
AbstractThread::DispatchDirectTask(already_AddRefed<nsIRunnable> aRunnable)
{
GetCurrent()->TailDispatcher().AddDirectTask(Move(aRunnable));
}
/* static */
already_AddRefed<AbstractThread>
AbstractThread::CreateXPCOMThreadWrapper(nsIThread* aThread, bool aRequireTailDispatch)
{
RefPtr<XPCOMThreadWrapper> wrapper = new XPCOMThreadWrapper(aThread, aRequireTailDispatch);
// Set the thread-local sCurrentThreadTLS to point to the wrapper on the
// target thread. This ensures that sCurrentThreadTLS is as expected by
// AbstractThread::GetCurrent() on the target thread.
nsCOMPtr<nsIRunnable> r =
NS_NewRunnableFunction([wrapper]() { sCurrentThreadTLS.set(wrapper); });
aThread->Dispatch(r.forget(), NS_DISPATCH_NORMAL);
return wrapper.forget();
}
} // namespace mozilla