mobile/android/base/db/PerProfileDatabaseProvider.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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 }

mercurial