From 1eabadf7aa834e2d7730ef0942b0ee48d22782f8 Mon Sep 17 00:00:00 2001 From: Dave Hylands Date: Fri, 18 Dec 2015 17:17:46 -0800 Subject: [PATCH] Bug 1232506: Make dom/devicestorage really work with e10s. r=alchen --- dom/devicestorage/DeviceStorageStatics.cpp | 62 +++++++++++++++++++++- dom/devicestorage/DeviceStorageStatics.h | 9 ++++ dom/ipc/ContentChild.cpp | 10 ++++ dom/ipc/ContentChild.h | 1 + dom/ipc/ContentParent.cpp | 5 ++ dom/ipc/PContent.ipdl | 11 ++++ 6 files changed, 96 insertions(+), 2 deletions(-) diff --git a/dom/devicestorage/DeviceStorageStatics.cpp b/dom/devicestorage/DeviceStorageStatics.cpp index d8fed46d4ad3..5289154b60c9 100644 --- a/dom/devicestorage/DeviceStorageStatics.cpp +++ b/dom/devicestorage/DeviceStorageStatics.cpp @@ -271,6 +271,13 @@ DeviceStorageStatics::DumpDirs() 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]); @@ -278,8 +285,8 @@ DeviceStorageStatics::DumpDirs() 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 } @@ -297,6 +304,47 @@ DeviceStorageStatics::Shutdown() 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 DeviceStorageStatics::GetDir(DeviceStorageType aType) { @@ -332,6 +380,16 @@ DeviceStorageStatics::GetDir(DeviceStorageType aType) return file.forget(); } +/* static */ void +DeviceStorageStatics::GetDirPath(DeviceStorageType aType, nsString& aDirPath) +{ + aDirPath.Truncate(); + nsCOMPtr file = GetDir(aType); + if (file) { + file->GetPath(aDirPath); + } +} + /* static */ bool DeviceStorageStatics::HasOverrideRootDir() { diff --git a/dom/devicestorage/DeviceStorageStatics.h b/dom/devicestorage/DeviceStorageStatics.h index 5fa7d9b4164e..2c115ee011d0 100644 --- a/dom/devicestorage/DeviceStorageStatics.h +++ b/dom/devicestorage/DeviceStorageStatics.h @@ -8,7 +8,12 @@ #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 @@ -35,6 +40,9 @@ public: 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 GetAppsDir(); static already_AddRefed GetCrashesDir(); @@ -56,6 +64,7 @@ private: }; static already_AddRefed GetDir(DeviceStorageType aType); + static void GetDirPath(DeviceStorageType aType, nsString& aString); DeviceStorageStatics(); virtual ~DeviceStorageStatics(); diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index 5f504dfd9676..76570bf941d0 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -17,6 +17,7 @@ #include "BlobChild.h" #include "CrashReporterChild.h" #include "GeckoProfiler.h" +#include "DeviceStorageStatics.h" #include "TabChild.h" #include "HandlerServiceChild.h" @@ -2594,6 +2595,15 @@ ContentChild::RecvVolumes(nsTArray&& aVolumes) 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, diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index 05c16daf9c2f..180693ffc8d3 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -383,6 +383,7 @@ public: virtual bool RecvLastPrivateDocShellDestroyed() override; virtual bool RecvVolumes(InfallibleTArray&& aVolumes) override; + virtual bool RecvDeviceStorageAreas(const DeviceStorageAreaInfo& areaInfo) override; virtual bool RecvFilePathUpdate(const nsString& aStorageType, const nsString& aStorageName, const nsString& aPath, diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index dd7869147376..8f48c4a117ca 100755 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -30,6 +30,7 @@ #include "AudioChannelService.h" #include "BlobParent.h" #include "CrashReporterParent.h" +#include "DeviceStorageStatics.h" #include "GMPServiceParent.h" #include "HandlerServiceParent.h" #include "IHistory.h" @@ -1606,6 +1607,10 @@ ContentParent::ForwardKnownInfo() vs->GetVolumesForIPC(&volumeInfo); Unused << SendVolumes(volumeInfo); } +#else + DeviceStorageAreaInfo areaInfo; + DeviceStorageStatics::GetDeviceStorageAreasForIPC(areaInfo); + Unused << SendDeviceStorageAreas(areaInfo); #endif /* MOZ_WIDGET_GONK */ nsCOMPtr systemMessenger = diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 077a020bc0cd..68ceb04c9e3a 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -364,6 +364,15 @@ struct VolumeInfo { bool isHotSwappable; }; +struct DeviceStorageAreaInfo { + nsString music; + nsString pictures; + nsString videos; + nsString sdcard; + nsString apps; + nsString crashes; +}; + struct ClipboardCapabilities { bool supportsSelectionClipboard; bool supportsFindClipboard; @@ -595,6 +604,8 @@ child: Volumes(VolumeInfo[] volumes); + DeviceStorageAreas(DeviceStorageAreaInfo areaInfo); + FlushMemory(nsString reason); GarbageCollect();