bool nsJARProtocolHandler::RemoteOpenFileInProgress( nsIHashable *aRemoteFile, nsIRemoteOpenFileListener *aListener) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aRemoteFile); MOZ_ASSERT(aListener); if (IsMainProcess()) { MOZ_NOT_REACHED("Shouldn't be called in the main process!"); return false; } RemoteFileListenerArray *listeners; if (mRemoteFileListeners.Get(aRemoteFile, &listeners)) { listeners->AppendElement(aListener); return true; } // We deliberately don't put the listener in the new array since the first // load is handled differently. mRemoteFileListeners.Put(aRemoteFile, new RemoteFileListenerArray()); return false; }
void nsJARProtocolHandler::RemoteOpenFileComplete(nsIHashable *aRemoteFile, nsresult aStatus) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aRemoteFile); if (IsMainProcess()) { MOZ_NOT_REACHED("Shouldn't be called in the main process!"); return; } RemoteFileListenerArray *tempListeners; if (!mRemoteFileListeners.Get(aRemoteFile, &tempListeners)) { return; } // Save the listeners in a stack array. The call to Remove() below will // delete the tempListeners array. RemoteFileListenerArray listeners; tempListeners->SwapElements(listeners); mRemoteFileListeners.Remove(aRemoteFile); // Technically we must fail OnRemoteFileComplete() since OpenNSPRFileDesc() // won't succeed here. We've trained nsJARChannel to recognize // NS_ERROR_ALREADY_OPENED in this case as "proceed to JAR cache hit." nsresult status = NS_SUCCEEDED(aStatus) ? NS_ERROR_ALREADY_OPENED : aStatus; uint32_t count = listeners.Length(); for (uint32_t index = 0; index < count; index++) { listeners[index]->OnRemoteFileOpenComplete(status); } }
nsresult IndexedDatabaseManager::AsyncDeleteFile(FileManager* aFileManager, int64_t aFileId) { MOZ_ASSERT(IsMainProcess()); MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aFileManager); MOZ_ASSERT(aFileId > 0); MOZ_ASSERT(mDeleteTimer); nsresult rv = mDeleteTimer->Cancel(); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } rv = mDeleteTimer->InitWithCallback(this, kDeleteTimeoutMs, nsITimer::TYPE_ONE_SHOT); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } nsTArray<int64_t>* array; if (!mPendingDeleteInfos.Get(aFileManager, &array)) { array = new nsTArray<int64_t>(); mPendingDeleteInfos.Put(aFileManager, array); } array->AppendElement(aFileId); return NS_OK; }
nsresult IndexedDatabaseManager::FlushPendingFileDeletions() { MOZ_ASSERT(NS_IsMainThread()); if (NS_WARN_IF(!InTestingMode())) { return NS_ERROR_UNEXPECTED; } if (IsMainProcess()) { nsresult rv = mDeleteTimer->Cancel(); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } rv = Notify(mDeleteTimer); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } } else { PBackgroundChild* bgActor = BackgroundChild::GetForCurrentThread(); if (NS_WARN_IF(!bgActor)) { return NS_ERROR_FAILURE; } if (!bgActor->SendFlushPendingFileDeletions()) { return NS_ERROR_FAILURE; } } return NS_OK; }
NS_IMETHODIMP IndexedDatabaseManager::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData) { NS_ASSERTION(IsMainProcess(), "Wrong process!"); NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); if (!strcmp(aTopic, DISKSPACEWATCHER_OBSERVER_TOPIC)) { NS_ASSERTION(aData, "No data?!"); const nsDependentString data(aData); if (data.EqualsLiteral(LOW_DISK_SPACE_DATA_FULL)) { sLowDiskSpaceMode = true; } else if (data.EqualsLiteral(LOW_DISK_SPACE_DATA_FREE)) { sLowDiskSpaceMode = false; } else { NS_NOTREACHED("Unknown data value!"); } return NS_OK; } NS_NOTREACHED("Unknown topic!"); return NS_ERROR_UNEXPECTED; }
nsresult IndexedDatabaseManager::FlushPendingFileDeletions() { MOZ_ASSERT(NS_IsMainThread()); if (NS_WARN_IF(!InTestingMode())) { return NS_ERROR_UNEXPECTED; } if (IsMainProcess()) { nsresult rv = mDeleteTimer->Cancel(); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } rv = Notify(mDeleteTimer); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } } else { ContentChild* contentChild = ContentChild::GetSingleton(); if (NS_WARN_IF(!contentChild)) { return NS_ERROR_FAILURE; } if (!contentChild->SendFlushPendingFileDeletions()) { return NS_ERROR_FAILURE; } } return NS_OK; }
void IndexedDatabaseManager::NoteBackgroundThread(nsIEventTarget* aBackgroundThread) { MOZ_ASSERT(IsMainProcess()); MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aBackgroundThread); mBackgroundThread = aBackgroundThread; }
nsresult IndexedDatabaseManager::BlockAndGetFileReferences( PersistenceType aPersistenceType, const nsACString& aOrigin, const nsAString& aDatabaseName, int64_t aFileId, int32_t* aRefCnt, int32_t* aDBRefCnt, int32_t* aSliceRefCnt, bool* aResult) { MOZ_ASSERT(NS_IsMainThread()); if (NS_WARN_IF(!InTestingMode())) { return NS_ERROR_UNEXPECTED; } if (IsMainProcess()) { nsRefPtr<GetFileReferencesHelper> helper = new GetFileReferencesHelper(aPersistenceType, aOrigin, aDatabaseName, aFileId); nsresult rv = helper->DispatchAndReturnFileReferences(aRefCnt, aDBRefCnt, aSliceRefCnt, aResult); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } } else { ContentChild* contentChild = ContentChild::GetSingleton(); if (NS_WARN_IF(!contentChild)) { return NS_ERROR_FAILURE; } if (!contentChild->SendGetFileReferences(aPersistenceType, nsCString(aOrigin), nsString(aDatabaseName), aFileId, aRefCnt, aDBRefCnt, aSliceRefCnt, aResult)) { return NS_ERROR_FAILURE; } } return NS_OK; }
NS_IMETHODIMP IndexedDatabaseManager::Notify(nsITimer* aTimer) { MOZ_ASSERT(IsMainProcess()); MOZ_ASSERT(NS_IsMainThread()); for (auto iter = mPendingDeleteInfos.ConstIter(); !iter.Done(); iter.Next()) { auto key = iter.Key(); auto value = iter.Data(); MOZ_ASSERT(!value->IsEmpty()); RefPtr<DeleteFilesRunnable> runnable = new DeleteFilesRunnable(mBackgroundThread, key, *value); MOZ_ASSERT(value->IsEmpty()); runnable->Dispatch(); } mPendingDeleteInfos.Clear(); return NS_OK; }