Bug 789923 - Drop saved thumbnails when device storage is low. r=mfinkle, lucasr

This commit is contained in:
Kartikaya Gupta 2012-10-16 10:07:06 -04:00
parent c53e719554
commit e93f0bc566
4 changed files with 37 additions and 5 deletions

View File

@ -5,6 +5,8 @@
package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserDB;
import android.content.BroadcastReceiver;
import android.content.ComponentCallbacks2;
import android.content.Context;
@ -106,8 +108,7 @@ class MemoryMonitor extends BroadcastReceiver {
if (Intent.ACTION_DEVICE_STORAGE_LOW.equals(intent.getAction())) {
Log.d(LOGTAG, "Device storage is low");
mStoragePressure = true;
// TODO: drop or shrink disk caches
// TODO: drop stuff from browser.db
GeckoAppShell.getHandler().post(new StorageReducer());
} else if (Intent.ACTION_DEVICE_STORAGE_OK.equals(intent.getAction())) {
Log.d(LOGTAG, "Device storage is ok");
mStoragePressure = false;
@ -201,4 +202,23 @@ class MemoryMonitor extends BroadcastReceiver {
GeckoAppShell.getHandler().postDelayed(this, DECREMENT_DELAY);
}
}
class StorageReducer implements Runnable {
@Override
public void run() {
// this might get run right on startup, if so wait 10 seconds and try again
if (!GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning)) {
GeckoAppShell.getHandler().postDelayed(this, 10000);
return;
}
if (!mStoragePressure) {
// pressure is off, so we can abort
return;
}
BrowserDB.removeThumbnails(Tabs.getInstance().getContentResolver());
// TODO: drop or shrink disk caches
}
}
}

View File

@ -75,6 +75,8 @@ public class BrowserDB {
public byte[] getThumbnailForUrl(ContentResolver cr, String uri);
public void removeThumbnails(ContentResolver cr);
public void registerBookmarkObserver(ContentResolver cr, ContentObserver observer);
public void registerHistoryObserver(ContentResolver cr, ContentObserver observer);
@ -186,6 +188,10 @@ public class BrowserDB {
return sDb.getThumbnailForUrl(cr, uri);
}
public static void removeThumbnails(ContentResolver cr) {
sDb.removeThumbnails(cr);
}
public static void registerBookmarkObserver(ContentResolver cr, ContentObserver observer) {
sDb.registerBookmarkObserver(cr, observer);
}

View File

@ -1662,10 +1662,10 @@ public class BrowserProvider extends ContentProvider {
String url = values.getAsString(Images.URL);
// if no URL is provided, update all of the entries
if (TextUtils.isEmpty(url))
throw new IllegalArgumentException("Images.URL is required");
if (shouldUpdateOrInsert(uri))
updated = updateExistingImage(uri, values, null, null);
else if (shouldUpdateOrInsert(uri))
updated = updateOrInsertImage(uri, values, Images.URL + " = ?",
new String[] { url });
else

View File

@ -680,6 +680,12 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
return b;
}
public void removeThumbnails(ContentResolver cr) {
ContentValues values = new ContentValues();
values.putNull(Images.THUMBNAIL);
cr.update(mImagesUriWithProfile, values, null, null);
}
// Utility function for updating existing history using batch operations
public void updateHistoryInBatch(ContentResolver cr,
Collection<ContentProviderOperation> operations,