1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/background/healthreport/HealthReportDatabases.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,53 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +package org.mozilla.gecko.background.healthreport; 1.9 + 1.10 +import java.io.File; 1.11 +import java.util.HashMap; 1.12 + 1.13 +import org.mozilla.gecko.background.common.log.Logger; 1.14 + 1.15 +import android.content.Context; 1.16 + 1.17 +/** 1.18 + * Manages a set of per-profile Health Report storage helpers. 1.19 + */ 1.20 +public class HealthReportDatabases { 1.21 + private static final String LOG_TAG = "HealthReportDatabases"; 1.22 + 1.23 + private Context context; 1.24 + private final HashMap<File, HealthReportDatabaseStorage> storages = new HashMap<File, HealthReportDatabaseStorage>(); 1.25 + 1.26 + 1.27 + public HealthReportDatabases(final Context context) { 1.28 + this.context = context; 1.29 + } 1.30 + 1.31 + public synchronized HealthReportDatabaseStorage getDatabaseHelperForProfile(final File profileDir) { 1.32 + if (profileDir == null) { 1.33 + throw new IllegalArgumentException("No profile provided."); 1.34 + } 1.35 + 1.36 + if (this.storages.containsKey(profileDir)) { 1.37 + return this.storages.get(profileDir); 1.38 + } 1.39 + 1.40 + final HealthReportDatabaseStorage helper; 1.41 + helper = new HealthReportDatabaseStorage(this.context, profileDir); 1.42 + this.storages.put(profileDir, helper); 1.43 + return helper; 1.44 + } 1.45 + 1.46 + public synchronized void closeDatabaseHelpers() { 1.47 + for (HealthReportDatabaseStorage helper : storages.values()) { 1.48 + try { 1.49 + helper.close(); 1.50 + } catch (Exception e) { 1.51 + Logger.warn(LOG_TAG, "Failed to close database helper.", e); 1.52 + } 1.53 + } 1.54 + storages.clear(); 1.55 + } 1.56 +}