Bug 1250707 - Create url annotations table. r=sebastian
MozReview-Commit-ID: BHtwkdrpfYi
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java
@@ -480,15 +480,41 @@ public class BrowserContract {
@RobocopTarget
public static final class SuggestedSites implements CommonColumns, URLColumns {
private SuggestedSites() {}
public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "suggestedsites");
}
+ public static final class UrlAnnotations implements CommonColumns, DateSyncColumns {
+ private UrlAnnotations() {}
+
+ public static final String TABLE_NAME = "urlannotations";
+
+ public static final String URL = "url";
+ public static final String KEY = "key";
+ public static final String VALUE = "value";
+ public static final String SYNC_STATUS = "sync_status";
+
+ public enum SyncStatus {
+ // We use a parameter, rather than ordinal(), as defensive coding: we can't let the
+ // ordinal values change because we've already stored values into the DB.
+ NEW (0);
+
+ // Value stored into the database for this column.
+ private final int dbValue;
+
+ SyncStatus(final int dbValue) {
+ this.dbValue = dbValue;
+ }
+
+ public int getDBValue() { return dbValue; }
+ }
+ }
+
// We refer to the service by name to decouple services from the rest of the code base.
public static final String TAB_RECEIVED_SERVICE_CLASS_NAME = "org.mozilla.gecko.tabqueue.TabReceivedService";
public static final String SKIP_TAB_QUEUE_FLAG = "skip_tab_queue";
public static final String EXTRA_CLIENT_GUID = "org.mozilla.gecko.extra.CLIENT_ID";
}
--- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserDatabaseHelper.java
@@ -1,29 +1,29 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.db;
import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.R;
import org.mozilla.gecko.db.BrowserContract.Bookmarks;
import org.mozilla.gecko.db.BrowserContract.Combined;
import org.mozilla.gecko.db.BrowserContract.Favicons;
import org.mozilla.gecko.db.BrowserContract.History;
import org.mozilla.gecko.db.BrowserContract.ReadingListItems;
import org.mozilla.gecko.db.BrowserContract.SearchHistory;
import org.mozilla.gecko.db.BrowserContract.Thumbnails;
+import org.mozilla.gecko.db.BrowserContract.UrlAnnotations;
import org.mozilla.gecko.util.FileUtils;
import static org.mozilla.gecko.db.DBUtils.qualifyColumn;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.DatabaseUtils;
@@ -36,17 +36,17 @@ import android.os.Build;
import android.util.Log;
final class BrowserDatabaseHelper extends SQLiteOpenHelper {
private static final String LOGTAG = "GeckoBrowserDBHelper";
// Replace the Bug number below with your Bug that is conducting a DB upgrade, as to force a merge conflict with any
// other patches that require a DB upgrade.
- public static final int DATABASE_VERSION = 27; // Bug 826400
+ public static final int DATABASE_VERSION = 28; // Bug 1250707
public static final String DATABASE_NAME = "browser.db";
final protected Context mContext;
static final String TABLE_BOOKMARKS = Bookmarks.TABLE_NAME;
static final String TABLE_HISTORY = History.TABLE_NAME;
static final String TABLE_FAVICONS = Favicons.TABLE_NAME;
static final String TABLE_THUMBNAILS = Thumbnails.TABLE_NAME;
@@ -353,16 +353,17 @@ final class BrowserDatabaseHelper extend
createOrUpdateSpecialFolder(db, Bookmarks.PLACES_FOLDER_GUID,
R.string.bookmarks_folder_places, 0);
createOrUpdateAllSpecialFolders(db);
createSearchHistoryTable(db);
createReadingListTable(db, TABLE_READING_LIST);
didCreateCurrentReadingListTable = true; // Mostly correct, in the absence of transactions.
createReadingListIndices(db, TABLE_READING_LIST);
+ createUrlAnnotationsTable(db);
}
/**
* Copies the tabs and clients tables out of the given tabs.db file and into the destinationDB.
*
* @param tabsDBFile Path to existing tabs.db.
* @param destinationDB The destination database.
*/
@@ -450,16 +451,33 @@ final class BrowserDatabaseHelper extend
private void createReadingListIndices(final SQLiteDatabase db, final String tableName) {
// No need to create an index on GUID; it's a UNIQUE column.
db.execSQL("CREATE INDEX reading_list_url ON " + tableName + "("
+ ReadingListItems.URL + ")");
db.execSQL("CREATE INDEX reading_list_content_status ON " + tableName + "("
+ ReadingListItems.CONTENT_STATUS + ")");
}
+ private void createUrlAnnotationsTable(final SQLiteDatabase db) {
+ debug("Creating " + UrlAnnotations.TABLE_NAME + " table");
+
+ db.execSQL("CREATE TABLE " + UrlAnnotations.TABLE_NAME + "(" +
+ UrlAnnotations._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
+ UrlAnnotations.URL + " TEXT NOT NULL, " +
+ UrlAnnotations.KEY + " TEXT NOT NULL, " +
+ UrlAnnotations.VALUE + " TEXT, " +
+ UrlAnnotations.DATE_CREATED + " INTEGER NOT NULL, " +
+ UrlAnnotations.DATE_MODIFIED + " INTEGER NOT NULL, " +
+ UrlAnnotations.SYNC_STATUS + " TINYINT NOT NULL DEFAULT " + UrlAnnotations.SyncStatus.NEW.getDBValue() +
+ " );");
+
+ db.execSQL("CREATE INDEX idx_url_annotations_url_key ON " +
+ UrlAnnotations.TABLE_NAME + "(" + UrlAnnotations.URL + ", " + UrlAnnotations.KEY + ")");
+ }
+
private void createOrUpdateAllSpecialFolders(SQLiteDatabase db) {
createOrUpdateSpecialFolder(db, Bookmarks.MOBILE_FOLDER_GUID,
R.string.bookmarks_folder_mobile, 0);
createOrUpdateSpecialFolder(db, Bookmarks.TOOLBAR_FOLDER_GUID,
R.string.bookmarks_folder_toolbar, 1);
createOrUpdateSpecialFolder(db, Bookmarks.MENU_FOLDER_GUID,
R.string.bookmarks_folder_menu, 2);
createOrUpdateSpecialFolder(db, Bookmarks.TAGS_FOLDER_GUID,
@@ -1027,16 +1045,21 @@ final class BrowserDatabaseHelper extend
private void upgradeDatabaseFrom25to26(SQLiteDatabase db) {
debug("Dropping unnecessary indices");
db.execSQL("DROP INDEX IF EXISTS clients_guid_index");
db.execSQL("DROP INDEX IF EXISTS thumbnails_url_index");
db.execSQL("DROP INDEX IF EXISTS favicons_url_index");
}
+ private void upgradeDatabaseFrom27to28(final SQLiteDatabase db) {
+ debug("Adding url annotations table");
+ createUrlAnnotationsTable(db);
+ }
+
private void createV19CombinedView(SQLiteDatabase db) {
db.execSQL("DROP VIEW IF EXISTS " + VIEW_COMBINED);
db.execSQL("DROP VIEW IF EXISTS " + VIEW_COMBINED_WITH_FAVICONS);
createCombinedViewOn19(db);
}
@Override
@@ -1110,16 +1133,20 @@ final class BrowserDatabaseHelper extend
case 25:
upgradeDatabaseFrom24to25(db);
break;
case 26:
upgradeDatabaseFrom25to26(db);
break;
+
+ case 28:
+ upgradeDatabaseFrom27to28(db);
+ break;
}
}
for (Table table : BrowserProvider.sTables) {
table.onUpgrade(db, oldVersion, newVersion);
}
// Delete the obsolete favicon database after all other upgrades complete.