本文整理汇总了C++中NS_DispatchToMainThread函数的典型用法代码示例。如果您正苦于以下问题:C++ NS_DispatchToMainThread函数的具体用法?C++ NS_DispatchToMainThread怎么用?C++ NS_DispatchToMainThread使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NS_DispatchToMainThread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NS_ERROR
nsresult
nsMemoryImpl::FlushMemory(const PRUnichar* aReason, bool aImmediate)
{
nsresult rv = NS_OK;
if (aImmediate) {
// They've asked us to run the flusher *immediately*. We've
// got to be on the UI main thread for us to be able to do
// that...are we?
if (!NS_IsMainThread()) {
NS_ERROR("can't synchronously flush memory: not on UI thread");
return NS_ERROR_FAILURE;
}
}
int32_t lastVal = sIsFlushing.exchange(1);
if (lastVal)
return NS_OK;
PRIntervalTime now = PR_IntervalNow();
// Run the flushers immediately if we can; otherwise, proxy to the
// UI thread an run 'em asynchronously.
if (aImmediate) {
rv = RunFlushers(aReason);
}
else {
// Don't broadcast more than once every 1000ms to avoid being noisy
if (PR_IntervalToMicroseconds(now - sLastFlushTime) > 1000) {
sFlushEvent.mReason = aReason;
rv = NS_DispatchToMainThread(&sFlushEvent, NS_DISPATCH_NORMAL);
}
}
sLastFlushTime = now;
return rv;
}
示例2: LOG
nsresult
MediaEngineWebRTCVideoSource::Stop(SourceMediaStream *aSource, TrackID aID)
{
LOG((__FUNCTION__));
if (!mSources.RemoveElement(aSource)) {
// Already stopped - this is allowed
return NS_OK;
}
if (!mSources.IsEmpty()) {
return NS_OK;
}
#ifdef MOZ_B2G_CAMERA
ReentrantMonitorAutoEnter sync(mCallbackMonitor);
#endif
if (mState != kStarted) {
return NS_ERROR_FAILURE;
}
{
MonitorAutoLock lock(mMonitor);
mState = kStopped;
aSource->EndTrack(aID);
// Drop any cached image so we don't start with a stale image on next
// usage
mImage = nullptr;
}
#ifdef MOZ_B2G_CAMERA
NS_DispatchToMainThread(WrapRunnable(this,
&MediaEngineWebRTCVideoSource::StopImpl));
#else
mViERender->StopRender(mCaptureIndex);
mViERender->RemoveRenderer(mCaptureIndex);
mViECapture->StopCapture(mCaptureIndex);
#endif
return NS_OK;
}
示例3: Run
NS_IMETHOD
Run()
{
NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
mManager = MediaManager::Get();
// Was a backend provided?
if (!mBackendChosen) {
mBackend = mManager->GetBackend();
}
// Was a device provided?
if (!mDeviceChosen) {
nsresult rv = SelectDevice();
if (rv != NS_OK) {
return rv;
}
}
// It is an error if audio or video are requested along with picture.
if (mPicture && (mAudio || mVideo)) {
NS_DispatchToMainThread(new ErrorCallbackRunnable(
mSuccess, mError, NS_LITERAL_STRING("NOT_SUPPORTED_ERR"), mWindowID
));
return NS_OK;
}
if (mPicture) {
ProcessGetUserMediaSnapshot(mVideoDevice->GetSource(), 0);
return NS_OK;
}
ProcessGetUserMedia(mAudio ? mAudioDevice->GetSource() : nullptr,
mVideo ? mVideoDevice->GetSource() : nullptr);
return NS_OK;
}
示例4: AsyncDispatchHelper
/* boolean dispatchEvent (in sbIMediacoreEvent aEvent, [optional] PRBool aAsync); */
nsresult
sbBaseMediacoreEventTarget::DispatchEvent(sbIMediacoreEvent *aEvent,
PRBool aAsync,
PRBool* _retval)
{
nsresult rv;
// Note: in the async case, we need to make a new runnable, because
// DispatchEvent has an out param, and XPCOM proxies can't deal with that.
if (aAsync) {
nsRefPtr<AsyncDispatchHelper> dispatchHelper =
new AsyncDispatchHelper(static_cast<sbIMediacoreEventTarget*>(mTarget), aEvent);
NS_ENSURE_TRUE(dispatchHelper, NS_ERROR_OUT_OF_MEMORY);
rv = NS_DispatchToMainThread(dispatchHelper, NS_DISPATCH_NORMAL);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
if (!NS_IsMainThread()) {
// we need to proxy to the main thread
nsCOMPtr<sbIMediacoreEventTarget> proxiedSelf;
{ /* scope the monitor */
NS_ENSURE_TRUE(mMonitor, NS_ERROR_NOT_INITIALIZED);
nsAutoMonitor mon(mMonitor);
rv = do_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
NS_GET_IID(sbIMediacoreEventTarget),
mTarget,
NS_PROXY_SYNC | NS_PROXY_ALWAYS,
getter_AddRefs(proxiedSelf));
NS_ENSURE_SUCCESS(rv, rv);
}
// don't have a return value if dispatching asynchronously
// (since the variable is likely to be dead by that point)
return proxiedSelf->DispatchEvent(aEvent, PR_FALSE, _retval);
}
return DispatchEventInternal(aEvent, _retval);
}
示例5: NS_ERROR
bool
NuwaParent::RecvNotifyReady()
{
#ifdef MOZ_NUWA_PROCESS
if (!mContentParent || !mContentParent->IsNuwaProcess()) {
NS_ERROR("Received NotifyReady() message from a non-Nuwa process.");
return false;
}
// Creating a NonOwningRunnableMethod here is safe because refcount changes of
// mContentParent have to go the the main thread. The mContentParent will
// be alive when the runnable runs.
nsCOMPtr<nsIRunnable> runnable =
NS_NewNonOwningRunnableMethod(mContentParent.get(),
&ContentParent::OnNuwaReady);
MOZ_ASSERT(runnable);
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToMainThread(runnable)));
return true;
#else
NS_ERROR("NuwaParent::RecvNotifyReady() not implemented!");
return false;
#endif
}
示例6: LOG
NS_IMETHODIMP
_OldCacheLoad::OnCacheEntryAvailable(nsICacheEntryDescriptor *entry,
nsCacheAccessMode access,
nsresult status)
{
LOG(("_OldCacheLoad::OnCacheEntryAvailable [this=%p, ent=%p, cb=%p, appcache=%p, access=%x]",
this, entry, mCallback.get(), mAppCache.get(), access));
// XXX Bug 759805: Sometimes we will call this method directly from
// HttpCacheQuery::Run when AsyncOpenCacheEntry fails, but
// AsyncOpenCacheEntry will also call this method. As a workaround, we just
// ensure we only execute this code once.
NS_ENSURE_TRUE(mRunCount == 0, NS_ERROR_UNEXPECTED);
++mRunCount;
mCacheEntry = entry ? new _OldCacheEntryWrapper(entry) : nullptr;
mStatus = status;
mNew = access == nsICache::ACCESS_WRITE;
if (!mMainThreadOnly)
Check();
return NS_DispatchToMainThread(this);
}
示例7: LOG
nsresult
MediaEngineGonkVideoSource::Deallocate(AllocationHandle* aHandle)
{
LOG((__FUNCTION__));
AssertIsOnOwningThread();
MOZ_ASSERT(!aHandle);
bool empty;
{
MonitorAutoLock lock(mMonitor);
empty = mSources.IsEmpty();
}
if (empty) {
ReentrantMonitorAutoEnter sync(mCallbackMonitor);
if (mState != kStopped && mState != kAllocated) {
return NS_ERROR_FAILURE;
}
// We do not register success callback here
NS_DispatchToMainThread(WrapRunnable(RefPtr<MediaEngineGonkVideoSource>(this),
&MediaEngineGonkVideoSource::DeallocImpl));
mCallbackMonitor.Wait();
if (mState != kReleased) {
return NS_ERROR_FAILURE;
}
mState = kReleased;
LOG(("Video device %d deallocated", mCaptureIndex));
} else {
LOG(("Video device %d deallocated but still in use", mCaptureIndex));
}
return NS_OK;
}
示例8: PR_Now
int
VideoRenderer::DeliverFrame(unsigned char* buffer, int buffer_size, uint32_t time_stamp, int64_t render_time)
{
PRTime epoch_c = PR_Now();
PRFloat64 epoch = (PRFloat64)(epoch_c / MICROSECONDS);
epoch += ((PRFloat64)(epoch_c % MICROSECONDS)) / MICROSECONDS;
int fsize = width * height * 4;
if (vCanvas) {
/* Convert i420 to RGB32 to write on canvas */
nsAutoArrayPtr<PRUint8> rgb32(new PRUint8[fsize]);
I420toRGB32(width, height,
(const char *)buffer, (char *)rgb32.get()
);
nsCOMPtr<nsIRunnable> render = new CanvasRenderer(
vCanvas, width, height, rgb32, fsize
);
NS_DispatchToMainThread(render);
}
return 0;
}
示例9: MOZ_ASSERT
void
AudioContext::OnStateChanged(void* aPromise, AudioContextState aNewState)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT((mAudioContextState == AudioContextState::Suspended &&
aNewState == AudioContextState::Running) ||
(mAudioContextState == AudioContextState::Running &&
aNewState == AudioContextState::Suspended) ||
(mAudioContextState == AudioContextState::Running &&
aNewState == AudioContextState::Closed) ||
(mAudioContextState == AudioContextState::Suspended &&
aNewState == AudioContextState::Closed) ||
(mAudioContextState == aNewState),
"Invalid AudioContextState transition");
MOZ_ASSERT(
mIsOffline || aPromise || aNewState == AudioContextState::Running,
"We should have a promise here if this is a real-time AudioContext."
"Or this is the first time we switch to \"running\".");
if (aPromise) {
Promise* promise = reinterpret_cast<Promise*>(aPromise);
promise->MaybeResolve(JS::UndefinedHandleValue);
DebugOnly<bool> rv = mPromiseGripArray.RemoveElement(promise);
MOZ_ASSERT(rv, "Promise wasn't in the grip array?");
}
if (mAudioContextState != aNewState) {
nsRefPtr<OnStateChangeTask> onStateChangeTask =
new OnStateChangeTask(this);
NS_DispatchToMainThread(onStateChangeTask);
}
mAudioContextState = aNewState;
}
示例10: LOG
nsresult
MediaEngineGonkVideoSource::Stop(SourceMediaStream* aSource, TrackID aID)
{
LOG((__FUNCTION__));
{
MonitorAutoLock lock(mMonitor);
if (!mSources.RemoveElement(aSource)) {
// Already stopped - this is allowed
return NS_OK;
}
if (!mSources.IsEmpty()) {
return NS_OK;
}
}
ReentrantMonitorAutoEnter sync(mCallbackMonitor);
if (mState != kStarted) {
return NS_ERROR_FAILURE;
}
{
MonitorAutoLock lock(mMonitor);
mState = kStopped;
aSource->EndTrack(aID);
// Drop any cached image so we don't start with a stale image on next
// usage
mImage = nullptr;
}
NS_DispatchToMainThread(WrapRunnable(nsRefPtr<MediaEngineGonkVideoSource>(this),
&MediaEngineGonkVideoSource::StopImpl));
return NS_OK;
}
示例11: MOZ_ASSERT
void
CDMProxy::gmp_Init(uint32_t aPromiseId)
{
MOZ_ASSERT(IsOnGMPThread());
nsCOMPtr<mozIGeckoMediaPluginService> mps =
do_GetService("@mozilla.org/gecko-media-plugin-service;1");
if (!mps) {
RejectPromise(aPromiseId, NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
nsTArray<nsCString> tags;
tags.AppendElement(NS_ConvertUTF16toUTF8(mKeySystem));
nsresult rv = mps->GetGMPDecryptor(&tags, GetOrigin(), &mCDM);
if (NS_FAILED(rv) || !mCDM) {
RejectPromise(aPromiseId, NS_ERROR_DOM_INVALID_STATE_ERR);
} else {
mCallback = new CDMCallbackProxy(this);
mCDM->Init(mCallback);
nsRefPtr<nsIRunnable> task(NS_NewRunnableMethodWithArg<uint32_t>(this, &CDMProxy::OnCDMCreated, aPromiseId));
NS_DispatchToMainThread(task);
}
}
示例12: DispatchFailConnection
NS_IMETHODIMP
EventSource::OnStopRequest(nsIRequest *aRequest,
nsISupports *aContext,
nsresult aStatusCode)
{
mWaitingForOnStopRequest = false;
if (mReadyState == CLOSED) {
return NS_ERROR_ABORT;
}
if (NS_FAILED(aStatusCode)) {
DispatchFailConnection();
return aStatusCode;
}
nsresult rv;
nsresult healthOfRequestResult = CheckHealthOfRequestCallback(aRequest);
if (NS_SUCCEEDED(healthOfRequestResult) &&
mLastConvertionResult == NS_PARTIAL_MORE_INPUT) {
// we had an incomplete UTF8 char at the end of the stream
rv = ParseCharacter(REPLACEMENT_CHAR);
NS_ENSURE_SUCCESS(rv, rv);
}
ClearFields();
nsCOMPtr<nsIRunnable> event =
NS_NewRunnableMethod(this, &EventSource::ReestablishConnection);
NS_ENSURE_STATE(event);
rv = NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
NS_ENSURE_SUCCESS(rv, rv);
return healthOfRequestResult;
}
示例13: NS_DispatchToMainThread
void
ContentProcessController::DispatchToRepaintThread(already_AddRefed<Runnable> aTask)
{
NS_DispatchToMainThread(Move(aTask));
}
示例14: MOZ_ASSERT
template<class Super> bool
Parent<Super>::RecvGetOriginKey(const uint32_t& aRequestId,
const nsCString& aOrigin,
const bool& aPrivateBrowsing,
const bool& aPersist)
{
MOZ_ASSERT(NS_IsMainThread());
// First, get profile dir.
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIFile> profileDir;
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
getter_AddRefs(profileDir));
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
// Then over to stream-transport thread to do the actual file io.
// Stash a pledge to hold the answer and get an id for this request.
RefPtr<Pledge<nsCString>> p = new Pledge<nsCString>();
uint32_t id = mOutstandingPledges.Append(*p);
nsCOMPtr<nsIEventTarget> sts = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
MOZ_ASSERT(sts);
RefPtr<OriginKeyStore> store(mOriginKeyStore);
bool sameProcess = mSameProcess;
rv = sts->Dispatch(NewRunnableFrom([id, profileDir, store, sameProcess, aOrigin,
aPrivateBrowsing, aPersist]() -> nsresult {
MOZ_ASSERT(!NS_IsMainThread());
store->mOriginKeys.SetProfileDir(profileDir);
nsCString result;
if (aPrivateBrowsing) {
store->mPrivateBrowsingOriginKeys.GetOriginKey(aOrigin, result);
} else {
store->mOriginKeys.GetOriginKey(aOrigin, result, aPersist);
}
// Pass result back to main thread.
nsresult rv;
rv = NS_DispatchToMainThread(NewRunnableFrom([id, store, sameProcess,
result]() -> nsresult {
Parent* parent = GccGetSingleton<Super>(); // GetSingleton();
if (!parent) {
return NS_OK;
}
RefPtr<Pledge<nsCString>> p = parent->mOutstandingPledges.Remove(id);
if (!p) {
return NS_ERROR_UNEXPECTED;
}
p->Resolve(result);
return NS_OK;
}), NS_DISPATCH_NORMAL);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}), NS_DISPATCH_NORMAL);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
p->Then([aRequestId, sameProcess](const nsCString& aKey) mutable {
if (!sameProcess) {
if (!sIPCServingParent) {
return NS_OK;
}
Unused << sIPCServingParent->SendGetOriginKeyResponse(aRequestId, aKey);
} else {
RefPtr<MediaManager> mgr = MediaManager::GetInstance();
if (!mgr) {
return NS_OK;
}
RefPtr<Pledge<nsCString>> pledge =
mgr->mGetOriginKeyPledges.Remove(aRequestId);
if (pledge) {
pledge->Resolve(aKey);
}
}
return NS_OK;
});
return true;
}
示例15: MOZ_ASSERT
void
nsPicoService::Init()
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(!mInitialized);
if (!sPicoApi.Init()) {
NS_WARNING("Failed to initialize pico library");
return;
}
// Use environment variable, or default android/b2g path
nsAutoCString langPath(PR_GetEnv("PICO_LANG_PATH"));
if (langPath.IsEmpty()) {
langPath.AssignLiteral(GONK_PICO_LANG_PATH);
}
nsCOMPtr<nsIFile> voicesDir;
NS_NewNativeLocalFile(langPath, true, getter_AddRefs(voicesDir));
nsCOMPtr<nsISimpleEnumerator> dirIterator;
nsresult rv = voicesDir->GetDirectoryEntries(getter_AddRefs(dirIterator));
if (NS_FAILED(rv)) {
NS_WARNING(nsPrintfCString("Failed to get contents of directory: %s", langPath.get()).get());
return;
}
bool hasMoreElements = false;
rv = dirIterator->HasMoreElements(&hasMoreElements);
MOZ_ASSERT(NS_SUCCEEDED(rv));
MonitorAutoLock autoLock(mVoicesMonitor);
while (hasMoreElements && NS_SUCCEEDED(rv)) {
nsCOMPtr<nsISupports> supports;
rv = dirIterator->GetNext(getter_AddRefs(supports));
MOZ_ASSERT(NS_SUCCEEDED(rv));
nsCOMPtr<nsIFile> voiceFile = do_QueryInterface(supports);
MOZ_ASSERT(voiceFile);
nsAutoCString leafName;
voiceFile->GetNativeLeafName(leafName);
nsAutoString lang;
if (GetVoiceFileLanguage(leafName, lang)) {
nsAutoString uri;
uri.AssignLiteral("urn:moz-tts:pico:");
uri.Append(lang);
bool found = false;
PicoVoice* voice = mVoices.GetWeak(uri, &found);
if (!found) {
voice = new PicoVoice(lang);
mVoices.Put(uri, voice);
}
// Each voice consists of two lingware files: A language resource file,
// suffixed by _ta.bin, and a speaker resource file, suffixed by _sb.bin.
// We currently assume that there is a pair of files for each language.
if (StringEndsWith(leafName, NS_LITERAL_CSTRING("_ta.bin"))) {
rv = voiceFile->GetPersistentDescriptor(voice->mTaFile);
MOZ_ASSERT(NS_SUCCEEDED(rv));
} else if (StringEndsWith(leafName, NS_LITERAL_CSTRING("_sg.bin"))) {
rv = voiceFile->GetPersistentDescriptor(voice->mSgFile);
MOZ_ASSERT(NS_SUCCEEDED(rv));
}
}
rv = dirIterator->HasMoreElements(&hasMoreElements);
}
NS_DispatchToMainThread(NS_NewRunnableMethod(this, &nsPicoService::RegisterVoices));
}