void RilConsumer::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage) { MOZ_ASSERT(NS_IsMainThread()); nsRefPtr<DispatchRILEvent> dre(new DispatchRILEvent(aMessage.forget())); mDispatcher->PostTask(dre); }
PLDHashOperator FreeObserverFunc(PrefCallback *aKey, nsAutoPtr<PrefCallback> &aCallback, void *aArgs) { // Calling NS_RELEASE below might trigger a call to // nsPrefBranch::RemoveObserver, since some classes remove themselves from // the pref branch on destruction. We don't need to worry about this causing // double-frees, however, because freeObserverList sets mFreeingObserverList // to true, which prevents RemoveObserver calls from doing anything. nsPrefBranch *prefBranch = aCallback->GetPrefBranch(); const char *pref = prefBranch->getPrefName(aCallback->GetDomain().get()); PREF_UnregisterCallback(pref, nsPrefBranch::NotifyObserver, aCallback); return PL_DHASH_REMOVE; }
void nsCSSSelectorList::AddSelector(nsAutoPtr<nsCSSSelector>& aSelector) { // prepend to list nsCSSSelector* newSel = aSelector.forget(); if (newSel) { newSel->mNext = mSelectors; mSelectors = newSel; } }
NS_IMETHODIMP nsUrlClassifierDBServiceWorker::CacheCompletions(CacheResultArray *results) { LOG(("nsUrlClassifierDBServiceWorker::CacheCompletions [%p]", this)); if (!mClassifier) return NS_OK; // Ownership is transferred in to us nsAutoPtr<CacheResultArray> resultsPtr(results); nsAutoPtr<ProtocolParser> pParse(new ProtocolParser(mHashKey)); nsTArray<TableUpdate*> updates; // Only cache results for tables that we have, don't take // in tables we might accidentally have hit during a completion. // This happens due to goog vs googpub lists existing. nsTArray<nsCString> tables; nsresult rv = mClassifier->ActiveTables(tables); NS_ENSURE_SUCCESS(rv, rv); for (PRUint32 i = 0; i < resultsPtr->Length(); i++) { bool activeTable = false; for (PRUint32 table = 0; table < tables.Length(); table++) { if (tables[table].Equals(resultsPtr->ElementAt(i).table)) { activeTable = true; } } if (activeTable) { TableUpdate * tu = pParse->GetTableUpdate(resultsPtr->ElementAt(i).table); LOG(("CacheCompletion Addchunk %d hash %X", resultsPtr->ElementAt(i).entry.addChunk, resultsPtr->ElementAt(i).entry.hash.prefix)); tu->NewAddComplete(resultsPtr->ElementAt(i).entry.addChunk, resultsPtr->ElementAt(i).entry.hash.complete); tu->NewAddChunk(resultsPtr->ElementAt(i).entry.addChunk); tu->SetLocalUpdate(); updates.AppendElement(tu); pParse->ForgetTableUpdates(); } else { LOG(("Completion received, but table is not active, so not caching.")); } } mClassifier->ApplyUpdates(&updates); return NS_OK; }
void UnixSocketImpl::Connect() { if(mFd.get() < 0) { mFd = mConnector->Create(); if (mFd.get() < 0) { return; } } int ret; socklen_t addr_sz; struct sockaddr addr; mConnector->CreateAddr(false, addr_sz, &addr, mAddress.get()); ret = connect(mFd.get(), &addr, addr_sz); if (ret) { #if DEBUG LOG("Socket connect errno=%d\n", errno); #endif mFd.reset(-1); nsRefPtr<OnSocketEventTask> t = new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR); NS_DispatchToMainThread(t); return; } if (!mConnector->SetUp(mFd)) { NS_WARNING("Could not set up socket!"); return; } nsRefPtr<OnSocketEventTask> t = new OnSocketEventTask(this, OnSocketEventTask::CONNECT_SUCCESS); NS_DispatchToMainThread(t); // Due to the fact that we've dispatched our OnConnectSuccess message before // starting reading, we're guaranteed that any subsequent read tasks will // happen after the object has been notified of a successful connect. XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new StartImplReadingTask(this)); }
void UnixSocketImpl::Accept() { MOZ_ASSERT(!NS_IsMainThread()); if (!mConnector) { NS_WARNING("No connector object available!"); return; } // This will set things we don't particularly care about, but it will hand // back the correct structure size which is what we do care about. if (!mConnector->CreateAddr(true, mAddrSize, mAddr, nullptr)) { NS_WARNING("Cannot create socket address!"); return; } if (mFd.get() < 0) { mFd = mConnector->Create(); if (mFd.get() < 0) { return; } if (!SetSocketFlags()) { return; } if (bind(mFd.get(), (struct sockaddr*)&mAddr, mAddrSize)) { #ifdef DEBUG LOG("...bind(%d) gave errno %d", mFd.get(), errno); #endif return; } if (listen(mFd.get(), 1)) { #ifdef DEBUG LOG("...listen(%d) gave errno %d", mFd.get(), errno); #endif return; } } SetUpIO(); }
status_t RtspMediaSource::read(MediaBuffer** out, const ReadOptions* options) { ReentrantMonitorAutoEnter mon(mMonitor); NS_ENSURE_TRUE(mIsStarted, MEDIA_ERROR_BASE); NS_ENSURE_TRUE(out, MEDIA_ERROR_BASE); *out = nullptr; // Video/audio track's initial frame size is FRAME_DEFAULT_SIZE. // We need to realloc the mBuffer if the mBuffer doesn't have enough space // for next ReadFrameFromTrack function. (actualFrameSize > mFrameMaxSize) status_t err; uint32_t readCount; uint32_t actualFrameSize; uint64_t time; nsresult rv; while (1) { err = mGroup->acquire_buffer(&mBuffer); NS_ENSURE_TRUE(err == OK, err); rv = mRtspResource->ReadFrameFromTrack((uint8_t *)mBuffer->data(), mFrameMaxSize, mTrackIdx, readCount, time, actualFrameSize); if (NS_FAILED(rv)) { // Release mGroup and mBuffer. stop(); // Since RtspMediaSource is an implementation of Android media source, // it's held by OMXCodec and isn't released yet. So we have to re-construct // mGroup and mBuffer. start(); NS_WARNING("ReadFrameFromTrack failed; releasing buffers and returning."); return ERROR_END_OF_STREAM; } if (actualFrameSize > mFrameMaxSize) { // release mGroup and mBuffer stop(); // re-construct mGroup and mBuffer mFrameMaxSize = actualFrameSize; err = start(); NS_ENSURE_TRUE(err == OK, err); } else { // ReadFrameFromTrack success, break the while loop. break; } } mBuffer->set_range(0, readCount); if (NS_SUCCEEDED(rv)) { mBuffer->meta_data()->clear(); // fill the meta data mBuffer->meta_data()->setInt64(kKeyTime, time); *out = mBuffer; mBuffer = nullptr; return OK; } return ERROR_END_OF_STREAM; }
static void OnGetLogging_m( nsMainThreadPtrHandle<WebrtcGlobalLoggingCallback> aLoggingCallback, const std::string& aPattern, nsAutoPtr<std::deque<std::string>> aLogList) { ErrorResult rv; if (!aLogList->empty()) { Sequence<nsString> nsLogs; for (auto l = aLogList->begin(); l != aLogList->end(); ++l) { nsLogs.AppendElement(NS_ConvertUTF8toUTF16(l->c_str())); } aLoggingCallback.get()->Call(nsLogs, rv); } if (rv.Failed()) { CSFLogError(logTag, "Error firing logging observer callback"); } }
void RegisterUeventListener(IUeventObserver *aObserver) { MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); if (!sPoller) InitializeUevent(); sPoller->RegisterObserver(aObserver); }
/* static */ PLDHashOperator nsPreflightCache::RemoveExpiredEntries(const nsACString& aKey, nsAutoPtr<CacheEntry>& aValue, void* aUserData) { TimeStamp* now = static_cast<TimeStamp*>(aUserData); aValue->PurgeExpired(*now); if (aValue->mHeaders.IsEmpty() && aValue->mMethods.IsEmpty()) { // Expired, remove from the list as well as the hash table. aValue->removeFrom(sPreflightCache->mList); return PL_DHASH_REMOVE; } return PL_DHASH_NEXT; }
void ListenSocketIO::GetSocketAddr(nsAString& aAddrStr) const { if (!mConnector) { NS_WARNING("No connector to get socket address from!"); aAddrStr.Truncate(); return; } mConnector->GetSocketAddr(mAddr, aAddrStr); }
static size_t SizeOfCategoryManagerTableEntryExcludingThis(nsDepCharHashKey::KeyType aKey, const nsAutoPtr<CategoryNode> &aData, MallocSizeOf aMallocSizeOf, void* aUserArg) { // We don't measure the string pointed to by aKey because it's a non-owning // pointer. return aData.get()->SizeOfExcludingThis(aMallocSizeOf); }
nsresult UnregisterBluetoothEventHandler(const nsCString& aNodeName, BluetoothEventObserver* aHandler) { MOZ_ASSERT(NS_IsMainThread()); BluetoothEventObserverList *ol; NS_ENSURE_TRUE(sBluetoothEventObserverTable, NS_ERROR_FAILURE); if (!sBluetoothEventObserverTable->Get(aNodeName, &ol)) { NS_WARNING("Node does not exist to remove BluetoothEventListener from!"); return NS_ERROR_FAILURE; } sBluetoothEventObserverTable->Get(aNodeName, &ol); ol->RemoveObserver(aHandler); if (ol->Length() == 0) { sBluetoothEventObserverTable->Remove(aNodeName); } return NS_OK; }
// Demux the call event to the right PeerConnection static void onCallEvent_m(nsAutoPtr<std::string> peerconnection, ccapi_call_event_e aCallEvent, CSF::CC_CallInfoPtr aInfo) { CSFLogDebug(logTag, "onCallEvent()"); PeerConnectionWrapper pc(peerconnection->c_str()); if (!pc.impl()) // This must be an event on a dead PC. Ignore return; CSFLogDebug(logTag, "Calling PC"); pc.impl()->onCallEvent(OnCallEventArgs(aCallEvent, aInfo)); }
void ListenSocketIO::Listen(ConnectionOrientedSocketIO* aCOSocketIO) { MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop()); MOZ_ASSERT(mConnector); MOZ_ASSERT(aCOSocketIO); if (!IsOpen()) { int fd = mConnector->Create(); if (fd < 0) { NS_WARNING("Cannot create socket fd!"); FireSocketError(); return; } if (!SetSocketFlags(fd)) { NS_WARNING("Cannot set socket flags!"); FireSocketError(); return; } if (!mConnector->SetUpListenSocket(GetFd())) { NS_WARNING("Could not set up listen socket!"); FireSocketError(); return; } // This will set things we don't particularly care about, but // it will hand back the correct structure size which is what // we do care about. if (!mConnector->CreateAddr(true, mAddrSize, mAddr, nullptr)) { NS_WARNING("Cannot create socket address!"); FireSocketError(); return; } SetFd(fd); } mCOSocketIO = aCOSocketIO; // calls OnListening on success, or OnError otherwise nsresult rv = UnixSocketWatcher::Listen( reinterpret_cast<struct sockaddr*>(&mAddr), mAddrSize); NS_WARN_IF(NS_FAILED(rv)); }
/*static*/ PLDHashOperator CompositorChild::RemoveSharedMetricsForLayersId(const uint64_t& aKey, nsAutoPtr<SharedFrameMetricsData>& aData, void* aLayerTransactionChild) { uint64_t childId = static_cast<LayerTransactionChild*>(aLayerTransactionChild)->GetId(); if (aData->GetLayersId() == childId) { return PLDHashOperator::PL_DHASH_REMOVE; } return PLDHashOperator::PL_DHASH_NEXT; }
PLDHashOperator SpdyStream::hdrHashEnumerate(const nsACString &key, nsAutoPtr<nsCString> &value, void *closure) { SpdyStream *self = static_cast<SpdyStream *>(closure); self->CompressToFrame(key); self->CompressToFrame(value.get()); return PL_DHASH_NEXT; }
nsresult RilSocketIO::QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer) { MOZ_ASSERT(aBuffer); if (!mBuffer) { mBuffer = new UnixSocketRawData(MAX_READ_SIZE); } *aBuffer = mBuffer.get(); return NS_OK; }
/** * Updating the database: * * The Update() method takes a series of chunks separated with control data, * as described in * http://code.google.com/p/google-safe-browsing/wiki/Protocolv2Spec * * It will iterate through the control data until it reaches a chunk. By * the time it reaches a chunk, it should have received * a) the table to which this chunk applies * b) the type of chunk (add, delete, expire add, expire delete). * c) the chunk ID * d) the length of the chunk. * * For add and subtract chunks, it needs to read the chunk data (expires * don't have any data). Chunk data is a list of URI fragments whose * encoding depends on the type of table (which is indicated by the end * of the table name): * a) tables ending with -exp are a zlib-compressed list of URI fragments * separated by newlines. * b) tables ending with -sha128 have the form * [domain][N][frag0]...[fragN] * 16 1 16 16 * If N is 0, the domain is reused as a fragment. * c) any other tables are assumed to be a plaintext list of URI fragments * separated by newlines. * * Update() can be fed partial data; It will accumulate data until there is * enough to act on. Finish() should be called when there will be no more * data. */ NS_IMETHODIMP nsUrlClassifierDBServiceWorker::UpdateStream(const nsACString& chunk) { if (gShuttingDownThread) return NS_ERROR_NOT_INITIALIZED; NS_ENSURE_STATE(mInStream); HandlePendingLookups(); return mProtocolParser->AppendStream(chunk); }
NS_IMETHODIMP nsUrlClassifierLookupCallback::Completion(const nsACString& completeHash, const nsACString& tableName, PRUint32 chunkId, bool verified) { LOG(("nsUrlClassifierLookupCallback::Completion [%p, %s, %d, %d]", this, PromiseFlatCString(tableName).get(), chunkId, verified)); mozilla::safebrowsing::Completion hash; hash.Assign(completeHash); // Send this completion to the store for caching. if (!mCacheResults) { mCacheResults = new CacheResultArray(); if (!mCacheResults) return NS_ERROR_OUT_OF_MEMORY; } if (verified) { CacheResult result; result.entry.addChunk = chunkId; result.entry.hash.complete = hash; result.table = tableName; // OK if this fails, we just won't cache the item. mCacheResults->AppendElement(result); } // Check if this matched any of our results. for (PRUint32 i = 0; i < mResults->Length(); i++) { LookupResult& result = mResults->ElementAt(i); // Now, see if it verifies a lookup if (result.CompleteHash() == hash && result.mTableName.Equals(tableName)) { result.mProtocolConfirmed = true; } } return NS_OK; }
// Allows the main thread to delete the connection which may be in // a background thread. // XXX This could be turned into a single shutdown event so the logic // is simpler in nsUrlClassifierDBService::Shutdown. NS_IMETHODIMP nsUrlClassifierDBServiceWorker::CloseDb() { if (mClassifier) { mClassifier->Close(); mClassifier = nsnull; } mCryptoHash = nsnull; LOG(("urlclassifier db closed\n")); return NS_OK; }
nsresult DaemonSocketIO::QueryReceiveBuffer(UnixSocketIOBuffer** aBuffer) { MOZ_ASSERT(aBuffer); if (!mPDU) { /* There's only one PDU for receiving. We reuse it every time. */ mPDU = new DaemonSocketPDU(DaemonSocketPDU::MAX_PAYLOAD_LENGTH); } *aBuffer = mPDU.get(); return NS_OK; }
nsresult StopBluetoothConnection() { if (!sDBusConnection) { NS_WARNING("DBusConnection does not exist, nothing to stop, skipping."); return NS_OK; } dbus_connection_remove_filter(sDBusConnection->mConnection, EventFilter, NULL); sDBusConnection = NULL; sBluetoothEventObserverTable->Clear(); sBluetoothEventObserverTable = NULL; return NS_OK; }
NS_IMETHODIMP nsUrlClassifierDBServiceWorker::BeginStream(const nsACString &table, const nsACString &serverMAC) { LOG(("nsUrlClassifierDBServiceWorker::BeginStream")); if (gShuttingDownThread) return NS_ERROR_NOT_INITIALIZED; NS_ENSURE_STATE(mUpdateObserver); NS_ENSURE_STATE(!mInStream); mInStream = true; NS_ASSERTION(!mProtocolParser, "Should not have a protocol parser."); mProtocolParser = new ProtocolParser(mHashKey); if (!mProtocolParser) return NS_ERROR_OUT_OF_MEMORY; mProtocolParser->Init(mCryptoHash); nsresult rv; // If we're expecting a MAC, create the nsICryptoHMAC component now. if (!mUpdateClientKey.IsEmpty()) { LOG(("Expecting MAC in this stream")); rv = mProtocolParser->InitHMAC(mUpdateClientKey, serverMAC); NS_ENSURE_SUCCESS(rv, rv); } else { LOG(("No MAC in this stream")); } if (!table.IsEmpty()) { mProtocolParser->SetCurrentTable(table); } return NS_OK; }
NS_IMETHODIMP nsUrlClassifierDBServiceWorker::ResetDatabase() { nsresult rv = OpenDb(); NS_ENSURE_SUCCESS(rv, rv); mClassifier->Reset(); rv = CloseDb(); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }
nsresult StartBluetoothConnection() { if (sDBusConnection) { NS_WARNING("DBusConnection already established, skipping"); return NS_OK; } sBluetoothEventObserverTable = new BluetoothEventObserverTable(); sBluetoothEventObserverTable->Init(100); sDBusConnection = new RawDBusConnection(); sDBusConnection->EstablishDBusConnection(); // Add a filter for all incoming messages_base if (!dbus_connection_add_filter(sDBusConnection->mConnection, EventFilter, NULL, NULL)) { NS_WARNING("Cannot create DBus Event Filter for DBus Thread!"); return NS_ERROR_FAILURE; } return NS_OK; }
status_t RtspMediaSource::start(MetaData* params) { ReentrantMonitorAutoEnter mon(mMonitor); if (!mIsStarted) { // RtspMediaSource relinquish the ownership of MediaBuffer |buf| to mGroup. mGroup = new MediaBufferGroup(); MediaBuffer* buf = new MediaBuffer(mFrameMaxSize); mGroup->add_buffer(buf); mIsStarted = true; } return OK; }
void MediaDecoder::MetadataLoaded(nsAutoPtr<MediaInfo> aInfo, nsAutoPtr<MetadataTags> aTags, MediaDecoderEventVisibility aEventVisibility) { MOZ_ASSERT(NS_IsMainThread()); if (mShuttingDown) { return; } DECODER_LOG("MetadataLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d", aInfo->mAudio.mChannels, aInfo->mAudio.mRate, aInfo->HasAudio(), aInfo->HasVideo()); { ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); mDuration = mDecoderStateMachine ? mDecoderStateMachine->GetDuration() : -1; // Duration has changed so we should recompute playback rate UpdatePlaybackRate(); } if (mDuration == -1) { SetInfinite(true); } mInfo = aInfo.forget(); ConstructMediaTracks(); if (mOwner) { // Make sure the element and the frame (if any) are told about // our new size. Invalidate(); if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) { mOwner->MetadataLoaded(mInfo, nsAutoPtr<const MetadataTags>(aTags.forget())); } } }
void MediaDecoder::FirstFrameLoaded(nsAutoPtr<MediaInfo> aInfo, MediaDecoderEventVisibility aEventVisibility) { MOZ_ASSERT(NS_IsMainThread()); if (mShuttingDown) { return; } DECODER_LOG("FirstFrameLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d mPlayState=%s mIsDormant=%d", aInfo->mAudio.mChannels, aInfo->mAudio.mRate, aInfo->HasAudio(), aInfo->HasVideo(), PlayStateStr(), mIsDormant); mInfo = aInfo.forget(); if (mOwner) { Invalidate(); if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) { mOwner->FirstFrameLoaded(); } } // This can run cache callbacks. mResource->EnsureCacheUpToDate(); // The element can run javascript via events // before reaching here, so only change the // state if we're still set to the original // loading state. if (mPlayState == PLAY_STATE_LOADING && !mIsDormant) { ChangeState(mNextState); } // Run NotifySuspendedStatusChanged now to give us a chance to notice // that autoplay should run. NotifySuspendedStatusChanged(); }
void MediaDecoder::FirstFrameLoaded(nsAutoPtr<MediaInfo> aInfo, MediaDecoderEventVisibility aEventVisibility) { MOZ_ASSERT(NS_IsMainThread()); MOZ_DIAGNOSTIC_ASSERT(!IsShutdown()); DECODER_LOG("FirstFrameLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d mPlayState=%s", aInfo->mAudio.mChannels, aInfo->mAudio.mRate, aInfo->HasAudio(), aInfo->HasVideo(), PlayStateStr()); mInfo = aInfo.forget(); Invalidate(); // This can run cache callbacks. mResource->EnsureCacheUpToDate(); // The element can run javascript via events // before reaching here, so only change the // state if we're still set to the original // loading state. if (mPlayState == PLAY_STATE_LOADING) { ChangeState(mNextState); } // Run NotifySuspendedStatusChanged now to give us a chance to notice // that autoplay should run. NotifySuspendedStatusChanged(); // mOwner->FirstFrameLoaded() might call us back. Put it at the bottom of // this function to avoid unexpected shutdown from reentrant calls. if (aEventVisibility != MediaDecoderEventVisibility::Suppressed) { mOwner->FirstFrameLoaded(); } }