Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | package org.mozilla.gecko.background.healthreport; |
michael@0 | 6 | |
michael@0 | 7 | import java.io.File; |
michael@0 | 8 | import java.util.HashMap; |
michael@0 | 9 | |
michael@0 | 10 | import org.mozilla.gecko.background.common.log.Logger; |
michael@0 | 11 | |
michael@0 | 12 | import android.content.Context; |
michael@0 | 13 | |
michael@0 | 14 | /** |
michael@0 | 15 | * Manages a set of per-profile Health Report storage helpers. |
michael@0 | 16 | */ |
michael@0 | 17 | public class HealthReportDatabases { |
michael@0 | 18 | private static final String LOG_TAG = "HealthReportDatabases"; |
michael@0 | 19 | |
michael@0 | 20 | private Context context; |
michael@0 | 21 | private final HashMap<File, HealthReportDatabaseStorage> storages = new HashMap<File, HealthReportDatabaseStorage>(); |
michael@0 | 22 | |
michael@0 | 23 | |
michael@0 | 24 | public HealthReportDatabases(final Context context) { |
michael@0 | 25 | this.context = context; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | public synchronized HealthReportDatabaseStorage getDatabaseHelperForProfile(final File profileDir) { |
michael@0 | 29 | if (profileDir == null) { |
michael@0 | 30 | throw new IllegalArgumentException("No profile provided."); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | if (this.storages.containsKey(profileDir)) { |
michael@0 | 34 | return this.storages.get(profileDir); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | final HealthReportDatabaseStorage helper; |
michael@0 | 38 | helper = new HealthReportDatabaseStorage(this.context, profileDir); |
michael@0 | 39 | this.storages.put(profileDir, helper); |
michael@0 | 40 | return helper; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | public synchronized void closeDatabaseHelpers() { |
michael@0 | 44 | for (HealthReportDatabaseStorage helper : storages.values()) { |
michael@0 | 45 | try { |
michael@0 | 46 | helper.close(); |
michael@0 | 47 | } catch (Exception e) { |
michael@0 | 48 | Logger.warn(LOG_TAG, "Failed to close database helper.", e); |
michael@0 | 49 | } |
michael@0 | 50 | } |
michael@0 | 51 | storages.clear(); |
michael@0 | 52 | } |
michael@0 | 53 | } |