Bug 1350933 - Labeling dom/filesystem - part 3 - IPC actors, r=billm

This commit is contained in:
Andrea Marchesini 2017-04-05 09:47:56 +02:00
Родитель 59743dbfbf
Коммит 7b2382f375
8 изменённых файлов: 42 добавлений и 31 удалений

Просмотреть файл

@ -112,12 +112,15 @@ NS_IMPL_ISUPPORTS(FileSystemTaskChildBase, nsIIPCBackgroundChildCreateCallback)
* FileSystemTaskBase class
*/
FileSystemTaskChildBase::FileSystemTaskChildBase(FileSystemBase* aFileSystem)
FileSystemTaskChildBase::FileSystemTaskChildBase(nsIGlobalObject* aGlobalObject,
FileSystemBase* aFileSystem)
: mErrorValue(NS_OK)
, mFileSystem(aFileSystem)
, mGlobalObject(aGlobalObject)
{
MOZ_ASSERT(aFileSystem, "aFileSystem should not be null.");
aFileSystem->AssertIsOnOwningThread();
MOZ_ASSERT(aGlobalObject);
}
FileSystemTaskChildBase::~FileSystemTaskChildBase()
@ -161,10 +164,7 @@ 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);
// This will be changed in the next patch TODO
DebugOnly<nsresult> rv = NS_DispatchToCurrentThread(runnable);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NS_DispatchToCurrentThread failed");
FileSystemUtils::DispatchRunnable(mGlobalObject, runnable.forget());
return;
}
@ -187,11 +187,14 @@ FileSystemTaskChildBase::ActorCreated(mozilla::ipc::PBackgroundChild* aActor)
// mozilla::ipc::BackgroundChildImpl::DeallocPFileSystemRequestChild.
NS_ADDREF_THIS();
mozilla::ipc::PBackgroundChild* actor =
mozilla::ipc::BackgroundChild::GetForCurrentThread();
MOZ_ASSERT(actor);
if (NS_IsMainThread()) {
nsIEventTarget* target = mGlobalObject->EventTargetFor(TaskCategory::Other);
MOZ_ASSERT(target);
actor->SendPFileSystemRequestConstructor(this, params);
aActor->SetEventTargetForActor(this, target);
}
aActor->SendPFileSystemRequestConstructor(this, params);
}
void

Просмотреть файл

@ -138,7 +138,8 @@ protected:
/*
* To create a task to handle the page content request.
*/
explicit FileSystemTaskChildBase(FileSystemBase* aFileSystem);
FileSystemTaskChildBase(nsIGlobalObject* aGlobalObject,
FileSystemBase* aFileSystem);
virtual
~FileSystemTaskChildBase();
@ -169,6 +170,7 @@ protected:
nsresult mErrorValue;
RefPtr<FileSystemBase> mFileSystem;
nsCOMPtr<nsIGlobalObject> mGlobalObject;
private:

Просмотреть файл

@ -38,12 +38,6 @@ GetDirectoryListingTaskChild::Create(FileSystemBase* aFileSystem,
MOZ_ASSERT(aDirectory);
aFileSystem->AssertIsOnOwningThread();
RefPtr<GetDirectoryListingTaskChild> task =
new GetDirectoryListingTaskChild(aFileSystem, aDirectory, aTargetPath,
aFilters);
// aTargetPath can be null. In this case SetError will be called.
nsCOMPtr<nsIGlobalObject> globalObject =
do_QueryInterface(aFileSystem->GetParentObject());
if (NS_WARN_IF(!globalObject)) {
@ -51,6 +45,12 @@ GetDirectoryListingTaskChild::Create(FileSystemBase* aFileSystem,
return nullptr;
}
RefPtr<GetDirectoryListingTaskChild> task =
new GetDirectoryListingTaskChild(globalObject, aFileSystem, aDirectory,
aTargetPath, aFilters);
// aTargetPath can be null. In this case SetError will be called.
task->mPromise = Promise::Create(globalObject, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
@ -59,11 +59,12 @@ GetDirectoryListingTaskChild::Create(FileSystemBase* aFileSystem,
return task.forget();
}
GetDirectoryListingTaskChild::GetDirectoryListingTaskChild(FileSystemBase* aFileSystem,
GetDirectoryListingTaskChild::GetDirectoryListingTaskChild(nsIGlobalObject* aGlobalObject,
FileSystemBase* aFileSystem,
Directory* aDirectory,
nsIFile* aTargetPath,
const nsAString& aFilters)
: FileSystemTaskChildBase(aFileSystem)
: FileSystemTaskChildBase(aGlobalObject, aFileSystem)
, mDirectory(aDirectory)
, mTargetPath(aTargetPath)
, mFilters(aFilters)

Просмотреть файл

@ -36,7 +36,8 @@ public:
private:
// If aDirectoryOnly is set, we should ensure that the target is a directory.
GetDirectoryListingTaskChild(FileSystemBase* aFileSystem,
GetDirectoryListingTaskChild(nsIGlobalObject* aGlobalObject,
FileSystemBase* aFileSystem,
Directory* aDirectory,
nsIFile* aTargetPath,
const nsAString& aFilters);

Просмотреть файл

@ -32,11 +32,6 @@ GetFileOrDirectoryTaskChild::Create(FileSystemBase* aFileSystem,
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
MOZ_ASSERT(aFileSystem);
RefPtr<GetFileOrDirectoryTaskChild> task =
new GetFileOrDirectoryTaskChild(aFileSystem, aTargetPath);
// aTargetPath can be null. In this case SetError will be called.
nsCOMPtr<nsIGlobalObject> globalObject =
do_QueryInterface(aFileSystem->GetParentObject());
if (NS_WARN_IF(!globalObject)) {
@ -44,6 +39,11 @@ GetFileOrDirectoryTaskChild::Create(FileSystemBase* aFileSystem,
return nullptr;
}
RefPtr<GetFileOrDirectoryTaskChild> task =
new GetFileOrDirectoryTaskChild(globalObject, aFileSystem, aTargetPath);
// aTargetPath can be null. In this case SetError will be called.
task->mPromise = Promise::Create(globalObject, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
@ -52,9 +52,10 @@ GetFileOrDirectoryTaskChild::Create(FileSystemBase* aFileSystem,
return task.forget();
}
GetFileOrDirectoryTaskChild::GetFileOrDirectoryTaskChild(FileSystemBase* aFileSystem,
GetFileOrDirectoryTaskChild::GetFileOrDirectoryTaskChild(nsIGlobalObject* aGlobalObject,
FileSystemBase* aFileSystem,
nsIFile* aTargetPath)
: FileSystemTaskChildBase(aFileSystem)
: FileSystemTaskChildBase(aGlobalObject, aFileSystem)
, mTargetPath(aTargetPath)
{
MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");

Просмотреть файл

@ -43,7 +43,8 @@ protected:
HandlerCallback() override;
private:
GetFileOrDirectoryTaskChild(FileSystemBase* aFileSystem,
GetFileOrDirectoryTaskChild(nsIGlobalObject* aGlobalObject,
FileSystemBase* aFileSystem,
nsIFile* aTargetPath);
RefPtr<Promise> mPromise;

Просмотреть файл

@ -44,7 +44,7 @@ GetFilesTaskChild::Create(FileSystemBase* aFileSystem,
}
RefPtr<GetFilesTaskChild> task =
new GetFilesTaskChild(aFileSystem, aDirectory, aTargetPath,
new GetFilesTaskChild(globalObject, aFileSystem, aDirectory, aTargetPath,
aRecursiveFlag);
// aTargetPath can be null. In this case SetError will be called.
@ -57,11 +57,12 @@ GetFilesTaskChild::Create(FileSystemBase* aFileSystem,
return task.forget();
}
GetFilesTaskChild::GetFilesTaskChild(FileSystemBase* aFileSystem,
GetFilesTaskChild::GetFilesTaskChild(nsIGlobalObject *aGlobalObject,
FileSystemBase* aFileSystem,
Directory* aDirectory,
nsIFile* aTargetPath,
bool aRecursiveFlag)
: FileSystemTaskChildBase(aFileSystem)
: FileSystemTaskChildBase(aGlobalObject, aFileSystem)
, mDirectory(aDirectory)
, mTargetPath(aTargetPath)
, mRecursiveFlag(aRecursiveFlag)

Просмотреть файл

@ -36,7 +36,8 @@ public:
private:
// If aDirectoryOnly is set, we should ensure that the target is a directory.
GetFilesTaskChild(FileSystemBase* aFileSystem,
GetFilesTaskChild(nsIGlobalObject* aGlobalObject,
FileSystemBase* aFileSystem,
Directory* aDirectory,
nsIFile* aTargetPath,
bool aRecursiveFlag);