Bug 783312 - Set up a backend for pinned sites. r=mfinkle

This commit is contained in:
Wes Johnston 2012-12-28 13:46:04 -08:00
parent 7285b255c0
commit 8da0cc0d31
6 changed files with 107 additions and 2 deletions

View File

@ -110,6 +110,7 @@ public class BrowserContract {
public static final int FIXED_ROOT_ID = 0;
public static final int FAKE_DESKTOP_FOLDER_ID = -1;
public static final int FIXED_READING_LIST_ID = -2;
public static final int FIXED_PINNED_LIST_ID = -3;
public static final String MOBILE_FOLDER_GUID = "mobile";
public static final String PLACES_FOLDER_GUID = "places";
@ -119,6 +120,7 @@ public class BrowserContract {
public static final String UNFILED_FOLDER_GUID = "unfiled";
public static final String READING_LIST_FOLDER_GUID = "readinglist";
public static final String FAKE_DESKTOP_FOLDER_GUID = "desktop";
public static final String PINNED_FOLDER_GUID = "pinned";
public static final int TYPE_FOLDER = 0;
public static final int TYPE_BOOKMARK = 1;

View File

@ -96,6 +96,14 @@ public class BrowserDB {
public void registerHistoryObserver(ContentResolver cr, ContentObserver observer);
public int getCount(ContentResolver cr, String database);
public void pinSite(ContentResolver cr, String url, String title, int position);
public void unpinSite(ContentResolver cr, int position);
public void unpinAllSites(ContentResolver cr);
public Cursor getPinnedSites(ContentResolver cr, int limit);
}
static {
@ -245,6 +253,22 @@ public class BrowserDB {
return sDb.getCount(cr, database);
}
public static void pinSite(ContentResolver cr, String url, String title, int position) {
sDb.pinSite(cr, url, title, position);
}
public static void unpinSite(ContentResolver cr, int position) {
sDb.unpinSite(cr, position);
}
public static void unpinAllSites(ContentResolver cr) {
sDb.unpinAllSites(cr);
}
public static Cursor getPinnedSites(ContentResolver cr, int limit) {
return sDb.getPinnedSites(cr, limit);
}
/* Cursor wrapper that forces top sites to contain at least
* mNumberOfTopSites entries. For rows outside the wrapped cursor
* will return empty strings and zero.

View File

@ -73,7 +73,7 @@ public class BrowserProvider extends ContentProvider {
static final String DATABASE_NAME = "browser.db";
static final int DATABASE_VERSION = 13;
static final int DATABASE_VERSION = 14;
// Maximum age of deleted records to be cleaned up (20 days in ms)
static final long MAX_AGE_OF_DELETED_RECORDS = 86400000 * 20;
@ -1101,6 +1101,8 @@ public class BrowserProvider extends ContentProvider {
R.string.bookmarks_folder_unfiled, 4);
createOrUpdateSpecialFolder(db, Bookmarks.READING_LIST_FOLDER_GUID,
R.string.bookmarks_folder_reading_list, 5);
createOrUpdateSpecialFolder(db, Bookmarks.PINNED_FOLDER_GUID,
R.string.bookmarks_folder_pinned, 6);
}
private void createOrUpdateSpecialFolder(SQLiteDatabase db,
@ -1114,6 +1116,8 @@ public class BrowserProvider extends ContentProvider {
values.put(Bookmarks._ID, Bookmarks.FIXED_ROOT_ID);
else if (guid.equals(Bookmarks.READING_LIST_FOLDER_GUID))
values.put(Bookmarks._ID, Bookmarks.FIXED_READING_LIST_ID);
else if (guid.equals(Bookmarks.PINNED_FOLDER_GUID))
values.put(Bookmarks._ID, Bookmarks.FIXED_PINNED_LIST_ID);
// Set the parent to 0, which sync assumes is the root
values.put(Bookmarks.PARENT, Bookmarks.FIXED_ROOT_ID);
@ -1567,6 +1571,11 @@ public class BrowserProvider extends ContentProvider {
db.execSQL("DROP TABLE IF EXISTS " + Obsolete.TABLE_IMAGES);
}
private void upgradeDatabaseFrom13to14(SQLiteDatabase db) {
createOrUpdateSpecialFolder(db, Bookmarks.PINNED_FOLDER_GUID,
R.string.bookmarks_folder_pinned, 6);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
debug("Upgrading browser.db: " + db.getPath() + " from " +
@ -1625,6 +1634,10 @@ public class BrowserProvider extends ContentProvider {
case 13:
upgradeDatabaseFrom12to13(db);
break;
case 14:
upgradeDatabaseFrom13to14(db);
break;
}
}

View File

@ -444,9 +444,11 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
Cursor c = cr.query(bookmarksUriWithLimit(1),
new String[] { Bookmarks._ID },
Bookmarks.URL + " = ? AND " +
Bookmarks.PARENT + " != ? AND " +
Bookmarks.PARENT + " != ?",
new String[] { uri,
String.valueOf(Bookmarks.FIXED_READING_LIST_ID) },
String.valueOf(Bookmarks.FIXED_READING_LIST_ID),
String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID) },
Bookmarks.URL);
count = c.getCount();
c.close();
@ -1084,4 +1086,65 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
return super.getColumnIndexOrThrow(translateColumnName(columnName));
}
}
public void pinSite(ContentResolver cr, String url, String title, int position) {
ContentValues values = new ContentValues();
final long now = System.currentTimeMillis();
values.put(Bookmarks.TITLE, title);
values.put(Bookmarks.URL, url);
values.put(Bookmarks.PARENT, Bookmarks.FIXED_PINNED_LIST_ID);
values.put(Bookmarks.DATE_MODIFIED, now);
values.put(Bookmarks.POSITION, position);
values.put(Bookmarks.IS_DELETED, 0);
// If this site is already pinned, unpin it
cr.delete(mBookmarksUriWithProfile,
Bookmarks.PARENT + " == ? AND " + Bookmarks.URL + " == ?",
new String[] {
String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID),
url
});
// If something is already pinned in this spot update it
int updated = cr.update(mBookmarksUriWithProfile,
values,
Bookmarks.POSITION + " = ? AND " +
Bookmarks.PARENT + " = ?",
new String[] { Integer.toString(position),
String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID) });
// Otherwise just insert a new item
if (updated == 0) {
cr.insert(mBookmarksUriWithProfile, values);
}
}
public Cursor getPinnedSites(ContentResolver cr, int limit) {
return cr.query(bookmarksUriWithLimit(limit),
new String[] { Bookmarks._ID,
Bookmarks.URL,
Bookmarks.TITLE,
Bookmarks.POSITION },
Bookmarks.PARENT + " == ?",
new String[] { String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID) },
Bookmarks.POSITION + " ASC");
}
public void unpinSite(ContentResolver cr, int position) {
cr.delete(mBookmarksUriWithProfile,
Bookmarks.PARENT + " == ? AND " + Bookmarks.POSITION + " = ?",
new String[] {
String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID),
Integer.toString(position)
});
}
public void unpinAllSites(ContentResolver cr) {
cr.delete(mBookmarksUriWithProfile,
Bookmarks.PARENT + " == ?",
new String[] {
String.valueOf(Bookmarks.FIXED_PINNED_LIST_ID)
});
}
}

View File

@ -83,6 +83,8 @@
<!ENTITY bookmarks.folder.desktop.label 'Desktop Bookmarks'>
<!ENTITY bookmarks.folder.mobile.label 'Mobile Bookmarks'>
<!ENTITY bookmarks.folder.readinglist.label 'Reading List'>
<!-- Pinned sites on about:home. This folder should never be shown to the user, but we have to give it a string name -->
<!ENTITY bookmarks.folder.pinned.label 'Pinned'>
<!-- Notification strings -->
<!ENTITY sync.notification.oneaccount.label 'Only one &syncBrand.fullName.label; account is supported.'>

View File

@ -76,6 +76,7 @@
<string name="bookmarks_folder_desktop">&bookmarks.folder.desktop.label;</string>
<string name="bookmarks_folder_mobile">&bookmarks.folder.mobile.label;</string>
<string name="bookmarks_folder_reading_list">&bookmarks.folder.readinglist.label;</string>
<string name="bookmarks_folder_pinned">&bookmarks.folder.pinned.label;</string>
<!-- Notification strings -->
<string name="sync_notification_oneaccount">&sync.notification.oneaccount.label;</string>