本文整理汇总了C++中FileService类的典型用法代码示例。如果您正苦于以下问题:C++ FileService类的具体用法?C++ FileService怎么用?C++ FileService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileService类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NS_ASSERTION
nsresult
ReadHelper::DoAsyncRun(nsISupports* aStream)
{
NS_ASSERTION(aStream, "Passed a null stream!");
uint32_t flags = FileStreamWrapper::NOTIFY_PROGRESS;
nsCOMPtr<nsIInputStream> istream =
new FileInputStreamWrapper(aStream, this, mLocation, mSize, flags);
FileService* service = FileService::Get();
NS_ASSERTION(service, "This should never be null");
nsIEventTarget* target = service->StreamTransportTarget();
nsCOMPtr<nsIAsyncStreamCopier> copier;
nsresult rv =
NS_NewAsyncStreamCopier(getter_AddRefs(copier), istream, mStream, target,
false, true, STREAM_COPY_BLOCK_SIZE);
NS_ENSURE_SUCCESS(rv, rv);
rv = copier->AsyncCopy(this, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
mRequest = do_QueryInterface(copier);
return NS_OK;
}
示例2: NS_DispatchToMainThread
NS_IMETHODIMP
FinishHelper::Run()
{
if (NS_IsMainThread()) {
mLockedFile->mReadyState = LockedFile::DONE;
FileService* service = FileService::Get();
if (service) {
service->NotifyLockedFileCompleted(mLockedFile);
}
nsCOMPtr<nsIDOMEvent> event;
if (mAborted) {
event = CreateGenericEvent(mLockedFile, NS_LITERAL_STRING("abort"),
true, false);
}
else {
event = CreateGenericEvent(mLockedFile, NS_LITERAL_STRING("complete"),
false, false);
}
NS_ENSURE_TRUE(event, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
bool dummy;
if (NS_FAILED(mLockedFile->DispatchEvent(event, &dummy))) {
NS_WARNING("Dispatch failed!");
}
mLockedFile = nullptr;
return NS_OK;
}
nsIFileStorage* fileStorage = mLockedFile->mFileHandle->mFileStorage;
if (fileStorage->IsInvalidated()) {
mAborted = true;
}
for (uint32_t index = 0; index < mParallelStreams.Length(); index++) {
nsCOMPtr<nsIInputStream> stream =
do_QueryInterface(mParallelStreams[index]);
if (NS_FAILED(stream->Close())) {
NS_WARNING("Failed to close stream!");
}
mParallelStreams[index] = nullptr;
}
if (mStream) {
nsCOMPtr<nsIInputStream> stream = do_QueryInterface(mStream);
if (NS_FAILED(stream->Close())) {
NS_WARNING("Failed to close stream!");
}
mStream = nullptr;
}
return NS_DispatchToMainThread(this, NS_DISPATCH_NORMAL);
}
示例3: NS_DispatchToMainThread
NS_IMETHODIMP
FinishHelper::Run()
{
if (NS_IsMainThread()) {
mFileHandle->mReadyState = FileHandleBase::DONE;
FileService* service = FileService::Get();
if (service) {
service->NotifyFileHandleCompleted(mFileHandle);
}
nsresult rv = mFileHandle->OnCompleteOrAbort(mAborted);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mFileHandle = nullptr;
return NS_OK;
}
if (mFileHandle->MutableFile()->IsInvalid()) {
mAborted = true;
}
for (uint32_t index = 0; index < mParallelStreams.Length(); index++) {
nsCOMPtr<nsIInputStream> stream =
do_QueryInterface(mParallelStreams[index]);
if (NS_FAILED(stream->Close())) {
NS_WARNING("Failed to close stream!");
}
mParallelStreams[index] = nullptr;
}
if (mStream) {
nsCOMPtr<nsIInputStream> stream = do_QueryInterface(mStream);
if (NS_FAILED(stream->Close())) {
NS_WARNING("Failed to close stream!");
}
mStream = nullptr;
}
return NS_DispatchToMainThread(this);
}
示例4: MOZ_ASSERT
nsresult
FileHandleBase::Finish()
{
MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
nsRefPtr<FinishHelper> helper(new FinishHelper(this));
FileService* service = FileService::Get();
MOZ_ASSERT(service, "This should never be null");
nsIEventTarget* target = service->ThreadPoolTarget();
nsresult rv = target->Dispatch(helper, NS_DISPATCH_NORMAL);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
示例5: NS_ASSERTION
nsresult
FileHelper::Enqueue()
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
FileService* service = FileService::GetOrCreate();
NS_ENSURE_TRUE(service, NS_ERROR_FAILURE);
nsresult rv = service->Enqueue(mLockedFile, this);
NS_ENSURE_SUCCESS(rv, rv);
if (mLockedFile) {
mLockedFile->OnNewRequest();
}
return NS_OK;
}
示例6: NS_NewRequestObserverProxy
nsresult
AsyncHelper::AsyncWork(nsIRequestObserver* aObserver, nsISupports* aCtxt)
{
nsresult rv;
if (aObserver) {
// build proxy for observer events
rv = NS_NewRequestObserverProxy(getter_AddRefs(mObserver), aObserver, aCtxt);
NS_ENSURE_SUCCESS(rv, rv);
}
FileService* service = FileService::GetOrCreate();
NS_ENSURE_TRUE(service, NS_ERROR_FAILURE);
nsIEventTarget* target = service->StreamTransportTarget();
rv = target->Dispatch(this, NS_DISPATCH_NORMAL);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}