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 michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.background.healthreport; michael@0: michael@0: import java.io.File; michael@0: import java.util.HashMap; michael@0: michael@0: import org.mozilla.gecko.background.common.log.Logger; michael@0: michael@0: import android.content.Context; michael@0: michael@0: /** michael@0: * Manages a set of per-profile Health Report storage helpers. michael@0: */ michael@0: public class HealthReportDatabases { michael@0: private static final String LOG_TAG = "HealthReportDatabases"; michael@0: michael@0: private Context context; michael@0: private final HashMap storages = new HashMap(); michael@0: michael@0: michael@0: public HealthReportDatabases(final Context context) { michael@0: this.context = context; michael@0: } michael@0: michael@0: public synchronized HealthReportDatabaseStorage getDatabaseHelperForProfile(final File profileDir) { michael@0: if (profileDir == null) { michael@0: throw new IllegalArgumentException("No profile provided."); michael@0: } michael@0: michael@0: if (this.storages.containsKey(profileDir)) { michael@0: return this.storages.get(profileDir); michael@0: } michael@0: michael@0: final HealthReportDatabaseStorage helper; michael@0: helper = new HealthReportDatabaseStorage(this.context, profileDir); michael@0: this.storages.put(profileDir, helper); michael@0: return helper; michael@0: } michael@0: michael@0: public synchronized void closeDatabaseHelpers() { michael@0: for (HealthReportDatabaseStorage helper : storages.values()) { michael@0: try { michael@0: helper.close(); michael@0: } catch (Exception e) { michael@0: Logger.warn(LOG_TAG, "Failed to close database helper.", e); michael@0: } michael@0: } michael@0: storages.clear(); michael@0: } michael@0: }