Bug 1173320 - patch 2/8 - Proper naming for the FileSystem path serialization, r=smaug
☠☠ backed out by de7baace275a ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Sat, 19 Mar 2016 22:29:46 +0100
changeset 289571 f1a965c2f7969c8121e313226792de83efacd160
parent 289570 176128ba757f02042c701813352a4120bbd77660
child 289572 fb298010e12ee2e6ce20d83775563dbdd30965bc
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1173320
milestone48.0a1
Bug 1173320 - patch 2/8 - Proper naming for the FileSystem path serialization, r=smaug
dom/filesystem/DeviceStorageFileSystem.cpp
dom/filesystem/DeviceStorageFileSystem.h
dom/filesystem/FileSystemBase.cpp
dom/filesystem/FileSystemBase.h
dom/filesystem/FileSystemRequestParent.cpp
dom/filesystem/FileSystemTaskBase.cpp
dom/filesystem/GetDirectoryListingTask.cpp
dom/filesystem/GetFileOrDirectoryTask.cpp
dom/filesystem/OSFileSystem.cpp
dom/filesystem/OSFileSystem.h
--- a/dom/filesystem/DeviceStorageFileSystem.cpp
+++ b/dom/filesystem/DeviceStorageFileSystem.cpp
@@ -26,22 +26,16 @@ DeviceStorageFileSystem::DeviceStorageFi
   const nsAString& aStorageName)
   : mWindowId(0)
 {
   MOZ_ASSERT(NS_IsMainThread(), "Only call on main thread!");
 
   mStorageType = aStorageType;
   mStorageName = aStorageName;
 
-  // Generate the string representation of the file system.
-  mString.AppendLiteral("devicestorage-");
-  mString.Append(mStorageType);
-  mString.Append('-');
-  mString.Append(mStorageName);
-
   mRequiresPermissionChecks =
     !mozilla::Preferences::GetBool("device.storage.prompt.testing", false);
 
   // Get the permission name required to access the file system.
   nsresult rv =
     DeviceStorageTypeChecker::GetPermissionForType(mStorageType, mPermission);
   NS_WARN_IF(NS_FAILED(rv));
 
@@ -135,14 +129,30 @@ DeviceStorageFileSystem::IsSafeDirectory
 
   ErrorResult rv;
   RefPtr<FileSystemBase> fs = aDir->GetFileSystem(rv);
   if (NS_WARN_IF(rv.Failed())) {
     rv.SuppressException();
     return false;
   }
 
+  nsAutoString fsSerialization;
+  fs->SerializeDOMPath(fsSerialization);
+
+  nsAutoString thisSerialization;
+  SerializeDOMPath(thisSerialization);
+
   // Check if the given directory is from this storage.
-  return fs->ToString() == mString;
+  return fsSerialization == thisSerialization;
+}
+
+void
+DeviceStorageFileSystem::SerializeDOMPath(nsAString& aString) const
+{
+  // Generate the string representation of the file system.
+  aString.AssignLiteral("devicestorage-");
+  aString.Append(mStorageType);
+  aString.Append('-');
+  aString.Append(mStorageName);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/filesystem/DeviceStorageFileSystem.h
+++ b/dom/filesystem/DeviceStorageFileSystem.h
@@ -36,16 +36,20 @@ public:
   virtual void
   GetRootName(nsAString& aRetval) const override;
 
   virtual bool
   IsSafeFile(nsIFile* aFile) const override;
 
   virtual bool
   IsSafeDirectory(Directory* aDir) const override;
+
+  virtual void
+  SerializeDOMPath(nsAString& aSerializedString) const override;
+
 private:
   virtual
   ~DeviceStorageFileSystem();
 
   nsString mStorageType;
   nsString mStorageName;
 
   uint64_t mWindowId;
--- a/dom/filesystem/FileSystemBase.cpp
+++ b/dom/filesystem/FileSystemBase.cpp
@@ -10,17 +10,17 @@
 #include "nsCharSeparatedTokenizer.h"
 #include "OSFileSystem.h"
 
 namespace mozilla {
 namespace dom {
 
 // static
 already_AddRefed<FileSystemBase>
-FileSystemBase::FromString(const nsAString& aString)
+FileSystemBase::DeserializeDOMPath(const nsAString& aString)
 {
   if (StringBeginsWith(aString, NS_LITERAL_STRING("devicestorage-"))) {
     // The string representation of devicestorage file system is of the format:
     // devicestorage-StorageType-StorageName
 
     nsCharSeparatedTokenizer tokenizer(aString, char16_t('-'));
     tokenizer.nextToken();
 
@@ -33,16 +33,17 @@ FileSystemBase::FromString(const nsAStri
     if (tokenizer.hasMoreTokens()) {
       storageName = tokenizer.nextToken();
     }
 
     RefPtr<DeviceStorageFileSystem> f =
       new DeviceStorageFileSystem(storageType, storageName);
     return f.forget();
   }
+
   return RefPtr<OSFileSystem>(new OSFileSystem(aString)).forget();
 }
 
 FileSystemBase::FileSystemBase()
   : mShutdown(false)
   , mRequiresPermissionChecks(true)
 {
 }
--- a/dom/filesystem/FileSystemBase.h
+++ b/dom/filesystem/FileSystemBase.h
@@ -20,29 +20,26 @@ class Directory;
 
 class FileSystemBase
 {
   NS_INLINE_DECL_REFCOUNTING(FileSystemBase)
 public:
 
   // Create file system object from its string representation.
   static already_AddRefed<FileSystemBase>
-  FromString(const nsAString& aString);
+  DeserializeDOMPath(const nsAString& aString);
 
   FileSystemBase();
 
   virtual void
   Shutdown();
 
-  // Get the string representation of the file system.
-  const nsString&
-  ToString() const
-  {
-    return mString;
-  }
+  // SerializeDOMPath the FileSystem to string.
+  virtual void
+  SerializeDOMPath(nsAString& aOutput) const = 0;
 
   virtual nsPIDOMWindowInner*
   GetWindow() const;
 
   /**
    * Create nsIFile object from the given real path (absolute DOM path).
    */
   already_AddRefed<nsIFile>
@@ -105,19 +102,16 @@ protected:
   // the OS directory that acts as the root of this OSFileSystem).
   // Only available in the parent process.
   // In the child process, we don't use it and its value should be empty.
   nsString mLocalRootPath;
 
   // The same, but with path separators normalized to "/".
   nsString mNormalizedLocalRootPath;
 
-  // The string representation of the file system.
-  nsString mString;
-
   bool mShutdown;
 
   // The permission name required to access the file system.
   nsCString mPermission;
 
   bool mRequiresPermissionChecks;
 };
 
--- a/dom/filesystem/FileSystemRequestParent.cpp
+++ b/dom/filesystem/FileSystemRequestParent.cpp
@@ -23,17 +23,17 @@ FileSystemRequestParent::FileSystemReque
 
 FileSystemRequestParent::~FileSystemRequestParent()
 {
 }
 
 #define FILESYSTEM_REQUEST_PARENT_DISPATCH_ENTRY(name)                         \
     case FileSystemParams::TFileSystem##name##Params: {                        \
       const FileSystem##name##Params& p = aParams;                             \
-      mFileSystem = FileSystemBase::FromString(p.filesystem());                \
+      mFileSystem = FileSystemBase::DeserializeDOMPath(p.filesystem());        \
       task = name##Task::Create(mFileSystem, p, this, rv);                     \
       if (NS_WARN_IF(rv.Failed())) {                                           \
         return false;                                                          \
       }                                                                        \
       break;                                                                   \
     }
 
 bool
--- a/dom/filesystem/FileSystemTaskBase.cpp
+++ b/dom/filesystem/FileSystemTaskBase.cpp
@@ -101,18 +101,21 @@ FileSystemTaskBase::Start()
     return;
   }
 
   // Run in child process.
   if (mFileSystem->IsShutdown()) {
     return;
   }
 
+  nsAutoString serialization;
+  mFileSystem->SerializeDOMPath(serialization);
+
   ErrorResult rv;
-  FileSystemParams params = GetRequestParams(mFileSystem->ToString(), rv);
+  FileSystemParams params = GetRequestParams(serialization, rv);
   if (NS_WARN_IF(rv.Failed())) {
     return;
   }
 
   // Retain a reference so the task object isn't deleted without IPDL's
   // knowledge. The reference will be released by
   // mozilla::dom::ContentChild::DeallocPFileSystemRequestChild.
   NS_ADDREF_THIS();
--- a/dom/filesystem/GetDirectoryListingTask.cpp
+++ b/dom/filesystem/GetDirectoryListingTask.cpp
@@ -65,17 +65,17 @@ GetDirectoryListingTask::Create(FileSyst
 
   NS_ConvertUTF16toUTF8 path(aParam.realPath());
   aRv = NS_NewNativeLocalFile(path, true, getter_AddRefs(task->mTargetPath));
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   task->mType = aParam.isRoot()
-                  ? Directory::eDOMRootDirectory : Directory::eNotRootDirectory;
+                  ? Directory::eDOMRootDirectory : Directory::eNotDOMRootDirectory;
   return task.forget();
 }
 
 GetDirectoryListingTask::GetDirectoryListingTask(FileSystemBase* aFileSystem,
                                                  nsIFile* aTargetPath,
                                                  Directory::DirectoryType aType,
                                                  const nsAString& aFilters)
   : FileSystemTaskBase(aFileSystem)
@@ -210,17 +210,17 @@ GetDirectoryListingTask::Work()
 
   bool exists;
   nsresult rv = mTargetPath->Exists(&exists);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (!exists) {
-    if (mType == Directory::eNotRootDirectory) {
+    if (mType == Directory::eNotDOMRootDirectory) {
       return NS_ERROR_DOM_FILE_NOT_FOUND_ERR;
     }
 
     // If the root directory doesn't exit, create it.
     rv = mTargetPath->Create(nsIFile::DIRECTORY_TYPE, 0777);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
@@ -385,17 +385,17 @@ GetDirectoryListingTask::HandlerCallback
       if (NS_WARN_IF(NS_FAILED(rv))) {
         mPromise->MaybeReject(rv);
         mPromise = nullptr;
         return;
       }
 
       RefPtr<Directory> directory = Directory::Create(mFileSystem->GetWindow(),
                                                       directoryPath,
-                                                      Directory::eNotRootDirectory,
+                                                      Directory::eNotDOMRootDirectory,
                                                       mFileSystem);
       MOZ_ASSERT(directory);
 
       // Propogate mFilter onto sub-Directory object:
       directory->SetContentFilters(mFilters);
       listing[i].SetAsDirectory() = directory;
     } else {
       MOZ_ASSERT(mTargetData[i].mType == Directory::BlobImplOrDirectoryPath::eBlobImpl);
--- a/dom/filesystem/GetFileOrDirectoryTask.cpp
+++ b/dom/filesystem/GetFileOrDirectoryTask.cpp
@@ -64,17 +64,17 @@ GetFileOrDirectoryTask::Create(FileSyste
 
   NS_ConvertUTF16toUTF8 path(aParam.realPath());
   aRv = NS_NewNativeLocalFile(path, true, getter_AddRefs(task->mTargetPath));
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   task->mType = aParam.isRoot()
-                  ? Directory::eDOMRootDirectory : Directory::eNotRootDirectory;
+                  ? Directory::eDOMRootDirectory : Directory::eNotDOMRootDirectory;
   return task.forget();
 }
 
 GetFileOrDirectoryTask::GetFileOrDirectoryTask(FileSystemBase* aFileSystem,
                                                nsIFile* aTargetPath,
                                                Directory::DirectoryType aType,
                                                bool aDirectoryOnly)
   : FileSystemTaskBase(aFileSystem)
@@ -195,17 +195,17 @@ GetFileOrDirectoryTask::Work()
   // Whether we want to get the root directory.
   bool exists;
   nsresult rv = mTargetPath->Exists(&exists);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (!exists) {
-    if (mType == Directory::eNotRootDirectory) {
+    if (mType == Directory::eNotDOMRootDirectory) {
       return NS_ERROR_DOM_FILE_NOT_FOUND_ERR;
     }
 
     // If the root directory doesn't exit, create it.
     rv = mTargetPath->Create(nsIFile::DIRECTORY_TYPE, 0777);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
--- a/dom/filesystem/OSFileSystem.cpp
+++ b/dom/filesystem/OSFileSystem.cpp
@@ -22,18 +22,16 @@ OSFileSystem::OSFileSystem(const nsAStri
   mLocalRootPath = aRootDir;
   FileSystemUtils::LocalPathToNormalizedPath(mLocalRootPath,
                                              mNormalizedLocalRootPath);
 
   // Non-mobile devices don't have the concept of separate permissions to
   // access different parts of devices storage like Pictures, or Videos, etc.
   mRequiresPermissionChecks = false;
 
-  mString = mLocalRootPath;
-
 #ifdef DEBUG
   mPermission.AssignLiteral("never-used");
 #endif
 }
 
 void
 OSFileSystem::Init(nsPIDOMWindowInner* aWindow)
 {
@@ -84,10 +82,16 @@ OSFileSystem::Unlink()
 
 void
 OSFileSystem::Traverse(nsCycleCollectionTraversalCallback &cb)
 {
   OSFileSystem* tmp = this;
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow);
 }
 
+void
+OSFileSystem::SerializeDOMPath(nsAString& aOutput) const
+{
+  aOutput = mLocalRootPath;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/filesystem/OSFileSystem.h
+++ b/dom/filesystem/OSFileSystem.h
@@ -29,16 +29,19 @@ public:
   GetRootName(nsAString& aRetval) const override;
 
   virtual bool
   IsSafeFile(nsIFile* aFile) const override;
 
   virtual bool
   IsSafeDirectory(Directory* aDir) const override;
 
+  virtual void
+  SerializeDOMPath(nsAString& aOutput) const override;
+
   // CC methods
   virtual void Unlink() override;
   virtual void Traverse(nsCycleCollectionTraversalCallback &cb) override;
 
 private:
   virtual ~OSFileSystem() {}
 
    nsCOMPtr<nsPIDOMWindowInner> mWindow;