diff -r 000000000000 -r 6474c204b198 mobile/android/base/db/PerProfileDatabaseProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mobile/android/base/db/PerProfileDatabaseProvider.java Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,50 @@ +/* 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 org.mozilla.gecko.db.PerProfileDatabases.DatabaseHelperFactory; + +import android.content.Context; +import android.database.sqlite.SQLiteOpenHelper; + +/** + * Abstract class containing methods needed to make a SQLite-based content + * provider with a database helper of type T, where one database helper is + * held per profile. + */ +public abstract class PerProfileDatabaseProvider extends AbstractPerProfileDatabaseProvider { + private PerProfileDatabases databases; + + @Override + protected PerProfileDatabases getDatabases() { + return databases; + } + + protected abstract String getDatabaseName(); + + /** + * Creates and returns an instance of the appropriate DB helper. + * + * @param context to use to create the database helper + * @param databasePath path to the DB file + * @return instance of the database helper + */ + protected abstract T createDatabaseHelper(Context context, String databasePath); + + @Override + public boolean onCreate() { + synchronized (this) { + databases = new PerProfileDatabases( + getContext(), getDatabaseName(), new DatabaseHelperFactory() { + @Override + public T makeDatabaseHelper(Context context, String databasePath) { + return createDatabaseHelper(context, databasePath); + } + }); + } + + return true; + } +}