--- a/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/LocalBrowserDB.java
@@ -133,26 +133,26 @@ public class LocalBrowserDB extends Brow
Bookmarks.TITLE,
Bookmarks.TYPE,
Bookmarks.PARENT };
public LocalBrowserDB(String profile) {
mProfile = profile;
mFolderIdMap = new HashMap<String, Long>();
- mBookmarksUriWithProfile = DBUtils.appendProfile(profile, Bookmarks.CONTENT_URI);
- mParentsUriWithProfile = DBUtils.appendProfile(profile, Bookmarks.PARENTS_CONTENT_URI);
- mHistoryUriWithProfile = DBUtils.appendProfile(profile, History.CONTENT_URI);
- mHistoryExpireUriWithProfile = DBUtils.appendProfile(profile, History.CONTENT_OLD_URI);
- mCombinedUriWithProfile = DBUtils.appendProfile(profile, Combined.CONTENT_URI);
- mFaviconsUriWithProfile = DBUtils.appendProfile(profile, Favicons.CONTENT_URI);
- mTopSitesUriWithProfile = DBUtils.appendProfile(profile, TopSites.CONTENT_URI);
- mHighlightsUriWithProfile = DBUtils.appendProfile(profile, Highlights.CONTENT_URI);
- mThumbnailsUriWithProfile = DBUtils.appendProfile(profile, Thumbnails.CONTENT_URI);
- mActivityStreamBlockedUriWithProfile = DBUtils.appendProfile(profile, ActivityStreamBlocklist.CONTENT_URI);
+ mBookmarksUriWithProfile = DBUtils.appendProfile(Bookmarks.CONTENT_URI, profile);
+ mParentsUriWithProfile = DBUtils.appendProfile(Bookmarks.PARENTS_CONTENT_URI, profile);
+ mHistoryUriWithProfile = DBUtils.appendProfile(History.CONTENT_URI, profile);
+ mHistoryExpireUriWithProfile = DBUtils.appendProfile(History.CONTENT_OLD_URI, profile);
+ mCombinedUriWithProfile = DBUtils.appendProfile(Combined.CONTENT_URI, profile);
+ mFaviconsUriWithProfile = DBUtils.appendProfile(Favicons.CONTENT_URI, profile);
+ mTopSitesUriWithProfile = DBUtils.appendProfile(TopSites.CONTENT_URI, profile);
+ mHighlightsUriWithProfile = DBUtils.appendProfile(Highlights.CONTENT_URI, profile);
+ mThumbnailsUriWithProfile = DBUtils.appendProfile(Thumbnails.CONTENT_URI, profile);
+ mActivityStreamBlockedUriWithProfile = DBUtils.appendProfile(ActivityStreamBlocklist.CONTENT_URI, profile);
mSearchHistoryUri = BrowserContract.SearchHistory.CONTENT_URI;
mUpdateHistoryUriWithProfile =
mHistoryUriWithProfile.buildUpon()
.appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true")
.appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true")
.build();
@@ -538,33 +538,21 @@ public class LocalBrowserDB extends Brow
// Invalidate cached data
@Override
public void invalidate() {
mDesktopBookmarksExist = null;
}
private Uri bookmarksUriWithLimit(int limit) {
- return mBookmarksUriWithProfile.buildUpon()
- .appendQueryParameter(BrowserContract.PARAM_LIMIT,
- String.valueOf(limit))
- .build();
+ return DBUtils.appendLimit(mBookmarksUriWithProfile, limit);
}
private Uri combinedUriWithLimit(int limit) {
- return mCombinedUriWithProfile.buildUpon()
- .appendQueryParameter(BrowserContract.PARAM_LIMIT,
- String.valueOf(limit))
- .build();
- }
-
- private static Uri withDeleted(final Uri uri) {
- return uri.buildUpon()
- .appendQueryParameter(BrowserContract.PARAM_SHOW_DELETED, "1")
- .build();
+ return DBUtils.appendLimit(mCombinedUriWithProfile, limit);
}
private Cursor filterAllSites(ContentResolver cr, String[] projection, CharSequence constraint,
int limit, CharSequence urlFilter, String selection, String[] selectionArgs) {
// The combined history/bookmarks selection queries for sites with a URL or title containing
// the constraint string(s), treating space-separated words as separate constraints
if (!TextUtils.isEmpty(constraint)) {
final String[] constraintWords = constraint.toString().split(" ");
@@ -586,20 +574,20 @@ public class LocalBrowserDB extends Brow
}
// Order by combined remote+local frecency score.
// Local visits are preferred, so they will by far outweigh remote visits.
// Bookmarked history items get extra frecency points.
final String sortOrder = BrowserContract.getCombinedFrecencySortOrder(true, false);
return cr.query(combinedUriWithLimit(limit),
- projection,
- selection,
- selectionArgs,
- sortOrder);
+ projection,
+ selection,
+ selectionArgs,
+ sortOrder);
}
@Override
public int getCount(ContentResolver cr, String database) {
int count = 0;
String[] columns = null;
String constraint = null;
Uri uri = null;
@@ -646,25 +634,25 @@ public class LocalBrowserDB extends Brow
selection = Combined.URL + " NOT IN (SELECT " +
Bookmarks.URL + " FROM bookmarks WHERE " +
DBUtils.qualifyColumn("bookmarks", Bookmarks.PARENT) + " = ? AND " +
DBUtils.qualifyColumn("bookmarks", Bookmarks.IS_DELETED) + " == 0)";
selectionArgs = new String[] { String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID) };
}
return filterAllSites(cr,
- new String[] { Combined._ID,
- Combined.URL,
- Combined.TITLE,
- Combined.BOOKMARK_ID,
- Combined.HISTORY_ID },
- constraint,
- limit,
- null,
- selection, selectionArgs);
+ new String[]{Combined._ID,
+ Combined.URL,
+ Combined.TITLE,
+ Combined.BOOKMARK_ID,
+ Combined.HISTORY_ID},
+ constraint,
+ limit,
+ null,
+ selection, selectionArgs);
}
@Override
public void updateVisitedHistory(ContentResolver cr, String uri) {
ContentValues values = new ContentValues();
values.put(History.URL, uri);
values.put(History.DATE_LAST_VISITED, System.currentTimeMillis());
@@ -712,23 +700,23 @@ public class LocalBrowserDB extends Brow
History.DATE_LAST_VISITED + " > 0",
null,
History.DATE_LAST_VISITED + " DESC");
}
@Override
public Cursor getRecentHistoryBetweenTime(ContentResolver cr, int limit, long start, long end) {
return cr.query(combinedUriWithLimit(limit),
- new String[] { Combined._ID,
+ new String[]{Combined._ID,
Combined.BOOKMARK_ID,
Combined.HISTORY_ID,
Combined.URL,
Combined.TITLE,
Combined.DATE_LAST_VISITED,
- Combined.VISITS },
+ Combined.VISITS},
History.DATE_LAST_VISITED + " >= " + start + " AND " + History.DATE_LAST_VISITED + " < " + end,
null,
History.DATE_LAST_VISITED + " DESC");
}
public Cursor getHistoryForURL(ContentResolver cr, String uri) {
return cr.query(mHistoryUriWithProfile,
new String[] {
@@ -762,17 +750,17 @@ public class LocalBrowserDB extends Brow
} finally {
cursor.close();
}
}
@Override
public void expireHistory(ContentResolver cr, ExpirePriority priority) {
Uri url = mHistoryExpireUriWithProfile;
- url = url.buildUpon().appendQueryParameter(BrowserContract.PARAM_EXPIRE_PRIORITY, priority.toString()).build();
+ url = DBUtils.appendParameterValue(url, BrowserContract.PARAM_EXPIRE_PRIORITY, priority.toString());
cr.delete(url, null, null);
}
@Override
@RobocopTarget
public void removeHistoryEntry(ContentResolver cr, String url) {
cr.delete(mHistoryUriWithProfile,
History.URL + " = ?",
@@ -953,24 +941,24 @@ public class LocalBrowserDB extends Brow
private boolean desktopBookmarksExist(ContentResolver cr) {
if (mDesktopBookmarksExist != null) {
return mDesktopBookmarksExist;
}
// Check to see if there are any bookmarks in one of our three
// fixed "Desktop Bookmarks" folders.
final Cursor c = cr.query(bookmarksUriWithLimit(1),
- new String[] { Bookmarks._ID },
- Bookmarks.PARENT + " = ? OR " +
- Bookmarks.PARENT + " = ? OR " +
- Bookmarks.PARENT + " = ?",
- new String[] { String.valueOf(getFolderIdFromGuid(cr, Bookmarks.TOOLBAR_FOLDER_GUID)),
- String.valueOf(getFolderIdFromGuid(cr, Bookmarks.MENU_FOLDER_GUID)),
- String.valueOf(getFolderIdFromGuid(cr, Bookmarks.UNFILED_FOLDER_GUID)) },
- null);
+ new String[]{Bookmarks._ID},
+ Bookmarks.PARENT + " = ? OR " +
+ Bookmarks.PARENT + " = ? OR " +
+ Bookmarks.PARENT + " = ?",
+ new String[]{String.valueOf(getFolderIdFromGuid(cr, Bookmarks.TOOLBAR_FOLDER_GUID)),
+ String.valueOf(getFolderIdFromGuid(cr, Bookmarks.MENU_FOLDER_GUID)),
+ String.valueOf(getFolderIdFromGuid(cr, Bookmarks.UNFILED_FOLDER_GUID))},
+ null);
try {
// Don't read back out of the cache to avoid races with invalidation.
final boolean e = c.getCount() > 0;
mDesktopBookmarksExist = e;
return e;
} finally {
c.close();
@@ -1080,19 +1068,17 @@ public class LocalBrowserDB extends Brow
}
} finally {
c.close();
}
// Restore deleted record if possible
values.put(Bookmarks.IS_DELETED, 0);
- final Uri bookmarksWithInsert = mBookmarksUriWithProfile.buildUpon()
- .appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true")
- .build();
+ final Uri bookmarksWithInsert = DBUtils.appendInsertIfNeeded(mBookmarksUriWithProfile);
cr.update(bookmarksWithInsert,
values,
Bookmarks.URL + " = ? AND " +
Bookmarks.PARENT + " = " + folderId,
new String[] { uri });
// Bump parent modified time using its ID.
debug("Bumping parent modified time for addition to: " + folderId);
@@ -1313,18 +1299,18 @@ public class LocalBrowserDB extends Brow
} else {
Log.w(LOGTAG, "Favicon compression failed.");
}
ContentValues values = new ContentValues();
values.put(Thumbnails.URL, uri);
values.put(Thumbnails.DATA, data);
- Uri thumbnailsUri = mThumbnailsUriWithProfile.buildUpon().
- appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build();
+ final Uri thumbnailsUri = DBUtils.appendInsertIfNeeded(mThumbnailsUriWithProfile);
+
cr.update(thumbnailsUri,
values,
Thumbnails.URL + " = ?",
new String[] { uri });
}
@Override
@RobocopTarget
@@ -1399,21 +1385,21 @@ public class LocalBrowserDB extends Brow
History._ID,
History.VISITS,
History.LOCAL_VISITS,
History.DATE_LAST_VISITED,
History.LOCAL_DATE_LAST_VISITED
};
// We need to get the old visit and date aggregates.
- final Cursor cursor = cr.query(withDeleted(mHistoryUriWithProfile),
- projection,
- History.URL + " = ?",
- new String[] { url },
- null);
+ final Cursor cursor = cr.query(DBUtils.appendShowDeleted(mHistoryUriWithProfile),
+ projection,
+ History.URL + " = ?",
+ new String[] { url },
+ null);
if (cursor == null) {
Log.w(LOGTAG, "Null cursor while querying for old visit and date aggregates");
return;
}
try {
final ContentValues values = new ContentValues();
@@ -1450,18 +1436,17 @@ public class LocalBrowserDB extends Brow
values.put(History.DATE_LAST_VISITED, date);
values.put(History.LOCAL_DATE_LAST_VISITED, date);
}
if (title != null) {
values.put(History.TITLE, title);
}
values.put(History.URL, url);
- final Uri historyUri = withDeleted(mHistoryUriWithProfile).buildUpon().
- appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build();
+ final Uri historyUri = DBUtils.appendInsertIfNeededAndWithDeleted(mHistoryUriWithProfile);
// Update or insert
final ContentProviderOperation.Builder builder =
ContentProviderOperation.newUpdate(historyUri);
builder.withSelection(History.URL + " = ?", new String[] { url });
builder.withValues(values);
// Queue the operation
@@ -1573,18 +1558,19 @@ public class LocalBrowserDB extends Brow
// This assumes no "real" folder has a negative ID. Only
// things like the reading list folder do.
if (parent < 0) {
parent = getFolderIdFromGuid(cr, Bookmarks.MOBILE_FOLDER_GUID);
}
values.put(Bookmarks.PARENT, parent);
values.put(Bookmarks.TYPE, type);
- Uri bookmarkUri = withDeleted(mBookmarksUriWithProfile).buildUpon().
- appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build();
+
+ final Uri bookmarkUri = DBUtils.appendInsertIfNeededAndWithDeleted(mHistoryUriWithProfile);
+
// Update or insert
ContentProviderOperation.Builder builder =
ContentProviderOperation.newUpdate(bookmarkUri);
if (url != null) {
// Bookmarks are defined by their URL and Folder.
builder.withSelection(Bookmarks.URL + " = ? AND "
+ Bookmarks.PARENT + " = ?",
new String[] { url,
@@ -1623,24 +1609,23 @@ public class LocalBrowserDB extends Brow
values.put(Bookmarks.DATE_MODIFIED, now);
values.put(Bookmarks.POSITION, position);
values.put(Bookmarks.IS_DELETED, 0);
// We do an update-and-replace here without deleting any existing pins for the given URL.
// That means if the user pins a URL, then edits another thumbnail to use the same URL,
// we'll end up with two pins for that site. This is the intended behavior, which
// incidentally saves us a delete query.
- Uri uri = mBookmarksUriWithProfile.buildUpon()
- .appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build();
+ final Uri uri = DBUtils.appendInsertIfNeeded(mBookmarksUriWithProfile);
cr.update(uri,
- values,
- Bookmarks.POSITION + " = ? AND " +
- Bookmarks.PARENT + " = ?",
- new String[] { Integer.toString(position),
- String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID) });
+ values,
+ Bookmarks.POSITION + " = ? AND " +
+ Bookmarks.PARENT + " = ?",
+ new String[]{Integer.toString(position),
+ String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID)});
}
@Override
public void unpinSite(ContentResolver cr, int position) {
cr.delete(mBookmarksUriWithProfile,
Bookmarks.PARENT + " == ? AND " + Bookmarks.POSITION + " = ?",
new String[] {
String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID),