Bug 1232506: Make dom/devicestorage really work with e10s. r=alchen
☠☠ backed out by a8acaa9868df ☠ ☠
authorDave Hylands <dhylands@mozilla.com>
Fri, 18 Dec 2015 17:17:46 -0800
changeset 277093 0f2a62a45b00e3516aef29930bc4446de6ced98c
parent 277092 9e1c3b1f311cfa17e98cb09b3e29b197a1b51f07
child 277094 dda92c46bb23ea846ca288da9cf9e102347699d6
push id16724
push usercbook@mozilla.com
push dateMon, 21 Dec 2015 11:00:52 +0000
treeherderfx-team@3f3f0361567c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersalchen
bugs1232506
milestone46.0a1
Bug 1232506: Make dom/devicestorage really work with e10s. r=alchen
dom/devicestorage/DeviceStorageStatics.cpp
dom/devicestorage/DeviceStorageStatics.h
dom/ipc/ContentChild.cpp
dom/ipc/ContentChild.h
dom/ipc/ContentParent.cpp
dom/ipc/PContent.ipdl
--- a/dom/devicestorage/DeviceStorageStatics.cpp
+++ b/dom/devicestorage/DeviceStorageStatics.cpp
@@ -266,25 +266,32 @@ DeviceStorageStatics::DumpDirs()
     "pictures",
     "videos",
     "music",
     "sdcard",
     "override",
     nullptr
   };
 
+  const char* ptStr;
+  if (XRE_IsParentProcess()) {
+    ptStr = "parent";
+  } else {
+    ptStr = "child";
+  }
+
   for (uint32_t i = 0; i < TYPE_COUNT; ++i) {
     MOZ_ASSERT(storageTypes[i]);
 
     nsString path;
     if (mDirs[i]) {
       mDirs[i]->GetPath(path);
     }
-    DS_LOG_INFO("%s: '%s'",
-      storageTypes[i], NS_LossyConvertUTF16toASCII(path).get());
+    DS_LOG_INFO("(%s) %s: '%s'",
+      ptStr, storageTypes[i], NS_LossyConvertUTF16toASCII(path).get());
   }
 #endif
 }
 
 void
 DeviceStorageStatics::Shutdown()
 {
   MOZ_ASSERT(NS_IsMainThread());
@@ -292,16 +299,57 @@ DeviceStorageStatics::Shutdown()
   DS_LOG_INFO("");
 
   Preferences::RemoveObserver(this, kPrefOverrideRootDir);
   Preferences::RemoveObserver(this, kPrefTesting);
   Preferences::RemoveObserver(this, kPrefPromptTesting);
   Preferences::RemoveObserver(this, kPrefWritableName);
 }
 
+/* static */ void
+DeviceStorageStatics::GetDeviceStorageAreasForIPC(
+  DeviceStorageAreaInfo& aAreaInfo)
+{
+  MOZ_ASSERT(XRE_IsParentProcess());
+  MOZ_ASSERT(NS_IsMainThread());
+
+  InitializeDirs();
+
+  GetDirPath(TYPE_APPS,     aAreaInfo.apps());
+  GetDirPath(TYPE_CRASHES,  aAreaInfo.crashes());
+  GetDirPath(TYPE_PICTURES, aAreaInfo.pictures());
+  GetDirPath(TYPE_VIDEOS,   aAreaInfo.videos());
+  GetDirPath(TYPE_MUSIC,    aAreaInfo.music());
+  GetDirPath(TYPE_SDCARD,   aAreaInfo.sdcard());
+}
+
+/* static */ void
+DeviceStorageStatics::RecvDeviceStorageAreasFromParent(
+  const DeviceStorageAreaInfo& aAreaInfo)
+{
+  if (XRE_IsParentProcess()) {
+    // We are the parent. Therefore our info is already correct.
+    return;
+  }
+
+  StaticMutexAutoLock lock(sMutex);
+  if (NS_WARN_IF(!sInstance)) {
+    return;
+  }
+
+  NS_NewLocalFile(aAreaInfo.apps(),     true, getter_AddRefs(sInstance->mDirs[TYPE_APPS]));
+  NS_NewLocalFile(aAreaInfo.crashes(),  true, getter_AddRefs(sInstance->mDirs[TYPE_CRASHES]));
+  NS_NewLocalFile(aAreaInfo.pictures(), true, getter_AddRefs(sInstance->mDirs[TYPE_PICTURES]));
+  NS_NewLocalFile(aAreaInfo.videos(),   true, getter_AddRefs(sInstance->mDirs[TYPE_VIDEOS]));
+  NS_NewLocalFile(aAreaInfo.music(),    true, getter_AddRefs(sInstance->mDirs[TYPE_MUSIC]));
+  NS_NewLocalFile(aAreaInfo.sdcard(),   true, getter_AddRefs(sInstance->mDirs[TYPE_SDCARD]));
+
+  sInstance->mInitialized = true;
+}
+
 /* static */ already_AddRefed<nsIFile>
 DeviceStorageStatics::GetDir(DeviceStorageType aType)
 {
   MOZ_ASSERT(aType < TYPE_COUNT);
 
   StaticMutexAutoLock lock(sMutex);
   if (NS_WARN_IF(!sInstance)) {
     return nullptr;
@@ -327,16 +375,26 @@ DeviceStorageStatics::GetDir(DeviceStora
 #ifdef MOZ_WIDGET_GONK
     /* We should use volume mount points on B2G. */
     MOZ_ASSERT(!file);
 #endif
   }
   return file.forget();
 }
 
+/* static */ void
+DeviceStorageStatics::GetDirPath(DeviceStorageType aType, nsString& aDirPath)
+{
+  aDirPath.Truncate();
+  nsCOMPtr<nsIFile> file = GetDir(aType);
+  if (file) {
+    file->GetPath(aDirPath);
+  }
+}
+
 /* static */ bool
 DeviceStorageStatics::HasOverrideRootDir()
 {
   StaticMutexAutoLock lock(sMutex);
   if (NS_WARN_IF(!sInstance)) {
     return false;
   }
   return sInstance->mDirs[TYPE_OVERRIDE];
--- a/dom/devicestorage/DeviceStorageStatics.h
+++ b/dom/devicestorage/DeviceStorageStatics.h
@@ -3,17 +3,22 @@
 /* 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_devicestorage_DeviceStorageStatics_h
 #define mozilla_dom_devicestorage_DeviceStorageStatics_h
 
 #include "mozilla/Mutex.h"
+#include "mozilla/RefPtr.h"
+#include "mozilla/StaticMutex.h"
+#include "mozilla/StaticPtr.h"
+#include "nsArrayUtils.h"
 
+class nsString;
 class nsDOMDeviceStorage;
 class DeviceStorageFile;
 #ifdef MOZ_WIDGET_GONK
 class nsIVolume;
 #endif
 
 namespace mozilla {
 namespace dom {
@@ -30,16 +35,19 @@ public:
   static void AddListener(nsDOMDeviceStorage* aListener);
   static void RemoveListener(nsDOMDeviceStorage* aListener);
 
   static bool LowDiskSpace();
   static bool IsPromptTesting();
   static void GetWritableName(nsString& aName);
   static void SetWritableName(const nsAString& aName);
 
+  static void GetDeviceStorageAreasForIPC(DeviceStorageAreaInfo& aAreaInfo);
+  static void RecvDeviceStorageAreasFromParent(const DeviceStorageAreaInfo& aAreaInfo);
+
   static bool HasOverrideRootDir();
   static already_AddRefed<nsIFile> GetAppsDir();
   static already_AddRefed<nsIFile> GetCrashesDir();
   static already_AddRefed<nsIFile> GetPicturesDir();
   static already_AddRefed<nsIFile> GetVideosDir();
   static already_AddRefed<nsIFile> GetMusicDir();
   static already_AddRefed<nsIFile> GetSdcardDir();
 
@@ -51,16 +59,17 @@ private:
     TYPE_VIDEOS,
     TYPE_MUSIC,
     TYPE_SDCARD,
     TYPE_OVERRIDE,
     TYPE_COUNT
   };
 
   static already_AddRefed<nsIFile> GetDir(DeviceStorageType aType);
+  static void GetDirPath(DeviceStorageType aType, nsString& aString);
 
   DeviceStorageStatics();
   virtual ~DeviceStorageStatics();
 
   void Init();
   void InitDirs();
   void DumpDirs();
   void Shutdown();
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -12,16 +12,17 @@
 #include "nsQAppInstance.h"
 #endif
 
 #include "ContentChild.h"
 
 #include "BlobChild.h"
 #include "CrashReporterChild.h"
 #include "GeckoProfiler.h"
+#include "DeviceStorageStatics.h"
 #include "TabChild.h"
 #include "HandlerServiceChild.h"
 
 #include "mozilla/Attributes.h"
 #include "mozilla/LookAndFeel.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/ProcessHangMonitorIPC.h"
 #include "mozilla/devtools/HeapSnapshotTempFileHelperChild.h"
@@ -2590,16 +2591,25 @@ ContentChild::RecvVolumes(nsTArray<Volum
     if (vs) {
         vs->RecvVolumesFromParent(aVolumes);
     }
 #endif
     return true;
 }
 
 bool
+ContentChild::RecvDeviceStorageAreas(const DeviceStorageAreaInfo& areaInfo)
+{
+#if !defined(MOZ_WIDGET_GONK)
+    DeviceStorageStatics::RecvDeviceStorageAreasFromParent(areaInfo);
+#endif
+    return true;
+}
+
+bool
 ContentChild::RecvFilePathUpdate(const nsString& aStorageType,
                                  const nsString& aStorageName,
                                  const nsString& aPath,
                                  const nsCString& aReason)
 {
     if (nsDOMDeviceStorage::InstanceCount() == 0) {
         // No device storage instances in this process. Don't try and
         // and create a DeviceStorageFile since it will fail.
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -378,16 +378,17 @@ public:
     virtual bool RecvAppInfo(const nsCString& version, const nsCString& buildID,
                              const nsCString& name, const nsCString& UAName,
                              const nsCString& ID, const nsCString& vendor) override;
     virtual bool RecvAppInit() override;
 
     virtual bool RecvLastPrivateDocShellDestroyed() override;
 
     virtual bool RecvVolumes(InfallibleTArray<VolumeInfo>&& aVolumes) override;
+    virtual bool RecvDeviceStorageAreas(const DeviceStorageAreaInfo& areaInfo) override;
     virtual bool RecvFilePathUpdate(const nsString& aStorageType,
                                     const nsString& aStorageName,
                                     const nsString& aPath,
                                     const nsCString& aReason) override;
     virtual bool RecvFileSystemUpdate(const nsString& aFsName,
                                       const nsString& aVolumeName,
                                       const int32_t& aState,
                                       const int32_t& aMountGeneration,
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -25,16 +25,17 @@
 
 #include <set>
 
 #include "mozilla/a11y/PDocAccessible.h"
 #include "AppProcessChecker.h"
 #include "AudioChannelService.h"
 #include "BlobParent.h"
 #include "CrashReporterParent.h"
+#include "DeviceStorageStatics.h"
 #include "GMPServiceParent.h"
 #include "HandlerServiceParent.h"
 #include "IHistory.h"
 #include "imgIContainer.h"
 #include "mozIApplication.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/CSSStyleSheet.h"
 #include "mozilla/DataStorage.h"
@@ -1601,16 +1602,20 @@ ContentParent::ForwardKnownInfo()
     }
 #ifdef MOZ_WIDGET_GONK
     InfallibleTArray<VolumeInfo> volumeInfo;
     RefPtr<nsVolumeService> vs = nsVolumeService::GetSingleton();
     if (vs) {
         vs->GetVolumesForIPC(&volumeInfo);
         Unused << SendVolumes(volumeInfo);
     }
+#else
+    DeviceStorageAreaInfo areaInfo;
+    DeviceStorageStatics::GetDeviceStorageAreasForIPC(areaInfo);
+    Unused << SendDeviceStorageAreas(areaInfo);
 #endif /* MOZ_WIDGET_GONK */
 
     nsCOMPtr<nsISystemMessagesInternal> systemMessenger =
         do_GetService("@mozilla.org/system-message-internal;1");
     if (systemMessenger && !mIsForBrowser) {
         nsCOMPtr<nsIURI> manifestURI;
         nsresult rv = NS_NewURI(getter_AddRefs(manifestURI), mAppManifestURL);
         if (NS_SUCCEEDED(rv)) {
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -359,16 +359,25 @@ struct VolumeInfo {
   bool isSharing;
   bool isFormatting;
   bool isFake;
   bool isUnmounting;
   bool isRemovable;
   bool isHotSwappable;
 };
 
+struct DeviceStorageAreaInfo {
+  nsString music;
+  nsString pictures;
+  nsString videos;
+  nsString sdcard;
+  nsString apps;
+  nsString crashes;
+};
+
 struct ClipboardCapabilities {
   bool supportsSelectionClipboard;
   bool supportsFindClipboard;
 };
 
 union MaybeFileDesc {
     FileDescriptor;
     void_t;
@@ -590,16 +599,18 @@ child:
 
     // nsIPermissionManager messages
     AddPermission(Permission permission);
 
     ScreenSizeChanged(IntSize size);
 
     Volumes(VolumeInfo[] volumes);
 
+    DeviceStorageAreas(DeviceStorageAreaInfo areaInfo);
+
     FlushMemory(nsString reason);
 
     GarbageCollect();
     CycleCollect();
 
     /**
      * Start accessibility engine in content process.
      */