michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.db; michael@0: michael@0: import org.mozilla.gecko.db.PerProfileDatabases.DatabaseHelperFactory; michael@0: michael@0: import android.content.Context; michael@0: import android.database.sqlite.SQLiteOpenHelper; michael@0: michael@0: /** michael@0: * Abstract class containing methods needed to make a SQLite-based content michael@0: * provider with a database helper of type T, where one database helper is michael@0: * held per profile. michael@0: */ michael@0: public abstract class PerProfileDatabaseProvider extends AbstractPerProfileDatabaseProvider { michael@0: private PerProfileDatabases databases; michael@0: michael@0: @Override michael@0: protected PerProfileDatabases getDatabases() { michael@0: return databases; michael@0: } michael@0: michael@0: protected abstract String getDatabaseName(); michael@0: michael@0: /** michael@0: * Creates and returns an instance of the appropriate DB helper. michael@0: * michael@0: * @param context to use to create the database helper michael@0: * @param databasePath path to the DB file michael@0: * @return instance of the database helper michael@0: */ michael@0: protected abstract T createDatabaseHelper(Context context, String databasePath); michael@0: michael@0: @Override michael@0: public boolean onCreate() { michael@0: synchronized (this) { michael@0: databases = new PerProfileDatabases( michael@0: getContext(), getDatabaseName(), new DatabaseHelperFactory() { michael@0: @Override michael@0: public T makeDatabaseHelper(Context context, String databasePath) { michael@0: return createDatabaseHelper(context, databasePath); michael@0: } michael@0: }); michael@0: } michael@0: michael@0: return true; michael@0: } michael@0: }