mobile/android/base/db/AbstractPerProfileDatabaseProvider.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 package org.mozilla.gecko.db;
     7 import org.mozilla.gecko.mozglue.RobocopTarget;
     9 import android.database.sqlite.SQLiteDatabase;
    10 import android.database.sqlite.SQLiteOpenHelper;
    11 import android.net.Uri;
    13 /**
    14  * The base class for ContentProviders that wish to use a different DB
    15  * for each profile.
    16  *
    17  * This class has logic shared between ordinary per-profile CPs and
    18  * those that wish to share DB connections between CPs.
    19  */
    20 public abstract class AbstractPerProfileDatabaseProvider extends AbstractTransactionalProvider {
    22     /**
    23      * Extend this to provide access to your own map of shared databases. This
    24      * is a method so that your subclass doesn't collide with others!
    25      */
    26     protected abstract PerProfileDatabases<? extends SQLiteOpenHelper> getDatabases();
    28     /*
    29      * Fetches a readable database based on the profile indicated in the
    30      * passed URI. If the URI does not contain a profile param, the default profile
    31      * is used.
    32      *
    33      * @param uri content URI optionally indicating the profile of the user
    34      * @return    instance of a readable SQLiteDatabase
    35      */
    36     @Override
    37     protected SQLiteDatabase getReadableDatabase(Uri uri) {
    38         String profile = null;
    39         if (uri != null) {
    40             profile = uri.getQueryParameter(BrowserContract.PARAM_PROFILE);
    41         }
    43         return getDatabases().getDatabaseHelperForProfile(profile, isTest(uri)).getReadableDatabase();
    44     }
    46     /*
    47      * Fetches a writable database based on the profile indicated in the
    48      * passed URI. If the URI does not contain a profile param, the default profile
    49      * is used
    50      *
    51      * @param uri content URI optionally indicating the profile of the user
    52      * @return    instance of a writable SQLiteDatabase
    53      */
    54     @Override
    55     protected SQLiteDatabase getWritableDatabase(Uri uri) {
    56         String profile = null;
    57         if (uri != null) {
    58             profile = uri.getQueryParameter(BrowserContract.PARAM_PROFILE);
    59         }
    61         return getDatabases().getDatabaseHelperForProfile(profile, isTest(uri)).getWritableDatabase();
    62     }
    64     protected SQLiteDatabase getWritableDatabaseForProfile(String profile, boolean isTest) {
    65         return getDatabases().getDatabaseHelperForProfile(profile, isTest).getWritableDatabase();
    66     }
    68     /**
    69      * This method should ONLY be used for testing purposes.
    70      *
    71      * @param uri content URI optionally indicating the profile of the user
    72      * @return    instance of a writable SQLiteDatabase
    73      */
    74     @Override
    75     @RobocopTarget
    76     public SQLiteDatabase getWritableDatabaseForTesting(Uri uri) {
    77         return getWritableDatabase(uri);
    78     }
    79 }

mercurial