Bug 1299500 - Get rid of DeviceStorage API - part 6 - Directory::CreateDirectory, r=ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 08 Mar 2017 20:15:45 +0100
changeset 346614 f6e90b7c442fc8407f1df1b7beec10ae6d49dc42
parent 346613 a8670bee71a54d0f91874e653c9f4d6b7c401792
child 346615 f28b200fd93d6c83400df490b8a1244ef63b1f9f
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 6 - Directory::CreateDirectory, r=ehsan
dom/filesystem/CreateDirectoryTask.cpp
dom/filesystem/CreateDirectoryTask.h
dom/filesystem/Directory.cpp
dom/filesystem/Directory.h
dom/filesystem/FileSystemRequestParent.cpp
dom/filesystem/PFileSystemParams.ipdlh
dom/webidl/Directory.webidl
deleted file mode 100644
--- a/dom/filesystem/CreateDirectoryTask.cpp
+++ /dev/null
@@ -1,220 +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 "CreateDirectoryTask.h"
-
-#include "mozilla/dom/Directory.h"
-#include "mozilla/dom/FileSystemBase.h"
-#include "mozilla/dom/FileSystemUtils.h"
-#include "mozilla/dom/PFileSystemParams.h"
-#include "mozilla/dom/Promise.h"
-#include "mozilla/ipc/BackgroundParent.h"
-#include "nsIFile.h"
-#include "nsStringGlue.h"
-
-namespace mozilla {
-
-using namespace ipc;
-
-namespace dom {
-
-/**
- * CreateDirectoryTaskChild
- */
-
-/* static */ already_AddRefed<CreateDirectoryTaskChild>
-CreateDirectoryTaskChild::Create(FileSystemBase* aFileSystem,
-                                 nsIFile* aTargetPath,
-                                 ErrorResult& aRv)
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-  MOZ_ASSERT(aFileSystem);
-
-  RefPtr<CreateDirectoryTaskChild> task =
-    new CreateDirectoryTaskChild(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)) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return nullptr;
-  }
-
-  task->mPromise = Promise::Create(globalObject, aRv);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return nullptr;
-  }
-
-  return task.forget();
-}
-
-CreateDirectoryTaskChild::CreateDirectoryTaskChild(FileSystemBase* aFileSystem,
-                                                   nsIFile* aTargetPath)
-  : FileSystemTaskChildBase(aFileSystem)
-  , mTargetPath(aTargetPath)
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-  MOZ_ASSERT(aFileSystem);
-}
-
-CreateDirectoryTaskChild::~CreateDirectoryTaskChild()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-}
-
-already_AddRefed<Promise>
-CreateDirectoryTaskChild::GetPromise()
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-  return RefPtr<Promise>(mPromise).forget();
-}
-
-FileSystemParams
-CreateDirectoryTaskChild::GetRequestParams(const nsString& aSerializedDOMPath,
-                                           ErrorResult& aRv) const
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-
-  nsAutoString path;
-  aRv = mTargetPath->GetPath(path);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return FileSystemCreateDirectoryParams();
-  }
-
-  return FileSystemCreateDirectoryParams(aSerializedDOMPath, path);
-}
-
-void
-CreateDirectoryTaskChild::SetSuccessRequestResult(const FileSystemResponseValue& aValue,
-                                                  ErrorResult& aRv)
-{
-  MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
-
-  const FileSystemDirectoryResponse& r =
-    aValue.get_FileSystemDirectoryResponse();
-
-  aRv = NS_NewLocalFile(r.realPath(), true, getter_AddRefs(mTargetPath));
-  NS_WARNING_ASSERTION(!aRv.Failed(), "NS_NewLocalFile failed");
-}
-
-void
-CreateDirectoryTaskChild::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<Directory> dir = Directory::Create(mFileSystem->GetParentObject(),
-                                            mTargetPath, mFileSystem);
-  MOZ_ASSERT(dir);
-
-  mPromise->MaybeResolve(dir);
-  mPromise = nullptr;
-}
-
-void
-CreateDirectoryTaskChild::GetPermissionAccessType(nsCString& aAccess) const
-{
-  aAccess.AssignLiteral(DIRECTORY_CREATE_PERMISSION);
-}
-
-/**
- * CreateDirectoryTaskParent
- */
-
-/* static */ already_AddRefed<CreateDirectoryTaskParent>
-CreateDirectoryTaskParent::Create(FileSystemBase* aFileSystem,
-                                  const FileSystemCreateDirectoryParams& aParam,
-                                  FileSystemRequestParent* aParent,
-                                  ErrorResult& aRv)
-{
-  MOZ_ASSERT(XRE_IsParentProcess(), "Only call from parent process!");
-  AssertIsOnBackgroundThread();
-  MOZ_ASSERT(aFileSystem);
-
-  RefPtr<CreateDirectoryTaskParent> task =
-    new CreateDirectoryTaskParent(aFileSystem, aParam, aParent);
-
-  aRv = NS_NewLocalFile(aParam.realPath(), true,
-                        getter_AddRefs(task->mTargetPath));
-  if (NS_WARN_IF(aRv.Failed())) {
-    return nullptr;
-  }
-
-  return task.forget();
-}
-
-CreateDirectoryTaskParent::CreateDirectoryTaskParent(FileSystemBase* aFileSystem,
-                                                     const FileSystemCreateDirectoryParams& aParam,
-                                                     FileSystemRequestParent* aParent)
-  : FileSystemTaskParentBase(aFileSystem, aParam, aParent)
-{
-  MOZ_ASSERT(XRE_IsParentProcess(), "Only call from parent process!");
-  AssertIsOnBackgroundThread();
-  MOZ_ASSERT(aFileSystem);
-}
-
-FileSystemResponseValue
-CreateDirectoryTaskParent::GetSuccessRequestResult(ErrorResult& aRv) const
-{
-  AssertIsOnBackgroundThread();
-
-  nsAutoString path;
-  aRv = mTargetPath->GetPath(path);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return FileSystemDirectoryResponse();
-  }
-
-  return FileSystemDirectoryResponse(path);
-}
-
-nsresult
-CreateDirectoryTaskParent::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;
-  }
-
-  bool fileExists;
-  nsresult rv = mTargetPath->Exists(&fileExists);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  if (fileExists) {
-    return NS_ERROR_DOM_FILESYSTEM_PATH_EXISTS_ERR;
-  }
-
-  rv = mTargetPath->Create(nsIFile::DIRECTORY_TYPE, 0770);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return rv;
-  }
-
-  return NS_OK;
-}
-
-void
-CreateDirectoryTaskParent::GetPermissionAccessType(nsCString& aAccess) const
-{
-  aAccess.AssignLiteral(DIRECTORY_CREATE_PERMISSION);
-}
-
-} // namespace dom
-} // namespace mozilla
deleted file mode 100644
--- a/dom/filesystem/CreateDirectoryTask.h
+++ /dev/null
@@ -1,87 +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_CreateDirectoryTask_h
-#define mozilla_dom_CreateDirectoryTask_h
-
-#include "mozilla/dom/FileSystemTaskBase.h"
-#include "mozilla/ErrorResult.h"
-
-namespace mozilla {
-namespace dom {
-
-class FileSystemCreateDirectoryParams;
-class Promise;
-
-class CreateDirectoryTaskChild final : public FileSystemTaskChildBase
-{
-public:
-  static already_AddRefed<CreateDirectoryTaskChild>
-  Create(FileSystemBase* aFileSystem,
-         nsIFile* aTargetPath,
-         ErrorResult& aRv);
-
-  virtual
-  ~CreateDirectoryTaskChild();
-
-  already_AddRefed<Promise>
-  GetPromise();
-
-  virtual void
-  GetPermissionAccessType(nsCString& aAccess) const override;
-
-  virtual void
-  HandlerCallback() override;
-
-protected:
-  virtual FileSystemParams
-  GetRequestParams(const nsString& aSerializedDOMPath,
-                   ErrorResult& aRv) const override;
-
-  virtual void
-  SetSuccessRequestResult(const FileSystemResponseValue& aValue,
-                          ErrorResult& aRv) override;
-
-
-private:
-  CreateDirectoryTaskChild(FileSystemBase* aFileSystem,
-                           nsIFile* aTargetPath);
-
-  RefPtr<Promise> mPromise;
-  nsCOMPtr<nsIFile> mTargetPath;
-};
-
-class CreateDirectoryTaskParent final : public FileSystemTaskParentBase
-{
-public:
-  static already_AddRefed<CreateDirectoryTaskParent>
-  Create(FileSystemBase* aFileSystem,
-         const FileSystemCreateDirectoryParams& aParam,
-         FileSystemRequestParent* aParent,
-         ErrorResult& aRv);
-
-  virtual void
-  GetPermissionAccessType(nsCString& aAccess) const override;
-
-protected:
-  virtual nsresult
-  IOWork() override;
-
-  virtual FileSystemResponseValue
-  GetSuccessRequestResult(ErrorResult& aRv) const override;
-
-private:
-  CreateDirectoryTaskParent(FileSystemBase* aFileSystem,
-                            const FileSystemCreateDirectoryParams& aParam,
-                            FileSystemRequestParent* aParent);
-
-  nsCOMPtr<nsIFile> mTargetPath;
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_CreateDirectoryTask_h
--- a/dom/filesystem/Directory.cpp
+++ b/dom/filesystem/Directory.cpp
@@ -1,38 +1,30 @@
 /* -*- 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/Directory.h"
 
-#include "CreateDirectoryTask.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"
 
-// 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
-
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(Directory)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Directory)
   if (tmp->mFileSystem) {
     tmp->mFileSystem->Unlink();
@@ -184,41 +176,16 @@ Directory::GetName(nsAString& aRetval, E
   if (NS_WARN_IF(aRv.Failed())) {
     return;
   }
 
   fs->GetDirectoryName(mFile, aRetval, aRv);
 }
 
 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));
-
-  RefPtr<FileSystemBase> fs = GetFileSystem(aRv);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return nullptr;
-  }
-
-  RefPtr<CreateDirectoryTaskChild> task =
-    CreateDirectoryTaskChild::Create(fs, realPath, aRv);
-  if (NS_WARN_IF(aRv.Failed())) {
-    return nullptr;
-  }
-
-  task->SetError(error);
-  FileSystemPermissionRequest::RequestForTask(task);
-  return task->GetPromise();
-}
-
-already_AddRefed<Promise>
 Directory::Get(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
@@ -9,23 +9,16 @@
 
 #include "mozilla/Attributes.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/dom/File.h"
 #include "nsCycleCollectionParticipant.h"
 #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
-
 namespace mozilla {
 namespace dom {
 
 class FileSystemBase;
 class Promise;
 class StringOrFileOrDirectory;
 
 class Directory final
@@ -61,19 +54,16 @@ public:
 
   virtual JSObject*
   WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   void
   GetName(nsAString& aRetval, 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);
 
   already_AddRefed<Promise>
   RemoveDeep(const StringOrFileOrDirectory& aPath, ErrorResult& aRv);
 
--- a/dom/filesystem/FileSystemRequestParent.cpp
+++ b/dom/filesystem/FileSystemRequestParent.cpp
@@ -1,16 +1,15 @@
 /* -*- 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 "GetDirectoryListingTask.h"
 #include "GetFileOrDirectoryTask.h"
 #include "RemoveTask.h"
 
 #include "mozilla/dom/FileSystemBase.h"
 
 namespace mozilla {
 namespace dom {
@@ -43,17 +42,16 @@ bool
 FileSystemRequestParent::Initialize(const FileSystemParams& aParams)
 {
   AssertIsOnBackgroundThread();
 
   ErrorResult rv;
 
   switch (aParams.type()) {
 
-    FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(CreateDirectory)
     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/PFileSystemParams.ipdlh
+++ b/dom/filesystem/PFileSystemParams.ipdlh
@@ -2,22 +2,16 @@
  * 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 protocol PBlob;
 
 namespace mozilla {
 namespace dom {
 
-struct FileSystemCreateDirectoryParams
-{
-  nsString filesystem;
-  nsString realPath;
-};
-
 union FileSystemFileDataValue
 {
   uint8_t[];
   PBlob;
 };
 
 struct FileSystemGetDirectoryListingParams
 {
@@ -56,17 +50,16 @@ struct FileSystemRemoveParams
   nsString filesystem;
   nsString directory;
   nsString targetDirectory;
   bool recursive;
 };
 
 union FileSystemParams
 {
-  FileSystemCreateDirectoryParams;
   FileSystemGetDirectoryListingParams;
   FileSystemGetFilesParams;
   FileSystemGetFileOrDirectoryParams;
   FileSystemRemoveParams;
 };
 
 } // dom namespace
 } // mozilla namespace
--- a/dom/webidl/Directory.webidl
+++ b/dom/webidl/Directory.webidl
@@ -22,28 +22,16 @@
 interface Directory {
   /*
    * The leaf name of the directory.
    */
   [Throws]
   readonly attribute DOMString name;
 
   /*
-   * 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.
-   */
-  [Func="mozilla::dom::Directory::DeviceStorageEnabled", NewObject]
-  Promise<Directory> createDirectory(DOMString path);
-
-  /*
    * Gets a descendent file or directory with the given path.
    *
    * @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]