2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-03-05 07:25:40 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "mozilla/dom/FileSystemRequestParent.h"
|
|
|
|
|
|
|
|
#include "CreateDirectoryTask.h"
|
2014-03-05 12:40:48 +04:00
|
|
|
#include "CreateFileTask.h"
|
2015-06-23 02:31:32 +03:00
|
|
|
#include "GetDirectoryListingTask.h"
|
2014-03-05 07:25:40 +04:00
|
|
|
#include "GetFileOrDirectoryTask.h"
|
2014-03-12 10:30:21 +04:00
|
|
|
#include "RemoveTask.h"
|
2014-03-05 07:25:40 +04:00
|
|
|
|
|
|
|
#include "mozilla/dom/FileSystemBase.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
FileSystemRequestParent::FileSystemRequestParent()
|
2016-04-09 21:17:02 +03:00
|
|
|
: mDestroyed(false)
|
2014-03-05 07:25:40 +04:00
|
|
|
{
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnBackgroundThread();
|
2014-03-05 07:25:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
FileSystemRequestParent::~FileSystemRequestParent()
|
|
|
|
{
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnBackgroundThread();
|
2014-03-05 07:25:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(name) \
|
|
|
|
case FileSystemParams::TFileSystem##name##Params: { \
|
|
|
|
const FileSystem##name##Params& p = aParams; \
|
2016-03-20 13:56:10 +03:00
|
|
|
mFileSystem = FileSystemBase::DeserializeDOMPath(p.filesystem()); \
|
2016-04-09 21:17:02 +03:00
|
|
|
MOZ_ASSERT(mFileSystem); \
|
|
|
|
mTask = name##TaskParent::Create(mFileSystem, p, this, rv); \
|
2016-03-20 13:56:10 +03:00
|
|
|
if (NS_WARN_IF(rv.Failed())) { \
|
2016-07-22 17:50:10 +03:00
|
|
|
rv.SuppressException(); \
|
2016-03-20 13:56:10 +03:00
|
|
|
return false; \
|
|
|
|
} \
|
2014-03-05 07:25:40 +04:00
|
|
|
break; \
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2016-04-09 21:17:02 +03:00
|
|
|
FileSystemRequestParent::Initialize(const FileSystemParams& aParams)
|
2014-03-05 07:25:40 +04:00
|
|
|
{
|
2016-04-09 21:17:02 +03:00
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
|
2016-03-20 13:56:10 +03:00
|
|
|
ErrorResult rv;
|
|
|
|
|
2014-03-05 07:25:40 +04:00
|
|
|
switch (aParams.type()) {
|
|
|
|
|
|
|
|
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(CreateDirectory)
|
2014-03-05 12:40:48 +04:00
|
|
|
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(CreateFile)
|
2015-06-23 02:31:32 +03:00
|
|
|
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetDirectoryListing)
|
2014-03-05 07:25:40 +04:00
|
|
|
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetFileOrDirectory)
|
2016-04-13 14:15:56 +03:00
|
|
|
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetFiles)
|
2014-03-12 10:30:21 +04:00
|
|
|
FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(Remove)
|
2014-03-05 07:25:40 +04:00
|
|
|
|
|
|
|
default: {
|
2016-12-03 00:46:53 +03:00
|
|
|
MOZ_CRASH("not reached");
|
2014-03-05 07:25:40 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-09 21:17:02 +03:00
|
|
|
if (NS_WARN_IF(!mTask || !mFileSystem)) {
|
2014-03-05 07:25:40 +04:00
|
|
|
// Should never reach here.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-09 21:17:02 +03:00
|
|
|
if (mFileSystem->PermissionCheckType() != FileSystemBase::ePermissionCheckNotRequired) {
|
|
|
|
nsAutoCString access;
|
|
|
|
mTask->GetPermissionAccessType(access);
|
2014-03-05 07:24:19 +04:00
|
|
|
|
2016-04-09 21:17:02 +03:00
|
|
|
mPermissionName = mFileSystem->GetPermission();
|
|
|
|
mPermissionName.Append('-');
|
|
|
|
mPermissionName.Append(access);
|
2014-03-05 07:24:19 +04:00
|
|
|
}
|
|
|
|
|
2014-03-05 07:25:40 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-04-09 21:17:02 +03:00
|
|
|
FileSystemRequestParent::Start()
|
2014-03-05 07:25:40 +04:00
|
|
|
{
|
2016-04-09 21:17:02 +03:00
|
|
|
MOZ_ASSERT(!mDestroyed);
|
|
|
|
MOZ_ASSERT(mFileSystem);
|
|
|
|
MOZ_ASSERT(mTask);
|
|
|
|
|
|
|
|
mTask->Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FileSystemRequestParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
MOZ_ASSERT(!mDestroyed);
|
|
|
|
|
2014-03-05 07:25:40 +04:00
|
|
|
if (!mFileSystem) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-09 21:17:02 +03:00
|
|
|
|
2014-03-05 07:25:40 +04:00
|
|
|
mFileSystem->Shutdown();
|
|
|
|
mFileSystem = nullptr;
|
2016-04-09 21:17:02 +03:00
|
|
|
mTask = nullptr;
|
|
|
|
mDestroyed = true;
|
2014-03-05 07:25:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|