Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.gecko.db;
7 import org.mozilla.gecko.db.PerProfileDatabases.DatabaseHelperFactory;
9 import android.content.Context;
10 import android.database.sqlite.SQLiteOpenHelper;
12 /**
13 * Abstract class containing methods needed to make a SQLite-based content
14 * provider with a database helper of type T, where one database helper is
15 * held per profile.
16 */
17 public abstract class PerProfileDatabaseProvider<T extends SQLiteOpenHelper> extends AbstractPerProfileDatabaseProvider {
18 private PerProfileDatabases<T> databases;
20 @Override
21 protected PerProfileDatabases<T> getDatabases() {
22 return databases;
23 }
25 protected abstract String getDatabaseName();
27 /**
28 * Creates and returns an instance of the appropriate DB helper.
29 *
30 * @param context to use to create the database helper
31 * @param databasePath path to the DB file
32 * @return instance of the database helper
33 */
34 protected abstract T createDatabaseHelper(Context context, String databasePath);
36 @Override
37 public boolean onCreate() {
38 synchronized (this) {
39 databases = new PerProfileDatabases<T>(
40 getContext(), getDatabaseName(), new DatabaseHelperFactory<T>() {
41 @Override
42 public T makeDatabaseHelper(Context context, String databasePath) {
43 return createDatabaseHelper(context, databasePath);
44 }
45 });
46 }
48 return true;
49 }
50 }