Bug 1232506: Make dom/devicestorage really work with e10s. r=alchen

This commit is contained in:
Dave Hylands 2015-12-18 17:17:46 -08:00
parent 3fd1ae8a41
commit 1eabadf7aa
6 changed files with 96 additions and 2 deletions

View File

@ -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<nsIFile>
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<nsIFile> file = GetDir(aType);
if (file) {
file->GetPath(aDirPath);
}
}
/* static */ bool
DeviceStorageStatics::HasOverrideRootDir()
{

View File

@ -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<nsIFile> GetAppsDir();
static already_AddRefed<nsIFile> GetCrashesDir();
@ -56,6 +64,7 @@ private:
};
static already_AddRefed<nsIFile> GetDir(DeviceStorageType aType);
static void GetDirPath(DeviceStorageType aType, nsString& aString);
DeviceStorageStatics();
virtual ~DeviceStorageStatics();

View File

@ -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<VolumeInfo>&& 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,

View File

@ -383,6 +383,7 @@ public:
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,

View File

@ -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<nsISystemMessagesInternal> systemMessenger =

View File

@ -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();