Bug 1204618 - Add a field to the DeviceStorage object holding the low-disk-space status. r=dhylands, r=bzbarsky

This commit is contained in:
Gabriele Svelto 2015-09-16 22:29:56 +02:00
parent 56f195af33
commit 1eb62ca96c
5 changed files with 38 additions and 13 deletions

View File

@ -249,6 +249,7 @@ public:
bool CanBeFormatted();
bool CanBeShared();
bool IsRemovable();
bool LowDiskSpace();
bool Default();
void GetStorageName(nsAString& aStorageName);

View File

@ -72,6 +72,7 @@ DeviceStorageStatics::InitializeDirs()
DeviceStorageStatics::DeviceStorageStatics()
: mInitialized(false)
, mPromptTesting(false)
, mLowDiskSpace(false)
{
DS_LOG_INFO("");
}
@ -358,6 +359,16 @@ DeviceStorageStatics::IsPromptTesting()
return sInstance->mPromptTesting;
}
/* static */ bool
DeviceStorageStatics::LowDiskSpace()
{
StaticMutexAutoLock lock(sMutex);
if (NS_WARN_IF(!sInstance)) {
return false;
}
return sInstance->mLowDiskSpace;
}
/* static */ void
DeviceStorageStatics::GetWritableName(nsString& aName)
{
@ -605,27 +616,29 @@ DeviceStorageStatics::Observe(nsISupports* aSubject,
}
if (!strcmp(aTopic, kDiskSpaceWatcher)) {
// 'disk-space-watcher' notifications are sent when there is a modification
// of a file in a specific location while a low device storage situation
// exists or after recovery of a low storage situation. For Firefox OS,
// these notifications are specific for apps storage.
bool lowDiskSpace = false;
if (!NS_strcmp(aData, MOZ_UTF16("full"))) {
lowDiskSpace = true;
} else if (NS_strcmp(aData, MOZ_UTF16("free"))) {
return NS_OK;
}
StaticMutexAutoLock lock(sMutex);
if (NS_WARN_IF(!sInstance)) {
return NS_OK;
}
// 'disk-space-watcher' notifications are sent when there is a modification
// of a file in a specific location while a low device storage situation
// exists or after recovery of a low storage situation. For Firefox OS,
// these notifications are specific for apps storage.
if (!NS_strcmp(aData, MOZ_UTF16("full"))) {
sInstance->mLowDiskSpace = true;
} else if (!NS_strcmp(aData, MOZ_UTF16("free"))) {
sInstance->mLowDiskSpace = false;
} else {
return NS_OK;
}
uint32_t i = mListeners.Length();
DS_LOG_INFO("disk space %d (%u)", lowDiskSpace, i);
DS_LOG_INFO("disk space %d (%u)", sInstance->mLowDiskSpace, i);
while (i > 0) {
--i;
mListeners[i]->OnDiskSpaceWatcher(lowDiskSpace);
mListeners[i]->OnDiskSpaceWatcher(sInstance->mLowDiskSpace);
}
return NS_OK;
}

View File

@ -30,6 +30,7 @@ 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);
@ -92,6 +93,7 @@ private:
bool mInitialized;
bool mPromptTesting;
bool mLowDiskSpace;
nsString mWritableName;
static StaticRefPtr<DeviceStorageStatics> sInstance;

View File

@ -3374,6 +3374,12 @@ nsDOMDeviceStorage::IsRemovable()
return mIsRemovable;
}
bool
nsDOMDeviceStorage::LowDiskSpace()
{
return DeviceStorageStatics::LowDiskSpace();
}
already_AddRefed<Promise>
nsDOMDeviceStorage::GetRoot(ErrorResult& aRv)
{

View File

@ -86,6 +86,9 @@ interface DeviceStorage : EventTarget {
// Indicates if the storage area denoted by storageName is removable
readonly attribute boolean isRemovable;
// True if the storage area is close to being full
readonly attribute boolean lowDiskSpace;
[NewObject]
// XXXbz what type does this really return?
Promise<any> getRoot();