backout 62207930924a, 6931d5b6f055, 31cdc85ce16e, and 0636839be2d1 to fix commit message

This commit is contained in:
Wes Johnston 2012-10-19 17:49:42 -07:00
parent f7731609b2
commit 7114249e9f
7 changed files with 12 additions and 193 deletions

View File

@ -6,7 +6,6 @@
package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.gfx.Layer;
import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.gfx.PluginLayer;
@ -2102,9 +2101,6 @@ abstract public class GeckoApp
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(GeckoApp.PREFS_WAS_STOPPED, true);
editor.commit();
BrowserDB.expireHistory(getContentResolver(),
BrowserContract.ExpirePriority.NORMAL);
}
});

View File

@ -6,7 +6,6 @@
package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.BrowserContract;
import android.content.BroadcastReceiver;
import android.content.ComponentCallbacks2;
@ -54,7 +53,6 @@ class MemoryMonitor extends BroadcastReceiver {
private final PressureDecrementer mPressureDecrementer;
private int mMemoryPressure;
private boolean mStoragePressure;
private Context mContext;
private MemoryMonitor() {
mPressureDecrementer = new PressureDecrementer();
@ -63,7 +61,6 @@ class MemoryMonitor extends BroadcastReceiver {
}
public void init(Context context) {
mContext = context;
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_DEVICE_STORAGE_LOW);
filter.addAction(Intent.ACTION_DEVICE_STORAGE_OK);
@ -220,8 +217,6 @@ class MemoryMonitor extends BroadcastReceiver {
return;
}
BrowserDB.expireHistory(mContext.getContentResolver(),
BrowserContract.ExpirePriority.AGGRESSIVE);
BrowserDB.removeThumbnails(Tabs.getInstance().getContentResolver());
// TODO: drop or shrink disk caches
}

View File

@ -29,25 +29,6 @@ public class BrowserContract {
public static final String PARAM_IS_TEST = "test";
public static final String PARAM_INSERT_IF_NEEDED = "insert_if_needed";
public static final String PARAM_INCREMENT_VISITS = "increment_visits";
public static final String PARAM_EXPIRE_PRIORITY = "priority";
static public enum ExpirePriority {
NORMAL,
AGGRESSIVE
}
static public String getFrecencySortOrder(boolean includesBookmarks, boolean asc) {
final String age = "(" + Combined.DATE_LAST_VISITED + " - " + System.currentTimeMillis() + ") / 86400000";
StringBuilder order = new StringBuilder(Combined.VISITS + " * MAX(1, 100 * 225 / (" + age + "*" + age + " + 225)) ");
if (includesBookmarks) {
order.insert(0, "(CASE WHEN " + Combined.BOOKMARK_ID + " > -1 THEN 100 ELSE 0 END) + ");
}
order.append(asc ? " ASC" : " DESC");
return order.toString();
}
public interface CommonColumns {
public static final String _ID = "_id";
@ -130,7 +111,6 @@ public class BrowserContract {
public static final class History implements CommonColumns, URLColumns, HistoryColumns, ImageColumns, SyncColumns {
private History() {}
public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "history");
public static final Uri CONTENT_OLD_URI = Uri.withAppendedPath(AUTHORITY_URI, "history/old");
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/browser-history";
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/browser-history";
}

View File

@ -5,8 +5,6 @@
package org.mozilla.gecko.db;
import org.mozilla.gecko.db.BrowserContract.ExpirePriority;
import android.content.ContentResolver;
import android.database.ContentObserver;
import android.database.Cursor;
@ -45,8 +43,6 @@ public class BrowserDB {
public Cursor getRecentHistory(ContentResolver cr, int limit);
public void expireHistory(ContentResolver cr, ExpirePriority priority);
public void removeHistoryEntry(ContentResolver cr, int id);
public void clearHistory(ContentResolver cr);
@ -128,12 +124,6 @@ public class BrowserDB {
return sDb.getRecentHistory(cr, limit);
}
public static void expireHistory(ContentResolver cr, ExpirePriority priority) {
if (priority == null)
priority = ExpirePriority.NORMAL;
sDb.expireHistory(cr, priority);
}
public static void removeHistoryEntry(ContentResolver cr, int id) {
sDb.removeHistoryEntry(cr, id);
}

View File

@ -34,7 +34,6 @@ import org.mozilla.gecko.db.BrowserContract.Schema;
import org.mozilla.gecko.db.BrowserContract.SyncColumns;
import org.mozilla.gecko.db.BrowserContract.URLColumns;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.DBUtils;
import org.mozilla.gecko.ProfileMigrator;
import org.mozilla.gecko.sync.Utils;
@ -83,13 +82,6 @@ public class BrowserProvider extends ContentProvider {
// query (currently 3).
static final int MAX_POSITION_UPDATES_PER_QUERY = 100;
// Minimum number of records to keep when expiring history.
static final int DEFAULT_EXPIRY_RETAIN_COUNT = 2000;
static final int AGGRESSIVE_EXPIRY_RETAIN_COUNT = 500;
// Minimum duration to keep when expiring.
static final long DEFAULT_EXPIRY_PRESERVE_WINDOW = 1000L * 60L * 60L * 24L * 28L; // Four weeks.
static final String TABLE_BOOKMARKS = "bookmarks";
static final String TABLE_HISTORY = "history";
static final String TABLE_IMAGES = "images";
@ -112,7 +104,6 @@ public class BrowserProvider extends ContentProvider {
// History matches
static final int HISTORY = 200;
static final int HISTORY_ID = 201;
static final int HISTORY_OLD = 202;
// Image matches
static final int IMAGES = 300;
@ -185,7 +176,6 @@ public class BrowserProvider extends ContentProvider {
// History
URI_MATCHER.addURI(BrowserContract.AUTHORITY, "history", HISTORY);
URI_MATCHER.addURI(BrowserContract.AUTHORITY, "history/#", HISTORY_ID);
URI_MATCHER.addURI(BrowserContract.AUTHORITY, "history/old", HISTORY_OLD);
map = new HashMap<String, String>();
map.put(History._ID, History._ID);
@ -1334,47 +1324,6 @@ public class BrowserProvider extends ContentProvider {
}
}
/**
* Remove enough history items to bring the database count below <code>retain</code>,
* removing no items with a modified time after <code>keepAfter</code>.
*
* Provide <code>keepAfter</code> less than or equal to zero to skip that check.
*
* Items will be removed according to an approximate frecency calculation.
*
* Call this method within a transaction.
*/
public void expireHistory(final SQLiteDatabase db, final int retain, final long keepAfter) {
final long rows = DatabaseUtils.queryNumEntries(db, TABLE_HISTORY);
if (retain >= rows) {
debug("Not expiring history: only have " + rows + " rows.");
return;
}
final long toRemove = rows - retain;
debug("Expiring at most " + toRemove + " rows earlier than " + keepAfter + ".");
final String sortOrder = BrowserContract.getFrecencySortOrder(false, true);
final String sql;
if (keepAfter > 0) {
// If we don't bind these paramaters dynamically, the WHERE clause here can return null
sql = "DELETE FROM " + TABLE_HISTORY + " " +
"WHERE MAX(" + History.DATE_LAST_VISITED + ", " + History.DATE_MODIFIED +") < " + keepAfter + " " +
" AND " + History._ID + " " + "IN ( SELECT " +
History._ID + " FROM " + TABLE_HISTORY + " " +
"ORDER BY " + sortOrder + " LIMIT " + toRemove +
")";
} else {
sql = "DELETE FROM " + TABLE_HISTORY + " WHERE " + History._ID + " " +
"IN ( SELECT " + History._ID + " FROM " + TABLE_HISTORY + " " +
"ORDER BY " + sortOrder + " LIMIT " + toRemove + ")";
}
trace("Deleting using query: " + sql);
db.execSQL(sql);
}
private boolean isCallerSync(Uri uri) {
String isSync = uri.getQueryParameter(BrowserContract.PARAM_IS_SYNC);
return !TextUtils.isEmpty(isSync);
@ -1463,16 +1412,16 @@ public class BrowserProvider extends ContentProvider {
trace("Beginning delete transaction: " + uri);
db.beginTransaction();
try {
deleted = deleteInTransaction(db, uri, selection, selectionArgs);
deleted = deleteInTransaction(uri, selection, selectionArgs);
db.setTransactionSuccessful();
trace("Successful delete transaction: " + uri);
} finally {
db.endTransaction();
}
} else {
deleted = deleteInTransaction(db, uri, selection, selectionArgs);
deleted = deleteInTransaction(uri, selection, selectionArgs);
}
if (deleted > 0)
getContext().getContentResolver().notifyChange(uri, null);
@ -1480,7 +1429,7 @@ public class BrowserProvider extends ContentProvider {
}
@SuppressWarnings("fallthrough")
public int deleteInTransaction(SQLiteDatabase db, Uri uri, String selection, String[] selectionArgs) {
public int deleteInTransaction(Uri uri, String selection, String[] selectionArgs) {
trace("Calling delete in transaction on URI: " + uri);
final int match = URI_MATCHER.match(uri);
@ -1515,19 +1464,6 @@ public class BrowserProvider extends ContentProvider {
break;
}
case HISTORY_OLD: {
String priority = uri.getQueryParameter(BrowserContract.PARAM_EXPIRE_PRIORITY);
long keepAfter = System.currentTimeMillis() - DEFAULT_EXPIRY_PRESERVE_WINDOW;
int retainCount = DEFAULT_EXPIRY_RETAIN_COUNT;
if (BrowserContract.ExpirePriority.AGGRESSIVE.toString().equals(priority)) {
keepAfter = 0;
retainCount = AGGRESSIVE_EXPIRY_RETAIN_COUNT;
}
expireHistory(db, retainCount, keepAfter);
break;
}
case IMAGES_ID:
debug("Delete on IMAGES_ID: " + uri);
@ -2137,6 +2073,10 @@ public class BrowserProvider extends ContentProvider {
values.put(Bookmarks.DATE_CREATED, now);
}
if (!values.containsKey(Bookmarks.DATE_MODIFIED)) {
values.put(Bookmarks.DATE_MODIFIED, now);
}
if (!values.containsKey(Bookmarks.GUID)) {
values.put(Bookmarks.GUID, Utils.generateGuid());
}
@ -2295,9 +2235,7 @@ public class BrowserProvider extends ContentProvider {
selectionArgs, null, null, null);
try {
if (!values.containsKey(Bookmarks.DATE_MODIFIED)) {
values.put(Bookmarks.DATE_MODIFIED, System.currentTimeMillis());
}
values.put(History.DATE_MODIFIED, System.currentTimeMillis());
boolean updatingUrl = values.containsKey(History.URL);
String url = null;

View File

@ -12,7 +12,6 @@ import org.mozilla.gecko.db.BrowserContract.ImageColumns;
import org.mozilla.gecko.db.BrowserContract.Images;
import org.mozilla.gecko.db.BrowserContract.SyncColumns;
import org.mozilla.gecko.db.BrowserContract.URLColumns;
import org.mozilla.gecko.db.BrowserContract.ExpirePriority;
import android.content.ContentProviderOperation;
import android.content.ContentResolver;
@ -55,7 +54,6 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
private final Uri mBookmarksUriWithProfile;
private final Uri mParentsUriWithProfile;
private final Uri mHistoryUriWithProfile;
private final Uri mHistoryExpireUriWithProfile;
private final Uri mImagesUriWithProfile;
private final Uri mCombinedUriWithProfile;
private final Uri mDeletedHistoryUriWithProfile;
@ -80,7 +78,6 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
mBookmarksUriWithProfile = appendProfile(Bookmarks.CONTENT_URI);
mParentsUriWithProfile = appendProfile(Bookmarks.PARENTS_CONTENT_URI);
mHistoryUriWithProfile = appendProfile(History.CONTENT_URI);
mHistoryExpireUriWithProfile = appendProfile(History.CONTENT_OLD_URI);
mImagesUriWithProfile = appendProfile(Images.CONTENT_URI);
mCombinedUriWithProfile = appendProfile(Combined.CONTENT_URI);
@ -165,7 +162,9 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
// Using 15 as our scale parameter, we get a constant 15^2 = 225. Following this math,
// frecencyScore = numVisits * max(1, 100 * 225 / (age*age + 225)). (See bug 704977)
// We also give bookmarks an extra bonus boost by adding 100 points to their frecency score.
final String sortOrder = BrowserContract.getFrecencySortOrder(true, false);
final String age = "(" + Combined.DATE_LAST_VISITED + " - " + System.currentTimeMillis() + ") / 86400000";
final String sortOrder = "(CASE WHEN " + Combined.BOOKMARK_ID + " > -1 THEN 100 ELSE 0 END) + " +
Combined.VISITS + " * MAX(1, 100 * 225 / (" + age + "*" + age + " + 225)) DESC";
Cursor c = cr.query(combinedUriWithLimit(limit),
projection,
@ -286,12 +285,6 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
return new LocalDBCursor(c);
}
public void expireHistory(ContentResolver cr, ExpirePriority priority) {
Uri url = mHistoryExpireUriWithProfile;
url = url.buildUpon().appendQueryParameter(BrowserContract.PARAM_EXPIRE_PRIORITY, priority.toString()).build();
cr.delete(url, null, null);
}
public void removeHistoryEntry(ContentResolver cr, int id) {
cr.delete(mHistoryUriWithProfile,
History._ID + " = ?",

View File

@ -37,7 +37,6 @@ public class testBrowserProvider extends ContentProviderTest {
private Uri mBookmarksUri;
private Uri mBookmarksPositionUri;
private Uri mHistoryUri;
private Uri mHistoryOldUri;
private Uri mImagesUri;
private Uri mCombinedUri;
@ -97,7 +96,6 @@ public class testBrowserProvider extends ContentProviderTest {
private void loadContractInfo() throws Exception {
mBookmarksUri = getContentUri("Bookmarks");
mHistoryUri = getContentUri("History");
mHistoryOldUri = getUriColumn("History", "CONTENT_OLD_URI");
mImagesUri = getContentUri("Images");
mCombinedUri = getContentUri("Combined");
@ -325,7 +323,6 @@ public class testBrowserProvider extends ContentProviderTest {
mTests.add(new TestCombinedViewDisplay());
mTests.add(new TestCombinedViewWithDeletedBookmark());
mTests.add(new TestCombinedViewWithDeletedReadingListItem());
mTests.add(new TestExpireHistory());
}
public void testBrowserProvider() throws Exception {
@ -1589,74 +1586,4 @@ public class testBrowserProvider extends ContentProviderTest {
"Combined entry should have reader display type");
}
}
class TestExpireHistory extends Test {
private void createFakeHistory(long timeShift, int count) {
// Insert a bunch of very new entries
ContentValues allVals[] = new ContentValues[count];
long time = System.currentTimeMillis() - timeShift;
for (int i = 0; i < count; i++) {
allVals[i] = new ContentValues();
allVals[i].put(mHistoryTitleCol, "Test " + i);
allVals[i].put(mHistoryUrlCol, "http://www.test.org/" + i);
allVals[i].put(mHistoryVisitsCol, i);
allVals[i].put(mHistoryLastVisitedCol, time);
}
int inserts = mProvider.bulkInsert(mHistoryUri, allVals);
mAsserter.is(inserts, count, "Excepted number of inserts matches");
// inserting a new entry sets the date created and modified automatically
// reset all of them
for (int i = 0; i < count; i++) {
ContentValues cv = new ContentValues();
cv.put(mHistoryDateCreatedCol, time);
cv.put(mHistoryDateModifiedCol, time);
mProvider.update(mHistoryUri, cv, mHistoryUrlCol + " = ?",
new String[] { "http://www.test.org/" + i });
}
Cursor c = mProvider.query(mHistoryUri, null, "", null, null);
mAsserter.is(c.getCount(), count, count + " history entries found");
}
public void test() throws Exception {
final int count = 3000;
// insert a bunch of new entries
createFakeHistory(0, count);
// expiring with a normal priority should not delete new entries
Uri url = appendUriParam(mHistoryOldUri, "PARAM_EXPIRE_PRIORITY", "NORMAL");
mProvider.delete(url, null, null);
Cursor c = mProvider.query(mHistoryUri, null, "", null, null);
mAsserter.is(c.getCount(), count, count + " history entries found");
// expiring with a aggressive priority should leave 500 entries
url = appendUriParam(mHistoryOldUri, "PARAM_EXPIRE_PRIORITY", "AGGRESSIVE");
mProvider.delete(url, null, null);
c = mProvider.query(mHistoryUri, null, "", null, null);
mAsserter.is(c.getCount(), 500, "500 history entries found");
ensureEmptyDatabase();
// insert a bunch of entries with an old time created/modified
long time = 1000L * 60L * 60L * 24L * 30L * 3L;
createFakeHistory(time, count);
// expiring with an normal priority should remove at most 1000 entries
// entries leaving at least 2000
url = appendUriParam(mHistoryOldUri, "PARAM_EXPIRE_PRIORITY", "NORMAL");
mProvider.delete(url, null, null);
c = mProvider.query(mHistoryUri, null, "", null, null);
mAsserter.is(c.getCount(), 2000, "2000 history entries found");
// expiring with an agressive priority should remove old
// entries leaving at least 500
url = appendUriParam(mHistoryOldUri, "PARAM_EXPIRE_PRIORITY", "AGGRESSIVE");
mProvider.delete(url, null, null);
c = mProvider.query(mHistoryUri, null, "", null, null);
mAsserter.is(c.getCount(), 500, "500 history entries found");
}
}
}