Bug 1299500 - Get rid of DeviceStorage API - part 5 - Directory::CreateFile, r=ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 08 Mar 2017 20:15:44 +0100
changeset 346613 a8670bee71a54d0f91874e653c9f4d6b7c401792
parent 346612 a35a754a55d89566aa9c0e3cf4646e6782c4ab78
child 346614 f6e90b7c442fc8407f1df1b7beec10ae6d49dc42
push id31472
push userkwierso@gmail.com
push dateThu, 09 Mar 2017 01:08:10 +0000
treeherdermozilla-central@19289cc8bf6f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1299500
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1299500 - Get rid of DeviceStorage API - part 5 - Directory::CreateFile, r=ehsan
dom/filesystem/CreateFileTask.cpp
dom/filesystem/CreateFileTask.h
dom/filesystem/DeviceStorageFileSystem.cpp
dom/filesystem/Directory.cpp
dom/filesystem/Directory.h
dom/filesystem/FileSystemRequestParent.cpp
dom/filesystem/GetDirectoryListingTask.h
dom/filesystem/GetFileOrDirectoryTask.h
dom/filesystem/GetFilesTask.h
dom/filesystem/PFileSystemParams.ipdlh
dom/filesystem/RemoveTask.h
dom/filesystem/moz.build
dom/webidl/Directory.webidl
deleted file mode 100644
--- a/dom/filesystem/CreateFileTask.cpp
+++ /dev/null
@@ -1,399 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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 "CreateFileTask.h"
-
-#include <algorithm>
-
-#include "mozilla/Preferences.h"
-#include "mozilla/dom/FileBlobImpl.h"
-#include "mozilla/dom/FileSystemBase.h"
-#include "mozilla/dom/FileSystemUtils.h"
-#include "mozilla/dom/PFileSystemParams.h"
-#include "mozilla/dom/Promise.h"
-#include "mozilla/dom/ipc/BlobChild.h"
-#include "mozilla/dom/ipc/BlobParent.h"
-#include "mozilla/ipc/BackgroundChild.h"
-#include "mozilla/ipc/PBackgroundChild.h"
-#include "nsIFile.h"
-#include "nsNetUtil.h"
-#include "nsIInputStream.h"
-#include "nsIOutputStream.h"
-#include "nsStringGlue.h"
-
-#define GET_PERMISSION_ACCESS_TYPE(aAccess)                \
-  if (mReplace) {                                          \
-    aAccess.AssignLiteral(DIRECTORY_WRITE_PERMISSION);     \
-    return;                                                \
-  }                                                        \
-  aAccess.AssignLiteral(DIRECTORY_CREATE_PERMISSION);
-
-namespace mozilla {
-namespace dom {
-
-/**
- *CreateFileTaskChild
- */
-
-/* static */ already_AddRefed<CreateFileTaskChild>
-CreateFileTaskChild::Create(FileSystemBase* aFileSystem,
-                            nsIFile* aTargetPath,
-                            Blob* aBlobData,
-                            InfallibleTArray<uint8_t>& aArrayData,
-                            bool aReplace,
-                            ErrorResult& aRv)
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-  MOZ_ASSERT(aFileSystem);
-
-  RefPtr<CreateFileTaskChild> task =
-    new CreateFileTaskChild(aFileSystem, aTargetPath, aReplace);
-
-  // aTargetPath can be null. In this case SetError will be called.
-
-  if (aBlobData) {
-    task->mBlobImpl = aBlobData->Impl();
-  }
-
-  task->mArrayData.SwapElements(aArrayData);
-
-  nsCOMPtr<nsIGlobalObject> globalObject =
-    do_QueryInterface(aFileSystem->GetParentObject());
-  if (NS_WARN_IF(!globalObject)) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  task->mPromise = Promise::Create(globalObject, aRv);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return nullptr;
-  }
-
-  return task.forget();
-}
-
-CreateFileTaskChild::CreateFileTaskChild(FileSystemBase* aFileSystem,
-                                         nsIFile* aTargetPath,
-                                         bool aReplace)
-  : FileSystemTaskChildBase(aFileSystem)
-  , mTargetPath(aTargetPath)
-  , mReplace(aReplace)
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-  MOZ_ASSERT(aFileSystem);
-}
-
-CreateFileTaskChild::~CreateFileTaskChild()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-}
-
-already_AddRefed<Promise>
-CreateFileTaskChild::GetPromise()
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-  return RefPtr<Promise>(mPromise).forget();
-}
-
-FileSystemParams
-CreateFileTaskChild::GetRequestParams(const nsString& aSerializedDOMPath,
-                                      ErrorResult& aRv) const
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-  FileSystemCreateFileParams param;
-  param.filesystem() = aSerializedDOMPath;
-
-  aRv = mTargetPath->GetPath(param.realPath());
-  if (NS_WARN_IF(aRv.Failed())) {
-    return param;
-  }
-
-  // If we are here, PBackground must be up and running: this method is called
-  // when the task has been already started by FileSystemPermissionRequest
-  // class and this happens only when PBackground actor has already been
-  // created.
-  PBackgroundChild* actor =
-    mozilla::ipc::BackgroundChild::GetForCurrentThread();
-  MOZ_ASSERT(actor);
-
-  param.replace() = mReplace;
-  if (mBlobImpl) {
-    PBlobChild* blobActor =
-      mozilla::ipc::BackgroundChild::GetOrCreateActorForBlobImpl(actor,
-                                                                 mBlobImpl);
-    if (blobActor) {
-      param.data() = blobActor;
-    }
-  } else {
-    param.data() = mArrayData;
-  }
-  return param;
-}
-
-void
-CreateFileTaskChild::SetSuccessRequestResult(const FileSystemResponseValue& aValue,
-                                             ErrorResult& aRv)
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-
-  const FileSystemFileResponse& r = aValue.get_FileSystemFileResponse();
-
-  mBlobImpl = static_cast<BlobChild*>(r.blobChild())->GetBlobImpl();
-  MOZ_ASSERT(mBlobImpl);
-}
-
-void
-CreateFileTaskChild::HandlerCallback()
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-
-  if (mFileSystem->IsShutdown()) {
-    mPromise = nullptr;
-    return;
-  }
-
-  if (HasError()) {
-    mPromise->MaybeReject(mErrorValue);
-    mPromise = nullptr;
-    return;
-  }
-
-  RefPtr<File> file = File::Create(mFileSystem->GetParentObject(), mBlobImpl);
-  mPromise->MaybeResolve(file);
-
-  mBlobImpl = nullptr;
-  mPromise = nullptr;
-}
-
-void
-CreateFileTaskChild::GetPermissionAccessType(nsCString& aAccess) const
-{
-  GET_PERMISSION_ACCESS_TYPE(aAccess)
-}
-
-/**
- * CreateFileTaskParent
- */
-
-uint32_t CreateFileTaskParent::sOutputBufferSize = 0;
-
-/* static */ already_AddRefed<CreateFileTaskParent>
-CreateFileTaskParent::Create(FileSystemBase* aFileSystem,
-                             const FileSystemCreateFileParams& aParam,
-                             FileSystemRequestParent* aParent,
-                             ErrorResult& aRv)
-{
-  MOZ_ASSERT(XRE_IsParentProcess(), "Only call from parent process!");
-  AssertIsOnBackgroundThread();
-  MOZ_ASSERT(aFileSystem);
-
-  RefPtr<CreateFileTaskParent> task =
-    new CreateFileTaskParent(aFileSystem, aParam, aParent);
-
-  aRv = NS_NewLocalFile(aParam.realPath(), true,
-                        getter_AddRefs(task->mTargetPath));
-  if (NS_WARN_IF(aRv.Failed())) {
-    return nullptr;
-  }
-
-  task->mReplace = aParam.replace();
-
-  const FileSystemFileDataValue& data = aParam.data();
-
-  if (data.type() == FileSystemFileDataValue::TArrayOfuint8_t) {
-    task->mArrayData = data;
-    return task.forget();
-  }
-
-  MOZ_ASSERT(data.type() == FileSystemFileDataValue::TPBlobParent);
-
-  BlobParent* bp = static_cast<BlobParent*>(static_cast<PBlobParent*>(data));
-  task->mBlobImpl = bp->GetBlobImpl();
-  MOZ_ASSERT(task->mBlobImpl, "blobData should not be null.");
-
-  return task.forget();
-}
-
-CreateFileTaskParent::CreateFileTaskParent(FileSystemBase* aFileSystem,
-                                           const FileSystemCreateFileParams& aParam,
-                                           FileSystemRequestParent* aParent)
-  : FileSystemTaskParentBase(aFileSystem, aParam, aParent)
-  , mReplace(false)
-{
-  MOZ_ASSERT(XRE_IsParentProcess(), "Only call from parent process!");
-  AssertIsOnBackgroundThread();
-  MOZ_ASSERT(aFileSystem);
-}
-
-FileSystemResponseValue
-CreateFileTaskParent::GetSuccessRequestResult(ErrorResult& aRv) const
-{
-  AssertIsOnBackgroundThread();
-
-  RefPtr<BlobImpl> blobImpl = new FileBlobImpl(mTargetPath);
-  BlobParent* blobParent =
-    BlobParent::GetOrCreate(mRequestParent->Manager(), blobImpl);
-  return FileSystemFileResponse(blobParent, nullptr);
-}
-
-nsresult
-CreateFileTaskParent::IOWork()
-{
-  class MOZ_RAII AutoClose final
-  {
-  public:
-    explicit AutoClose(nsIOutputStream* aStream)
-      : mStream(aStream)
-    {
-      MOZ_ASSERT(aStream);
-    }
-
-    ~AutoClose()
-    {
-      mStream->Close();
-    }
-
-  private:
-    nsCOMPtr<nsIOutputStream> mStream;
-  };
-
-  MOZ_ASSERT(XRE_IsParentProcess(),
-             "Only call from parent process!");
-  MOZ_ASSERT(!NS_IsMainThread(), "Only call on worker thread!");
-
-  if (mFileSystem->IsShutdown()) {
-    return NS_ERROR_FAILURE;
-  }
-
-  if (!mFileSystem->IsSafeFile(mTargetPath)) {
-    return NS_ERROR_DOM_SECURITY_ERR;
-  }
-
-  bool exists = false;
-  nsresult rv = mTargetPath->Exists(&exists);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  if (exists) {
-    bool isFile = false;
-    rv = mTargetPath->IsFile(&isFile);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
-    }
-
-    if (!isFile) {
-      return NS_ERROR_DOM_FILESYSTEM_TYPE_MISMATCH_ERR;
-    }
-
-    if (!mReplace) {
-      return NS_ERROR_DOM_FILESYSTEM_PATH_EXISTS_ERR;
-    }
-
-    // Remove the old file before creating.
-    rv = mTargetPath->Remove(false);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
-    }
-  }
-
-  rv = mTargetPath->Create(nsIFile::NORMAL_FILE_TYPE, 0600);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  nsCOMPtr<nsIOutputStream> outputStream;
-  rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream), mTargetPath);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  AutoClose acOutputStream(outputStream);
-  MOZ_ASSERT(sOutputBufferSize);
-
-  nsCOMPtr<nsIOutputStream> bufferedOutputStream;
-  rv = NS_NewBufferedOutputStream(getter_AddRefs(bufferedOutputStream),
-                                  outputStream,
-                                  sOutputBufferSize);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  AutoClose acBufferedOutputStream(bufferedOutputStream);
-
-  // Write the file content from blob data.
-  if (mBlobImpl) {
-    ErrorResult error;
-    nsCOMPtr<nsIInputStream> blobStream;
-    mBlobImpl->GetInternalStream(getter_AddRefs(blobStream), error);
-    if (NS_WARN_IF(error.Failed())) {
-      return error.StealNSResult();
-    }
-
-    uint64_t bufSize = 0;
-    rv = blobStream->Available(&bufSize);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
-    }
-
-    while (bufSize && !mFileSystem->IsShutdown()) {
-      uint32_t written = 0;
-      uint32_t writeSize = bufSize < UINT32_MAX ? bufSize : UINT32_MAX;
-      rv = bufferedOutputStream->WriteFrom(blobStream, writeSize, &written);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-      bufSize -= written;
-    }
-
-    blobStream->Close();
-
-    if (mFileSystem->IsShutdown()) {
-      return NS_ERROR_FAILURE;
-    }
-
-    return NS_OK;
-  }
-
-  // Write file content from array data.
-
-  uint32_t written;
-  rv = bufferedOutputStream->Write(
-    reinterpret_cast<char*>(mArrayData.Elements()),
-    mArrayData.Length(),
-    &written);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  if (mArrayData.Length() != written) {
-    return NS_ERROR_DOM_FILESYSTEM_UNKNOWN_ERR;
-  }
-
-  return NS_OK;
-}
-
-nsresult
-CreateFileTaskParent::MainThreadWork()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  if (!sOutputBufferSize) {
-    sOutputBufferSize =
-      mozilla::Preferences::GetUint("dom.filesystem.outputBufferSize", 4096 * 4);
-  }
-
-  return FileSystemTaskParentBase::MainThreadWork();
-}
-
-void
-CreateFileTaskParent::GetPermissionAccessType(nsCString& aAccess) const
-{
-  GET_PERMISSION_ACCESS_TYPE(aAccess)
-}
-
-} // namespace dom
-} // namespace mozilla
deleted file mode 100644
--- a/dom/filesystem/CreateFileTask.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* 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/. */
-
-#ifndef mozilla_dom_CreateFileTask_h
-#define mozilla_dom_CreateFileTask_h
-
-#include "mozilla/dom/FileSystemTaskBase.h"
-#include "mozilla/ErrorResult.h"
-
-class nsIInputStream;
-
-namespace mozilla {
-namespace dom {
-
-class Blob;
-class BlobImpl;
-class Promise;
-
-class CreateFileTaskChild final : public FileSystemTaskChildBase
-{
-public:
-  static already_AddRefed<CreateFileTaskChild>
-  Create(FileSystemBase* aFileSystem,
-         nsIFile* aFile,
-         Blob* aBlobData,
-         InfallibleTArray<uint8_t>& aArrayData,
-         bool replace,
-         ErrorResult& aRv);
-
-  virtual
-  ~CreateFileTaskChild();
-
-  already_AddRefed<Promise>
-  GetPromise();
-
-  virtual void
-  GetPermissionAccessType(nsCString& aAccess) const override;
-
-protected:
-  virtual FileSystemParams
-  GetRequestParams(const nsString& aSerializedDOMPath,
-                   ErrorResult& aRv) const override;
-
-  virtual void
-  SetSuccessRequestResult(const FileSystemResponseValue& aValue,
-                          ErrorResult& aRv) override;
-
-  virtual void
-  HandlerCallback() override;
-
-private:
-  CreateFileTaskChild(FileSystemBase* aFileSystem,
-                      nsIFile* aFile,
-                      bool aReplace);
-
-  RefPtr<Promise> mPromise;
-  nsCOMPtr<nsIFile> mTargetPath;
-
-  // This is the content of what we want to store. Then, when the File is
-  // created, this will be used to store the new object.
-  RefPtr<BlobImpl> mBlobImpl;
-
-  // This is going to be the content of the file, received by createFile()
-  // params.
-  InfallibleTArray<uint8_t> mArrayData;
-
-  bool mReplace;
-};
-
-class CreateFileTaskParent final : public FileSystemTaskParentBase
-{
-public:
-  static already_AddRefed<CreateFileTaskParent>
-  Create(FileSystemBase* aFileSystem,
-         const FileSystemCreateFileParams& aParam,
-         FileSystemRequestParent* aParent,
-         ErrorResult& aRv);
-
-  virtual bool
-  NeedToGoToMainThread() const override { return true; }
-
-  virtual nsresult
-  MainThreadWork() override;
-
-  virtual void
-  GetPermissionAccessType(nsCString& aAccess) const override;
-
-protected:
-  virtual FileSystemResponseValue
-  GetSuccessRequestResult(ErrorResult& aRv) const override;
-
-  virtual nsresult
-  IOWork() override;
-
-private:
-  CreateFileTaskParent(FileSystemBase* aFileSystem,
-                       const FileSystemCreateFileParams& aParam,
-                       FileSystemRequestParent* aParent);
-
-  static uint32_t sOutputBufferSize;
-
-  nsCOMPtr<nsIFile> mTargetPath;
-
-  RefPtr<BlobImpl> mBlobImpl;
-
-  // This is going to be the content of the file, received by createFile()
-  // params.
-  InfallibleTArray<uint8_t> mArrayData;
-
-  bool mReplace;
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_CreateFileTask_h
--- a/dom/filesystem/DeviceStorageFileSystem.cpp
+++ b/dom/filesystem/DeviceStorageFileSystem.cpp
@@ -6,24 +6,27 @@
 
 #include "mozilla/dom/DeviceStorageFileSystem.h"
 
 #include "DeviceStorage.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/dom/Directory.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/FileSystemUtils.h"
+#include "mozilla/ipc/BackgroundParent.h"
 #include "mozilla/Unused.h"
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsDeviceStorage.h"
 #include "nsIFile.h"
 #include "nsPIDOMWindow.h"
 #include "nsGlobalWindow.h"
 
+using namespace mozilla::ipc;
+
 namespace mozilla {
 namespace dom {
 
 DeviceStorageFileSystem::DeviceStorageFileSystem(const nsAString& aStorageType,
                                                  const nsAString& aStorageName)
   : mStorageType(aStorageType)
   , mStorageName(aStorageName)
   , mWindowId(0)
--- a/dom/filesystem/Directory.cpp
+++ b/dom/filesystem/Directory.cpp
@@ -2,17 +2,16 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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/Directory.h"
 
 #include "CreateDirectoryTask.h"
-#include "CreateFileTask.h"
 #include "FileSystemPermissionRequest.h"
 #include "GetDirectoryListingTask.h"
 #include "GetFileOrDirectoryTask.h"
 #include "GetFilesTask.h"
 #include "RemoveTask.h"
 #include "WorkerPrivate.h"
 
 #include "nsCharSeparatedTokenizer.h"
@@ -23,21 +22,16 @@
 #include "mozilla/dom/OSFileSystem.h"
 
 // Resolve the name collision of Microsoft's API name with macros defined in
 // Windows header files. Undefine the macro of CreateDirectory to avoid
 // Directory#CreateDirectory being replaced by Directory#CreateDirectoryW.
 #ifdef CreateDirectory
 #undef CreateDirectory
 #endif
-// Undefine the macro of CreateFile to avoid Directory#CreateFile being replaced
-// by Directory#CreateFileW.
-#ifdef CreateFile
-#undef CreateFile
-#endif
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(Directory)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Directory)
   if (tmp->mFileSystem) {
@@ -190,67 +184,16 @@ Directory::GetName(nsAString& aRetval, E
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
   fs->GetDirectoryName(mFile, aRetval, aRv);
 }
 
 already_AddRefed<Promise>
-Directory::CreateFile(const nsAString& aPath, const CreateFileOptions& aOptions,
-                      ErrorResult& aRv)
-{
-  // Only exposed for DeviceStorage.
-  MOZ_ASSERT(NS_IsMainThread());
-
-  RefPtr<Blob> blobData;
-  InfallibleTArray<uint8_t> arrayData;
-  bool replace = (aOptions.mIfExists == CreateIfExistsMode::Replace);
-
-  // Get the file content.
-  if (aOptions.mData.WasPassed()) {
-    auto& data = aOptions.mData.Value();
-    if (data.IsString()) {
-      NS_ConvertUTF16toUTF8 str(data.GetAsString());
-      arrayData.AppendElements(reinterpret_cast<const uint8_t *>(str.get()),
-                               str.Length());
-    } else if (data.IsArrayBuffer()) {
-      const ArrayBuffer& buffer = data.GetAsArrayBuffer();
-      buffer.ComputeLengthAndData();
-      arrayData.AppendElements(buffer.Data(), buffer.Length());
-    } else if (data.IsArrayBufferView()){
-      const ArrayBufferView& view = data.GetAsArrayBufferView();
-      view.ComputeLengthAndData();
-      arrayData.AppendElements(view.Data(), view.Length());
-    } else {
-      blobData = data.GetAsBlob();
-    }
-  }
-
-  nsCOMPtr<nsIFile> realPath;
-  nsresult error = DOMPathToRealPath(aPath, getter_AddRefs(realPath));
-
-  RefPtr<FileSystemBase> fs = GetFileSystem(aRv);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return nullptr;
-  }
-
-  RefPtr<CreateFileTaskChild> task =
-    CreateFileTaskChild::Create(fs, realPath, blobData, arrayData, replace,
-                                aRv);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return nullptr;
-  }
-
-  task->SetError(error);
-  FileSystemPermissionRequest::RequestForTask(task);
-  return task->GetPromise();
-}
-
-already_AddRefed<Promise>
 Directory::CreateDirectory(const nsAString& aPath, ErrorResult& aRv)
 {
   // Only exposed for DeviceStorage.
   MOZ_ASSERT(NS_IsMainThread());
 
   nsCOMPtr<nsIFile> realPath;
   nsresult error = DOMPathToRealPath(aPath, getter_AddRefs(realPath));
 
--- a/dom/filesystem/Directory.h
+++ b/dom/filesystem/Directory.h
@@ -15,26 +15,20 @@
 #include "nsWrapperCache.h"
 
 // Resolve the name collision of Microsoft's API name with macros defined in
 // Windows header files. Undefine the macro of CreateDirectory to avoid
 // Directory#CreateDirectory being replaced by Directory#CreateDirectoryW.
 #ifdef CreateDirectory
 #undef CreateDirectory
 #endif
-// Undefine the macro of CreateFile to avoid Directory#CreateFile being replaced
-// by Directory#CreateFileW.
-#ifdef CreateFile
-#undef CreateFile
-#endif
 
 namespace mozilla {
 namespace dom {
 
-struct CreateFileOptions;
 class FileSystemBase;
 class Promise;
 class StringOrFileOrDirectory;
 
 class Directory final
   : public nsISupports
   , public nsWrapperCache
 {
@@ -67,20 +61,16 @@ public:
 
   virtual JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   void
   GetName(nsAString& aRetval, ErrorResult& aRv);
 
   already_AddRefed<Promise>
-  CreateFile(const nsAString& aPath, const CreateFileOptions& aOptions,
-             ErrorResult& aRv);
-
-  already_AddRefed<Promise>
   CreateDirectory(const nsAString& aPath, ErrorResult& aRv);
 
   already_AddRefed<Promise>
   Get(const nsAString& aPath, ErrorResult& aRv);
 
   already_AddRefed<Promise>
   Remove(const StringOrFileOrDirectory& aPath, ErrorResult& aRv);
 
--- a/dom/filesystem/FileSystemRequestParent.cpp
+++ b/dom/filesystem/FileSystemRequestParent.cpp
@@ -1,17 +1,16 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* 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"
-#include "CreateFileTask.h"
 #include "GetDirectoryListingTask.h"
 #include "GetFileOrDirectoryTask.h"
 #include "RemoveTask.h"
 
 #include "mozilla/dom/FileSystemBase.h"
 
 namespace mozilla {
 namespace dom {
@@ -45,17 +44,16 @@ FileSystemRequestParent::Initialize(cons
 {
   AssertIsOnBackgroundThread();
 
   ErrorResult rv;
 
   switch (aParams.type()) {
 
     FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(CreateDirectory)
-    FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(CreateFile)
     FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetDirectoryListing)
     FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetFileOrDirectory)
     FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(GetFiles)
     FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(Remove)
 
     default: {
       MOZ_CRASH("not reached");
       break;
--- a/dom/filesystem/GetDirectoryListingTask.h
+++ b/dom/filesystem/GetDirectoryListingTask.h
@@ -10,16 +10,17 @@
 #include "mozilla/dom/Directory.h"
 #include "mozilla/dom/FileSystemTaskBase.h"
 #include "mozilla/ErrorResult.h"
 
 namespace mozilla {
 namespace dom {
 
 class BlobImpl;
+class FileSystemGetDirectoryListingParams;
 
 class GetDirectoryListingTaskChild final : public FileSystemTaskChildBase
 {
 public:
   static already_AddRefed<GetDirectoryListingTaskChild>
   Create(FileSystemBase* aFileSystem,
          Directory* aDirectory,
          nsIFile* aTargetPath,
--- a/dom/filesystem/GetFileOrDirectoryTask.h
+++ b/dom/filesystem/GetFileOrDirectoryTask.h
@@ -10,16 +10,17 @@
 #include "mozilla/dom/Directory.h"
 #include "mozilla/dom/FileSystemTaskBase.h"
 #include "mozilla/ErrorResult.h"
 
 namespace mozilla {
 namespace dom {
 
 class BlobImpl;
+class FileSystemGetFileOrDirectoryParams;
 
 class GetFileOrDirectoryTaskChild final : public FileSystemTaskChildBase
 {
 public:
   static already_AddRefed<GetFileOrDirectoryTaskChild>
   Create(FileSystemBase* aFileSystem,
          nsIFile* aTargetPath,
          bool aDirectoryOnly,
--- a/dom/filesystem/GetFilesTask.h
+++ b/dom/filesystem/GetFilesTask.h
@@ -11,16 +11,17 @@
 #include "mozilla/dom/FileSystemTaskBase.h"
 #include "mozilla/dom/GetFilesHelper.h"
 #include "mozilla/ErrorResult.h"
 
 namespace mozilla {
 namespace dom {
 
 class BlobImpl;
+class FileSystemGetFilesParams;
 
 class GetFilesTaskChild final : public FileSystemTaskChildBase
 {
 public:
   static already_AddRefed<GetFilesTaskChild>
   Create(FileSystemBase* aFileSystem,
          Directory* aDirectory,
          nsIFile* aTargetPath,
--- a/dom/filesystem/PFileSystemParams.ipdlh
+++ b/dom/filesystem/PFileSystemParams.ipdlh
@@ -14,24 +14,16 @@ struct FileSystemCreateDirectoryParams
 };
 
 union FileSystemFileDataValue
 {
   uint8_t[];
   PBlob;
 };
 
-struct FileSystemCreateFileParams
-{
-  nsString filesystem;
-  nsString realPath;
-  FileSystemFileDataValue data;
-  bool replace;
-};
-
 struct FileSystemGetDirectoryListingParams
 {
   nsString filesystem;
   nsString realPath;
   nsString domPath;
 
   // 'filters' could be an array rather than a semicolon separated string
   // (we'd then use InfallibleTArray<nsString> internally), but that is
@@ -65,17 +57,16 @@ struct FileSystemRemoveParams
   nsString directory;
   nsString targetDirectory;
   bool recursive;
 };
 
 union FileSystemParams
 {
   FileSystemCreateDirectoryParams;
-  FileSystemCreateFileParams;
   FileSystemGetDirectoryListingParams;
   FileSystemGetFilesParams;
   FileSystemGetFileOrDirectoryParams;
   FileSystemRemoveParams;
 };
 
 } // dom namespace
 } // mozilla namespace
--- a/dom/filesystem/RemoveTask.h
+++ b/dom/filesystem/RemoveTask.h
@@ -9,16 +9,17 @@
 
 #include "mozilla/dom/FileSystemTaskBase.h"
 #include "mozilla/ErrorResult.h"
 
 namespace mozilla {
 namespace dom {
 
 class BlobImpl;
+class FileSystemRemoveParams;
 class Promise;
 
 class RemoveTaskChild final : public FileSystemTaskChildBase
 {
 public:
   static already_AddRefed<RemoveTaskChild>
   Create(FileSystemBase* aFileSystem,
          nsIFile* aDirPath,
--- a/dom/filesystem/moz.build
+++ b/dom/filesystem/moz.build
@@ -18,18 +18,16 @@ EXPORTS.mozilla.dom += [
     'FileSystemRequestParent.h',
     'FileSystemTaskBase.h',
     'FileSystemUtils.h',
     'GetFilesHelper.h',
     'OSFileSystem.h',
 ]
 
 UNIFIED_SOURCES += [
-    'CreateDirectoryTask.cpp',
-    'CreateFileTask.cpp',
     'DeviceStorageFileSystem.cpp',
     'Directory.cpp',
     'FileSystemBase.cpp',
     'FileSystemPermissionRequest.cpp',
     'FileSystemRequestParent.cpp',
     'FileSystemTaskBase.cpp',
     'FileSystemUtils.cpp',
     'GetDirectoryListingTask.cpp',
--- a/dom/webidl/Directory.webidl
+++ b/dom/webidl/Directory.webidl
@@ -22,35 +22,16 @@
 interface Directory {
   /*
    * The leaf name of the directory.
    */
   [Throws]
   readonly attribute DOMString name;
 
   /*
-   * Creates a new file or replaces an existing file with given data. The file
-   * should be a descendent of current directory.
-   *
-   * @param path The relative path of the new file to current directory.
-   * @param options It has two optional properties, 'ifExists' and 'data'.
-   * If 'ifExists' is 'fail' and the path already exists, createFile must fail;
-   * If 'ifExists' is 'replace', the path already exists, and is a file, create
-   * a new file to replace the existing one;
-   * If 'ifExists' is 'replace', the path already exists, but is a directory,
-   * createFile must fail.
-   * Otherwise, if no other error occurs, createFile will create a new file.
-   * The 'data' property contains the new file's content.
-   * @return If succeeds, the promise is resolved with the new created
-   * File object. Otherwise, rejected with a DOM error.
-   */
-  [Func="mozilla::dom::Directory::DeviceStorageEnabled", NewObject]
-  Promise<File> createFile(DOMString path, optional CreateFileOptions options);
-
-  /*
    * Creates a descendent directory. This method will create any intermediate
    * directories specified by the path segments.
    *
    * @param path The relative path of the new directory to current directory.
    * If path exists, createDirectory must fail.
    * @return If succeeds, the promise is resolved with the new created
    * Directory object. Otherwise, rejected with a DOM error.
    */
@@ -116,15 +97,8 @@ partial interface Directory {
    * Getter for the immediate children of this directory.
    */
   [Throws]
   Promise<sequence<(File or Directory)>> getFilesAndDirectories();
 
   [Throws]
   Promise<sequence<File>> getFiles(optional boolean recursiveFlag = false);
 };
-
-enum CreateIfExistsMode { "replace", "fail" };
-
-dictionary CreateFileOptions {
-  CreateIfExistsMode ifExists = "fail";
-  (DOMString or Blob or ArrayBuffer or ArrayBufferView) data;
-};