зеркало из https://github.com/mozilla/gecko-dev.git
Bug 861894 - Avoid apps to schedule new offline cache downloads while device free space is low. r=honzab
This commit is contained in:
Родитель
aea65f6983
Коммит
ee50f5e46e
|
@ -1778,6 +1778,16 @@ nsOfflineCacheUpdate::Begin()
|
|||
|
||||
mItemsInProgress = 0;
|
||||
|
||||
if (mState == STATE_CANCELLED) {
|
||||
nsRefPtr<nsRunnableMethod<nsOfflineCacheUpdate> > errorNotification =
|
||||
NS_NewRunnableMethod(this,
|
||||
&nsOfflineCacheUpdate::AsyncFinishWithError);
|
||||
nsresult rv = NS_DispatchToMainThread(errorNotification);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mPartialUpdate) {
|
||||
mState = STATE_DOWNLOADING;
|
||||
NotifyState(nsIOfflineCacheUpdateObserver::STATE_DOWNLOADING);
|
||||
|
@ -2153,6 +2163,13 @@ nsOfflineCacheUpdate::Finish()
|
|||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
nsOfflineCacheUpdate::AsyncFinishWithError()
|
||||
{
|
||||
NotifyState(nsOfflineCacheUpdate::STATE_ERROR);
|
||||
Finish();
|
||||
}
|
||||
|
||||
static nsresult
|
||||
EvictOneOfCacheGroups(nsIApplicationCacheService *cacheService,
|
||||
uint32_t count, const char * const *groups)
|
||||
|
|
|
@ -239,6 +239,8 @@ private:
|
|||
nsresult Finish();
|
||||
nsresult FinishNoNotify();
|
||||
|
||||
void AsyncFinishWithError();
|
||||
|
||||
// Find one non-pinned cache group and evict it.
|
||||
nsresult EvictOneNonPinned();
|
||||
|
||||
|
@ -355,6 +357,7 @@ private:
|
|||
|
||||
bool mDisabled;
|
||||
bool mUpdateRunning;
|
||||
bool mLowFreeSpace;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "nsIAsyncVerifyRedirectCallback.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsIDiskSpaceWatcher.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
|
@ -261,6 +262,7 @@ NS_IMPL_ISUPPORTS3(nsOfflineCacheUpdateService,
|
|||
nsOfflineCacheUpdateService::nsOfflineCacheUpdateService()
|
||||
: mDisabled(false)
|
||||
, mUpdateRunning(false)
|
||||
, mLowFreeSpace(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -288,6 +290,15 @@ nsOfflineCacheUpdateService::Init()
|
|||
true);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Get the current status of the disk in terms of free space and observe
|
||||
// low device storage notifications.
|
||||
nsCOMPtr<nsIDiskSpaceWatcher> diskSpaceWatcherService =
|
||||
do_GetService("@mozilla.org/toolkit/disk-space-watcher;1");
|
||||
diskSpaceWatcherService->GetIsDiskFull(&mLowFreeSpace);
|
||||
|
||||
rv = observerService->AddObserver(this, "disk-space-watcher", false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
gOfflineCacheUpdateService = this;
|
||||
|
||||
return NS_OK;
|
||||
|
@ -408,6 +419,11 @@ nsOfflineCacheUpdateService::ProcessNextUpdate()
|
|||
|
||||
if (mUpdates.Length() > 0) {
|
||||
mUpdateRunning = true;
|
||||
// Canceling the update before Begin() call will make the update
|
||||
// asynchronously finish with an error.
|
||||
if (mLowFreeSpace) {
|
||||
mUpdates[0]->Cancel();
|
||||
}
|
||||
return mUpdates[0]->Begin();
|
||||
}
|
||||
|
||||
|
@ -599,6 +615,17 @@ nsOfflineCacheUpdateService::Observe(nsISupports *aSubject,
|
|||
mDisabled = true;
|
||||
}
|
||||
|
||||
if (!strcmp(aTopic, "disk-space-watcher")) {
|
||||
if (NS_LITERAL_STRING("full").Equals(aData)) {
|
||||
mLowFreeSpace = true;
|
||||
for (uint32_t i = 0; i < mUpdates.Length(); i++) {
|
||||
mUpdates[i]->Cancel();
|
||||
}
|
||||
} else if (NS_LITERAL_STRING("free").Equals(aData)) {
|
||||
mLowFreeSpace = false;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче