本文整理汇总了C++中NS_NewRunnableFunction函数的典型用法代码示例。如果您正苦于以下问题:C++ NS_NewRunnableFunction函数的具体用法?C++ NS_NewRunnableFunction怎么用?C++ NS_NewRunnableFunction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NS_NewRunnableFunction函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MOZ_ASSERT
void
GMPCDMCallbackProxy::SessionClosed(const nsCString& aSessionId)
{
MOZ_ASSERT(mProxy->IsOnOwnerThread());
bool keyStatusesChange = false;
auto sid = NS_ConvertUTF8toUTF16(aSessionId);
{
CDMCaps::AutoLock caps(mProxy->Capabilites());
keyStatusesChange = caps.RemoveKeysForSession(NS_ConvertUTF8toUTF16(aSessionId));
}
if (keyStatusesChange) {
RefPtr<CDMProxy> proxy = mProxy;
NS_DispatchToMainThread(
NS_NewRunnableFunction([proxy, sid] ()
{
proxy->OnKeyStatusesChange(sid);
})
);
}
RefPtr<CDMProxy> proxy = mProxy;
NS_DispatchToMainThread(
NS_NewRunnableFunction([proxy, sid] ()
{
proxy->OnSessionClosed(sid);
})
);
}
示例2: lock
NotNull<AllocPolicy*> GlobalAllocPolicy::Instance(TrackType aTrack) {
StaticMutexAutoLock lock(sMutex);
if (aTrack == TrackType::kAudioTrack) {
static RefPtr<AllocPolicyImpl> sAudioPolicy = []() {
SystemGroup::Dispatch(
TaskCategory::Other,
NS_NewRunnableFunction(
"GlobalAllocPolicy::GlobalAllocPolicy:Audio", []() {
ClearOnShutdown(&sAudioPolicy, ShutdownPhase::ShutdownThreads);
}));
return new AllocPolicyImpl(MediaDecoderLimitDefault());
}();
return WrapNotNull(sAudioPolicy.get());
}
static RefPtr<AllocPolicyImpl> sVideoPolicy = []() {
SystemGroup::Dispatch(
TaskCategory::Other,
NS_NewRunnableFunction(
"GlobalAllocPolicy::GlobalAllocPolicy:Audio", []() {
ClearOnShutdown(&sVideoPolicy, ShutdownPhase::ShutdownThreads);
}));
return new AllocPolicyImpl(MediaDecoderLimitDefault());
}();
return WrapNotNull(sVideoPolicy.get());
}
示例3: MOZ_ASSERT
mozilla::ipc::IProtocol*
NuwaParent::CloneProtocol(Channel* aChannel,
ProtocolCloneContext* aCtx)
{
MOZ_ASSERT(NS_IsMainThread());
RefPtr<NuwaParent> self = this;
MonitorAutoLock lock(mMonitor);
// Alloc NuwaParent on the worker thread.
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([self] () -> void
{
MonitorAutoLock lock(self->mMonitor);
// XXX Calling NuwaParent::Alloc() leads to a compilation error. Use
// self->Alloc() as a workaround.
self->mClonedActor = self->Alloc();
lock.Notify();
});
MOZ_ASSERT(runnable);
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(mWorkerThread->Dispatch(runnable,
NS_DISPATCH_NORMAL)));
while (!mClonedActor) {
lock.Wait();
}
RefPtr<NuwaParent> actor = mClonedActor;
mClonedActor = nullptr;
// mManager of the cloned actor is assigned after returning from this method.
// We can't call ActorConstructed() right after Alloc() in the above runnable.
// To be safe we dispatch a runnable to the current thread to do it.
runnable = NS_NewRunnableFunction([actor] () -> void
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIRunnable> nested = NS_NewRunnableFunction([actor] () -> void
{
AssertIsOnBackgroundThread();
// Call NuwaParent::ActorConstructed() on the worker thread.
actor->ActorConstructed();
// The actor can finally be deleted after fully constructed.
mozilla::Unused << actor->Send__delete__(actor);
});
MOZ_ASSERT(nested);
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
actor->mWorkerThread->Dispatch(nested, NS_DISPATCH_NORMAL)));
});
MOZ_ASSERT(runnable);
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(runnable)));
return actor;
}
示例4: ref
void
BenchmarkPlayback::DrainComplete()
{
RefPtr<Benchmark> ref(mMainThreadState);
Dispatch(NS_NewRunnableFunction([this, ref]() {
int32_t frames = mFrameCount - ref->mParameters.mStartupFrame;
TimeDuration elapsedTime = TimeStamp::Now() - mDecodeStartTime;
uint32_t decodeFps = frames / elapsedTime.ToSeconds();
MainThreadShutdown();
ref->Dispatch(NS_NewRunnableFunction([ref, decodeFps]() {
ref->ReturnResult(decodeFps);
}));
}));
}
示例5: SendTelemetry
// A single telemetry sample is reported for each MediaDataDecoder object
// that has detected error or produced output successfully.
static void
SendTelemetry(unsigned long hr)
{
// Collapse the error codes into a range of 0-0xff that can be viewed in
// telemetry histograms. For most MF_E_* errors, unique samples are used,
// retaining the least significant 7 or 8 bits. Other error codes are
// bucketed.
uint32_t sample;
if (SUCCEEDED(hr)) {
sample = 0;
} else if (hr < 0xc00d36b0) {
sample = 1; // low bucket
} else if (hr < 0xc00d3700) {
sample = hr & 0xffU; // MF_E_*
} else if (hr <= 0xc00d3705) {
sample = 0x80 + (hr & 0xfU); // more MF_E_*
} else if (hr < 0xc00d6d60) {
sample = 2; // mid bucket
} else if (hr <= 0xc00d6d78) {
sample = hr & 0xffU; // MF_E_TRANSFORM_*
} else {
sample = 3; // high bucket
}
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction(
[sample] {
Telemetry::Accumulate(Telemetry::MEDIA_WMF_DECODE_ERROR, sample);
});
NS_DispatchToMainThread(runnable);
}
示例6: MOZ_ASSERT
/* static */ void
IDecodingTask::NotifyDecodeComplete(NotNull<RasterImage*> aImage,
NotNull<Decoder*> aDecoder)
{
MOZ_ASSERT(aDecoder->HasError() || !aDecoder->InFrame(),
"Decode complete in the middle of a frame?");
// Capture the decoder's state.
DecoderFinalStatus finalStatus = aDecoder->FinalStatus();
ImageMetadata metadata = aDecoder->GetImageMetadata();
DecoderTelemetry telemetry = aDecoder->Telemetry();
Progress progress = aDecoder->TakeProgress();
IntRect invalidRect = aDecoder->TakeInvalidRect();
Maybe<uint32_t> frameCount = aDecoder->TakeCompleteFrameCount();
SurfaceFlags surfaceFlags = aDecoder->GetSurfaceFlags();
// Synchronously notify if we can.
if (NS_IsMainThread() &&
!(aDecoder->GetDecoderFlags() & DecoderFlags::ASYNC_NOTIFY)) {
aImage->NotifyDecodeComplete(finalStatus, metadata, telemetry, progress,
invalidRect, frameCount, surfaceFlags);
return;
}
// We're forced to notify asynchronously.
NotNull<RefPtr<RasterImage>> image = aImage;
NS_DispatchToMainThread(NS_NewRunnableFunction([=]() -> void {
image->NotifyDecodeComplete(finalStatus, metadata, telemetry, progress,
invalidRect, frameCount, surfaceFlags);
}));
}
示例7: EmptyString
/*static*/
void
SmsManager::NotifySmsReceived(int32_t aId,
jni::String::Param aSender,
jni::String::Param aBody,
int32_t aMessageClass,
int64_t aSentTimestamp,
int64_t aTimestamp)
{
// TODO Need to correct the message `threadId` parameter value. Bug 859098
SmsMessageData message;
message.id() = aId;
message.threadId() = 0;
message.iccId() = EmptyString();
message.delivery() = eDeliveryState_Received;
message.deliveryStatus() = eDeliveryStatus_Success;
message.sender() = aSender ? aSender->ToString() : EmptyString();
message.receiver() = EmptyString();
message.body() = aBody ? aBody->ToString() : EmptyString();
message.messageClass() = static_cast<MessageClass>(aMessageClass);
message.timestamp() = aTimestamp;
message.sentTimestamp() = aSentTimestamp;
message.deliveryTimestamp() = aTimestamp;
message.read() = false;
nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction([=] () {
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (!obs) {
return;
}
nsCOMPtr<nsISmsMessage> domMessage = new SmsMessageInternal(message);
obs->NotifyObservers(domMessage, kSmsReceivedObserverTopic, nullptr);
});
NS_DispatchToMainThread(runnable);
}
示例8: do_QueryInterface
already_AddRefed<Promise>
PresentationReceiver::GetConnectionList(ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mOwner);
if (NS_WARN_IF(!global)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
if (!mGetConnectionListPromise) {
mGetConnectionListPromise = Promise::Create(global, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
RefPtr<PresentationReceiver> self = this;
nsresult rv =
NS_DispatchToMainThread(NS_NewRunnableFunction([self] () -> void {
self->CreateConnectionList();
}));
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
}
RefPtr<Promise> promise = mGetConnectionListPromise;
return promise.forget();
}
示例9: mon
void
PDMFactory::EnsureInit() const
{
{
StaticMutexAutoLock mon(sMonitor);
if (sInstance) {
// Quick exit if we already have an instance.
return;
}
if (NS_IsMainThread()) {
// On the main thread and holding the lock -> Create instance.
sInstance = new PDMFactoryImpl();
ClearOnShutdown(&sInstance);
return;
}
}
// Not on the main thread -> Sync-dispatch creation to main thread.
nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
nsCOMPtr<nsIRunnable> runnable =
NS_NewRunnableFunction([]() {
StaticMutexAutoLock mon(sMonitor);
if (!sInstance) {
sInstance = new PDMFactoryImpl();
ClearOnShutdown(&sInstance);
}
});
SyncRunnable::DispatchToThread(mainThread, runnable);
}
示例10: caps
void
GMPCDMCallbackProxy::BatchedKeyStatusChangedInternal(const nsCString& aSessionId,
const nsTArray<CDMKeyInfo>& aKeyInfos)
{
bool keyStatusesChange = false;
{
CDMCaps::AutoLock caps(mProxy->Capabilites());
for (size_t i = 0; i < aKeyInfos.Length(); i++) {
keyStatusesChange |=
caps.SetKeyStatus(aKeyInfos[i].mKeyId,
NS_ConvertUTF8toUTF16(aSessionId),
aKeyInfos[i].mStatus);
}
}
if (keyStatusesChange) {
RefPtr<CDMProxy> proxy = mProxy;
auto sid = NS_ConvertUTF8toUTF16(aSessionId);
NS_DispatchToMainThread(
NS_NewRunnableFunction([proxy, sid] ()
{
proxy->OnKeyStatusesChange(sid);
})
);
}
}
示例11: NotifyProgress
static void
NotifyProgress(NotNull<Decoder*> aDecoder)
{
MOZ_ASSERT(aDecoder->HasProgress() && !aDecoder->IsMetadataDecode());
Progress progress = aDecoder->TakeProgress();
IntRect invalidRect = aDecoder->TakeInvalidRect();
Maybe<uint32_t> frameCount = aDecoder->TakeCompleteFrameCount();
SurfaceFlags surfaceFlags = aDecoder->GetSurfaceFlags();
// Synchronously notify if we can.
if (NS_IsMainThread() &&
!(aDecoder->GetDecoderFlags() & DecoderFlags::ASYNC_NOTIFY)) {
aDecoder->GetImage()->NotifyProgress(progress, invalidRect,
frameCount, surfaceFlags);
return;
}
// We're forced to notify asynchronously.
NotNull<RefPtr<Decoder>> decoder = aDecoder;
NS_DispatchToMainThread(NS_NewRunnableFunction([=]() -> void {
decoder->GetImage()->NotifyProgress(progress, invalidRect,
frameCount, surfaceFlags);
}));
}
示例12: PLAY_REQUEST_LOG
RefPtr<GenericPromise>
AutoplayRequest::RequestWithPrompt()
{
// If we've already requested permission, we'll just return the promise,
// as we don't want to show multiple permission requests at once.
// The promise is non-exclusive, so if the request has already completed,
// the ThenValue will run immediately.
if (mRequestDispatched) {
PLAY_REQUEST_LOG(
"AutoplayRequest %p RequestWithPrompt() request already dispatched",
this);
return mPromiseHolder.Ensure(__func__);
}
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryReferent(mWindow);
if (!window) {
return GenericPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR,
__func__);
}
nsCOMPtr<nsIContentPermissionRequest> request = do_QueryInterface(this);
MOZ_RELEASE_ASSERT(request);
nsCOMPtr<nsIRunnable> f = NS_NewRunnableFunction(
"AutoplayRequest::RequestWithPrompt", [window, request]() {
dom::nsContentPermissionUtils::AskPermission(request, window);
});
mMainThreadTarget->Dispatch(f, NS_DISPATCH_NORMAL);
mRequestDispatched = true;
return mPromiseHolder.Ensure(__func__);
}
示例13: AddDataEntry
void
URL::CreateObjectURL(const GlobalObject& aGlobal, MediaSource& aSource,
const objectURLOptions& aOptions,
nsAString& aResult,
ErrorResult& aError)
{
nsCOMPtr<nsIPrincipal> principal = nsContentUtils::ObjectPrincipal(aGlobal.Get());
nsCString url;
nsresult rv = nsHostObjectProtocolHandler::
AddDataEntry(NS_LITERAL_CSTRING(MEDIASOURCEURI_SCHEME),
&aSource, principal, url);
if (NS_FAILED(rv)) {
aError.Throw(rv);
return;
}
nsCOMPtr<nsIRunnable> revocation = NS_NewRunnableFunction(
[url] {
nsHostObjectProtocolHandler::RemoveDataEntry(url);
});
nsContentUtils::RunInStableState(revocation.forget());
CopyASCIItoUTF16(url, aResult);
}
示例14: MOZ_ASSERT
void BenchmarkPlayback::DemuxNextSample() {
MOZ_ASSERT(OnThread());
RefPtr<Benchmark> ref(mGlobalState);
RefPtr<MediaTrackDemuxer::SamplesPromise> promise =
mTrackDemuxer->GetSamples();
promise->Then(
Thread(), __func__,
[this, ref](RefPtr<MediaTrackDemuxer::SamplesHolder> aHolder) {
mSamples.AppendElements(std::move(aHolder->mSamples));
if (ref->mParameters.mStopAtFrame &&
mSamples.Length() == ref->mParameters.mStopAtFrame.ref()) {
InitDecoder(std::move(*mTrackDemuxer->GetInfo()));
} else {
Dispatch(
NS_NewRunnableFunction("BenchmarkPlayback::DemuxNextSample",
[this, ref]() { DemuxNextSample(); }));
}
},
[this, ref](const MediaResult& aError) {
switch (aError.Code()) {
case NS_ERROR_DOM_MEDIA_END_OF_STREAM:
InitDecoder(std::move(*mTrackDemuxer->GetInfo()));
break;
default:
Error(aError);
break;
}
});
}
示例15: ReportFailureOnMainThread
void
MediaDecodeTask::OnMetadataRead(MetadataHolder* aMetadata)
{
mMediaInfo = aMetadata->mInfo;
if (!mMediaInfo.HasAudio()) {
mDecoderReader->Shutdown();
ReportFailureOnMainThread(WebAudioDecodeJob::NoAudio);
return;
}
nsCString codec;
if (!mMediaInfo.mAudio.GetAsAudioInfo()->mMimeType.IsEmpty()) {
codec = nsPrintfCString("webaudio; %s", mMediaInfo.mAudio.GetAsAudioInfo()->mMimeType.get());
} else {
codec = nsPrintfCString("webaudio;resource; %s", mContentType.get());
}
nsCOMPtr<nsIRunnable> task = NS_NewRunnableFunction([codec]() -> void {
MOZ_ASSERT(!codec.IsEmpty());
MOZ_LOG(gMediaDecoderLog,
LogLevel::Debug,
("Telemetry (WebAudio) MEDIA_CODEC_USED= '%s'", codec.get()));
Telemetry::Accumulate(Telemetry::ID::MEDIA_CODEC_USED, codec);
});
AbstractThread::MainThread()->Dispatch(task.forget());
RequestSample();
}