void FileSystemTaskBase::Start() { MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!"); if (HasError()) { HandlerCallback(); return; } if (FileSystemUtils::IsParentProcess()) { // Run in parent process. // Start worker thread. nsCOMPtr<nsIEventTarget> target = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); NS_ASSERTION(target, "Must have stream transport service."); target->Dispatch(this, NS_DISPATCH_NORMAL); return; } // Run in child process. nsRefPtr<FileSystemBase> filesystem = do_QueryReferent(mFileSystem); if (!filesystem) { return; } // Retain a reference so the task object isn't deleted without IPDL's // knowledge. The reference will be released by // mozilla::dom::ContentChild::DeallocPFileSystemRequestChild. NS_ADDREF_THIS(); ContentChild::GetSingleton()->SendPFileSystemRequestConstructor(this, GetRequestParams(filesystem->ToString())); }
void FileSystemTaskChildBase::Start() { mFileSystem->AssertIsOnOwningThread(); if (HasError()) { // In this case we don't want to use IPC at all. RefPtr<ErrorRunnable> runnable = new ErrorRunnable(this); nsresult rv = NS_DispatchToCurrentThread(runnable); NS_WARN_IF(NS_FAILED(rv)); return; } if (mFileSystem->IsShutdown()) { return; } nsAutoString serialization; mFileSystem->SerializeDOMPath(serialization); ErrorResult rv; FileSystemParams params = GetRequestParams(serialization, rv); if (NS_WARN_IF(rv.Failed())) { rv.SuppressException(); return; } // Retain a reference so the task object isn't deleted without IPDL's // knowledge. The reference will be released by // mozilla::ipc::BackgroundChildImpl::DeallocPFileSystemRequestChild. NS_ADDREF_THIS(); // If we are here, PBackground must be up and running, because Start() is // called only by FileSystemPermissionRequest, and that class takes care of // PBackground initialization. PBackgroundChild* actor = mozilla::ipc::BackgroundChild::GetForCurrentThread(); MOZ_ASSERT(actor); actor->SendPFileSystemRequestConstructor(this, params); }
void FileSystemTaskChildBase::ActorCreated(mozilla::ipc::PBackgroundChild* aActor) { if (HasError()) { // In this case we don't want to use IPC at all. RefPtr<ErrorRunnable> runnable = new ErrorRunnable(this); FileSystemUtils::DispatchRunnable(mGlobalObject, runnable.forget()); return; } if (mFileSystem->IsShutdown()) { return; } nsAutoString serialization; mFileSystem->SerializeDOMPath(serialization); ErrorResult rv; FileSystemParams params = GetRequestParams(serialization, rv); if (NS_WARN_IF(rv.Failed())) { rv.SuppressException(); return; } // Retain a reference so the task object isn't deleted without IPDL's // knowledge. The reference will be released by // mozilla::ipc::BackgroundChildImpl::DeallocPFileSystemRequestChild. NS_ADDREF_THIS(); if (NS_IsMainThread()) { nsIEventTarget* target = mGlobalObject->EventTargetFor(TaskCategory::Other); MOZ_ASSERT(target); aActor->SetEventTargetForActor(this, target); } aActor->SendPFileSystemRequestConstructor(this, params); }