Bug 1299500 - Get rid of DeviceStorage API - part 7 - Directory::Remove, r=ehsan a=gchang
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 08 Mar 2017 20:15:45 +0100
changeset 395386 a74303464cee74022e59f84d18806e2ebf83791e
parent 395385 024b93a93726dba8f5d8f894b98fdefca2715a15
child 395387 52a3a2c64671fbecbe2b422f9b6fac858b426293
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, gchang
bugs1299500
milestone54.0a2
Bug 1299500 - Get rid of DeviceStorage API - part 7 - Directory::Remove, r=ehsan a=gchang
dom/filesystem/Directory.cpp
dom/filesystem/Directory.h
dom/filesystem/FileSystemRequestParent.cpp
dom/filesystem/PFileSystemParams.ipdlh
dom/filesystem/RemoveTask.cpp
dom/filesystem/RemoveTask.h
dom/filesystem/moz.build
dom/webidl/Directory.webidl
--- a/dom/filesystem/Directory.cpp
+++ b/dom/filesystem/Directory.cpp
@@ -5,17 +5,16 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/Directory.h"
 
 #include "FileSystemPermissionRequest.h"
 #include "GetDirectoryListingTask.h"
 #include "GetFileOrDirectoryTask.h"
 #include "GetFilesTask.h"
-#include "RemoveTask.h"
 #include "WorkerPrivate.h"
 
 #include "nsCharSeparatedTokenizer.h"
 #include "nsString.h"
 #include "mozilla/dom/DirectoryBinding.h"
 #include "mozilla/dom/FileSystemBase.h"
 #include "mozilla/dom/FileSystemUtils.h"
 #include "mozilla/dom/OSFileSystem.h"
@@ -200,86 +199,16 @@ Directory::Get(const nsAString& aPath, E
     return nullptr;
   }
 
   task->SetError(error);
   FileSystemPermissionRequest::RequestForTask(task);
   return task->GetPromise();
 }
 
-already_AddRefed<Promise>
-Directory::Remove(const StringOrFileOrDirectory& aPath, ErrorResult& aRv)
-{
-  // Only exposed for DeviceStorage.
-  MOZ_ASSERT(NS_IsMainThread());
-  return RemoveInternal(aPath, false, aRv);
-}
-
-already_AddRefed<Promise>
-Directory::RemoveDeep(const StringOrFileOrDirectory& aPath, ErrorResult& aRv)
-{
-  // Only exposed for DeviceStorage.
-  MOZ_ASSERT(NS_IsMainThread());
-  return RemoveInternal(aPath, true, aRv);
-}
-
-already_AddRefed<Promise>
-Directory::RemoveInternal(const StringOrFileOrDirectory& aPath, bool aRecursive,
-                          ErrorResult& aRv)
-{
-  // Only exposed for DeviceStorage.
-  MOZ_ASSERT(NS_IsMainThread());
-
-  nsresult error = NS_OK;
-  nsCOMPtr<nsIFile> realPath;
-
-  // Check and get the target path.
-
-  RefPtr<FileSystemBase> fs = GetFileSystem(aRv);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return nullptr;
-  }
-
-  // If this is a File
-  if (aPath.IsFile()) {
-    if (!fs->GetRealPath(aPath.GetAsFile().Impl(),
-                         getter_AddRefs(realPath))) {
-      error = NS_ERROR_DOM_SECURITY_ERR;
-    }
-
-  // If this is a string
-  } else if (aPath.IsString()) {
-    error = DOMPathToRealPath(aPath.GetAsString(), getter_AddRefs(realPath));
-
-  // Directory
-  } else {
-    MOZ_ASSERT(aPath.IsDirectory());
-    if (!fs->IsSafeDirectory(&aPath.GetAsDirectory())) {
-      error = NS_ERROR_DOM_SECURITY_ERR;
-    } else {
-      realPath = aPath.GetAsDirectory().mFile;
-    }
-  }
-
-  // The target must be a descendant of this directory.
-  if (!FileSystemUtils::IsDescendantPath(mFile, realPath)) {
-    error = NS_ERROR_DOM_FILESYSTEM_NO_MODIFICATION_ALLOWED_ERR;
-  }
-
-  RefPtr<RemoveTaskChild> task =
-    RemoveTaskChild::Create(fs, mFile, realPath, aRecursive, aRv);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return nullptr;
-  }
-
-  task->SetError(error);
-  FileSystemPermissionRequest::RequestForTask(task);
-  return task->GetPromise();
-}
-
 void
 Directory::GetPath(nsAString& aRetval, ErrorResult& aRv)
 {
   // This operation is expensive. Better to cache the result.
   if (mPath.IsEmpty()) {
     RefPtr<FileSystemBase> fs = GetFileSystem(aRv);
     if (NS_WARN_IF(aRv.Failed())) {
       return;
--- a/dom/filesystem/Directory.h
+++ b/dom/filesystem/Directory.h
@@ -56,22 +56,16 @@ public:
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   void
   GetName(nsAString& aRetval, ErrorResult& aRv);
 
   already_AddRefed<Promise>
   Get(const nsAString& aPath, ErrorResult& aRv);
 
-  already_AddRefed<Promise>
-  Remove(const StringOrFileOrDirectory& aPath, ErrorResult& aRv);
-
-  already_AddRefed<Promise>
-  RemoveDeep(const StringOrFileOrDirectory& aPath, ErrorResult& aRv);
-
   // From https://microsoftedge.github.io/directory-upload/proposal.html#directory-interface :
 
   void
   GetPath(nsAString& aRetval, ErrorResult& aRv);
 
   nsresult
   GetFullRealPath(nsAString& aPath);
 
@@ -127,20 +121,16 @@ private:
   ~Directory();
 
   /*
    * Convert relative DOM path to the absolute real path.
    */
   nsresult
   DOMPathToRealPath(const nsAString& aPath, nsIFile** aFile) const;
 
-  already_AddRefed<Promise>
-  RemoveInternal(const StringOrFileOrDirectory& aPath, bool aRecursive,
-                 ErrorResult& aRv);
-
   nsCOMPtr<nsISupports> mParent;
   RefPtr<FileSystemBase> mFileSystem;
   nsCOMPtr<nsIFile> mFile;
 
   nsString mFilters;
   nsString mPath;
 };
 
--- a/dom/filesystem/FileSystemRequestParent.cpp
+++ b/dom/filesystem/FileSystemRequestParent.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/FileSystemRequestParent.h"
 
 #include "GetDirectoryListingTask.h"
 #include "GetFileOrDirectoryTask.h"
-#include "RemoveTask.h"
 
 #include "mozilla/dom/FileSystemBase.h"
 
 namespace mozilla {
 namespace dom {
 
 FileSystemRequestParent::FileSystemRequestParent()
   : mDestroyed(false)
@@ -45,17 +44,16 @@ FileSystemRequestParent::Initialize(cons
 
   ErrorResult rv;
 
   switch (aParams.type()) {
 
     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;
     }
   }
 
   if (NS_WARN_IF(!mTask || !mFileSystem)) {
--- a/dom/filesystem/PFileSystemParams.ipdlh
+++ b/dom/filesystem/PFileSystemParams.ipdlh
@@ -40,26 +40,17 @@ struct FileSystemGetFilesParams
 };
 
 struct FileSystemGetFileOrDirectoryParams
 {
   nsString filesystem;
   nsString realPath;
 };
 
-struct FileSystemRemoveParams
-{
-  nsString filesystem;
-  nsString directory;
-  nsString targetDirectory;
-  bool recursive;
-};
-
 union FileSystemParams
 {
   FileSystemGetDirectoryListingParams;
   FileSystemGetFilesParams;
   FileSystemGetFileOrDirectoryParams;
-  FileSystemRemoveParams;
 };
 
 } // dom namespace
 } // mozilla namespace
deleted file mode 100644
--- a/dom/filesystem/RemoveTask.cpp
+++ /dev/null
@@ -1,258 +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 "RemoveTask.h"
-
-#include "mozilla/dom/File.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 "nsIFile.h"
-#include "nsStringGlue.h"
-
-namespace mozilla {
-namespace dom {
-
-/**
- * RemoveTaskChild
- */
-
-/* static */ already_AddRefed<RemoveTaskChild>
-RemoveTaskChild::Create(FileSystemBase* aFileSystem,
-                        nsIFile* aDirPath,
-                        nsIFile* aTargetPath,
-                        bool aRecursive,
-                        ErrorResult& aRv)
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-  MOZ_ASSERT(aFileSystem);
-  MOZ_ASSERT(aDirPath);
-  MOZ_ASSERT(aTargetPath);
-
-  RefPtr<RemoveTaskChild> task =
-    new RemoveTaskChild(aFileSystem, aDirPath, aTargetPath, aRecursive);
-
-  // aTargetPath can be null. In this case SetError will be called.
-
-  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();
-}
-
-RemoveTaskChild::RemoveTaskChild(FileSystemBase* aFileSystem,
-                                 nsIFile* aDirPath,
-                                 nsIFile* aTargetPath,
-                                 bool aRecursive)
-  : FileSystemTaskChildBase(aFileSystem)
-  , mDirPath(aDirPath)
-  , mTargetPath(aTargetPath)
-  , mRecursive(aRecursive)
-  , mReturnValue(false)
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-  MOZ_ASSERT(aFileSystem);
-  MOZ_ASSERT(aDirPath);
-  MOZ_ASSERT(aTargetPath);
-}
-
-RemoveTaskChild::~RemoveTaskChild()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-}
-
-already_AddRefed<Promise>
-RemoveTaskChild::GetPromise()
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-  return RefPtr<Promise>(mPromise).forget();
-}
-
-FileSystemParams
-RemoveTaskChild::GetRequestParams(const nsString& aSerializedDOMPath,
-                                  ErrorResult& aRv) const
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-  FileSystemRemoveParams param;
-  param.filesystem() = aSerializedDOMPath;
-
-  aRv = mDirPath->GetPath(param.directory());
-  if (NS_WARN_IF(aRv.Failed())) {
-    return param;
-  }
-
-  param.recursive() = mRecursive;
-
-  nsAutoString path;
-  aRv = mTargetPath->GetPath(path);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return param;
-  }
-
-  param.targetDirectory() = path;
-
-  return param;
-}
-
-void
-RemoveTaskChild::SetSuccessRequestResult(const FileSystemResponseValue& aValue,
-                                         ErrorResult& aRv)
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-
-  FileSystemBooleanResponse r = aValue;
-  mReturnValue = r.success();
-}
-
-void
-RemoveTaskChild::HandlerCallback()
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-
-  if (mFileSystem->IsShutdown()) {
-    mPromise = nullptr;
-    return;
-  }
-
-  if (HasError()) {
-    mPromise->MaybeReject(mErrorValue);
-    mPromise = nullptr;
-    return;
-  }
-
-  mPromise->MaybeResolve(mReturnValue);
-  mPromise = nullptr;
-}
-
-void
-RemoveTaskChild::GetPermissionAccessType(nsCString& aAccess) const
-{
-  aAccess.AssignLiteral(DIRECTORY_WRITE_PERMISSION);
-}
-
-/**
- * RemoveTaskParent
- */
-
-/* static */ already_AddRefed<RemoveTaskParent>
-RemoveTaskParent::Create(FileSystemBase* aFileSystem,
-                         const FileSystemRemoveParams& aParam,
-                         FileSystemRequestParent* aParent,
-                         ErrorResult& aRv)
-{
-  MOZ_ASSERT(XRE_IsParentProcess(), "Only call from parent process!");
-  AssertIsOnBackgroundThread();
-  MOZ_ASSERT(aFileSystem);
-
-  RefPtr<RemoveTaskParent> task =
-    new RemoveTaskParent(aFileSystem, aParam, aParent);
-
-  aRv = NS_NewLocalFile(aParam.directory(), true,
-                        getter_AddRefs(task->mDirPath));
-  if (NS_WARN_IF(aRv.Failed())) {
-    return nullptr;
-  }
-
-  task->mRecursive = aParam.recursive();
-
-  aRv = NS_NewLocalFile(aParam.targetDirectory(), true,
-                        getter_AddRefs(task->mTargetPath));
-  if (NS_WARN_IF(aRv.Failed())) {
-    return nullptr;
-  }
-
-  if (!FileSystemUtils::IsDescendantPath(task->mDirPath, task->mTargetPath)) {
-    aRv.Throw(NS_ERROR_DOM_FILESYSTEM_NO_MODIFICATION_ALLOWED_ERR);
-    return nullptr;
-  }
-
-  return task.forget();
-}
-
-RemoveTaskParent::RemoveTaskParent(FileSystemBase* aFileSystem,
-                                   const FileSystemRemoveParams& aParam,
-                                   FileSystemRequestParent* aParent)
-  : FileSystemTaskParentBase(aFileSystem, aParam, aParent)
-  , mRecursive(false)
-  , mReturnValue(false)
-{
-  MOZ_ASSERT(XRE_IsParentProcess(), "Only call from parent process!");
-  AssertIsOnBackgroundThread();
-  MOZ_ASSERT(aFileSystem);
-}
-
-FileSystemResponseValue
-RemoveTaskParent::GetSuccessRequestResult(ErrorResult& aRv) const
-{
-  AssertIsOnBackgroundThread();
-
-  return FileSystemBooleanResponse(mReturnValue);
-}
-
-nsresult
-RemoveTaskParent::IOWork()
-{
-  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;
-  }
-
-  MOZ_ASSERT(FileSystemUtils::IsDescendantPath(mDirPath, mTargetPath));
-
-  bool exists = false;
-  nsresult rv = mTargetPath->Exists(&exists);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  if (!exists) {
-    mReturnValue = false;
-    return NS_OK;
-  }
-
-  bool isFile = false;
-  rv = mTargetPath->IsFile(&isFile);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  if (isFile && !mFileSystem->IsSafeFile(mTargetPath)) {
-    return NS_ERROR_DOM_SECURITY_ERR;
-  }
-
-  rv = mTargetPath->Remove(mRecursive);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  mReturnValue = true;
-
-  return NS_OK;
-}
-
-void
-RemoveTaskParent::GetPermissionAccessType(nsCString& aAccess) const
-{
-  aAccess.AssignLiteral(DIRECTORY_WRITE_PERMISSION);
-}
-
-} // namespace dom
-} // namespace mozilla
deleted file mode 100644
--- a/dom/filesystem/RemoveTask.h
+++ /dev/null
@@ -1,106 +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_RemoveTask_h
-#define mozilla_dom_RemoveTask_h
-
-#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,
-         nsIFile* aTargetPath,
-         bool aRecursive,
-         ErrorResult& aRv);
-
-  virtual
-  ~RemoveTaskChild();
-
-  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:
-  RemoveTaskChild(FileSystemBase* aFileSystem,
-                  nsIFile* aDirPath,
-                  nsIFile* aTargetPath,
-                  bool aRecursive);
-
-  RefPtr<Promise> mPromise;
-
-  // This path is the Directory::mFile.
-  nsCOMPtr<nsIFile> mDirPath;
-
-  // This is what we want to remove. mTargetPath is discendant path of mDirPath.
-  nsCOMPtr<nsIFile> mTargetPath;
-
-  bool mRecursive;
-  bool mReturnValue;
-};
-
-class RemoveTaskParent final : public FileSystemTaskParentBase
-{
-public:
-  static already_AddRefed<RemoveTaskParent>
-  Create(FileSystemBase* aFileSystem,
-         const FileSystemRemoveParams& aParam,
-         FileSystemRequestParent* aParent,
-         ErrorResult& aRv);
-
-  virtual void
-  GetPermissionAccessType(nsCString& aAccess) const override;
-
-protected:
-  virtual FileSystemResponseValue
-  GetSuccessRequestResult(ErrorResult& aRv) const override;
-
-  virtual nsresult
-  IOWork() override;
-
-private:
-  RemoveTaskParent(FileSystemBase* aFileSystem,
-                   const FileSystemRemoveParams& aParam,
-                   FileSystemRequestParent* aParent);
-
-  // This path is the Directory::mFile.
-  nsCOMPtr<nsIFile> mDirPath;
-
-  // This is what we want to remove. mTargetPath is discendant path of mDirPath.
-  nsCOMPtr<nsIFile> mTargetPath;
-
-  bool mRecursive;
-  bool mReturnValue;
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_RemoveTask_h
--- a/dom/filesystem/moz.build
+++ b/dom/filesystem/moz.build
@@ -30,17 +30,16 @@ UNIFIED_SOURCES += [
     'FileSystemRequestParent.cpp',
     'FileSystemTaskBase.cpp',
     'FileSystemUtils.cpp',
     'GetDirectoryListingTask.cpp',
     'GetFileOrDirectoryTask.cpp',
     'GetFilesHelper.cpp',
     'GetFilesTask.cpp',
     'OSFileSystem.cpp',
-    'RemoveTask.cpp',
 ]
 
 FINAL_LIBRARY = 'xul'
 
 IPDL_SOURCES += [
     'PFileSystemParams.ipdlh',
     'PFileSystemRequest.ipdl',
 ]
--- a/dom/webidl/Directory.webidl
+++ b/dom/webidl/Directory.webidl
@@ -31,44 +31,16 @@ interface Directory {
    *
    * @param path The descendent entry's relative path to current directory.
    * @return If the path exists and no error occurs, the promise is resolved
    * with a File or Directory object, depending on the entry's type. Otherwise,
    * rejected with a DOM error.
    */
   [Func="mozilla::dom::Directory::DeviceStorageEnabled", NewObject]
   Promise<(File or Directory)> get(DOMString path);
-
-  /*
-   * Deletes a file or an empty directory. The target must be a descendent of
-   * current directory.
-   * @param path If a DOM string is passed, it is the relative path of the
-   * target. Otherwise, the File or Directory object of the target should be
-   * passed.
-   * @return If the target is a non-empty directory, or if deleting the target
-   * fails, the promise is rejected with a DOM error. If the target did not
-   * exist, the promise is resolved with boolean false. If the target did exist
-   * and was successfully deleted, the promise is resolved with boolean true.
-   */
-  [Func="mozilla::dom::Directory::DeviceStorageEnabled", NewObject]
-  Promise<boolean> remove((DOMString or File or Directory) path);
-
-  /*
-   * Deletes a file or a directory recursively. The target should be a
-   * descendent of current directory.
-   * @param path If a DOM string is passed, it is the relative path of the
-   * target. Otherwise, the File or Directory object of the target should be
-   * passed.
-   * @return If the target exists, but deleting the target fails, the promise is
-   * rejected with a DOM error. If the target did not exist, the promise is
-   * resolved with boolean false. If the target did exist and was successfully
-   * deleted, the promise is resolved with boolean true.
-   */
-  [Func="mozilla::dom::Directory::DeviceStorageEnabled", NewObject]
-  Promise<boolean> removeDeep((DOMString or File or Directory) path);
 };
 
 [Exposed=(Window,Worker)]
 partial interface Directory {
   // Already defined in the main interface declaration:
   //readonly attribute DOMString name;
 
   /*