mobile/android/base/background/healthreport/HealthReportDatabases.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

     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.background.healthreport;
     7 import java.io.File;
     8 import java.util.HashMap;
    10 import org.mozilla.gecko.background.common.log.Logger;
    12 import android.content.Context;
    14 /**
    15  * Manages a set of per-profile Health Report storage helpers.
    16  */
    17 public class HealthReportDatabases {
    18   private static final String LOG_TAG = "HealthReportDatabases";
    20   private Context context;
    21   private final HashMap<File, HealthReportDatabaseStorage> storages = new HashMap<File, HealthReportDatabaseStorage>();
    24   public HealthReportDatabases(final Context context) {
    25     this.context = context;
    26   }
    28   public synchronized HealthReportDatabaseStorage getDatabaseHelperForProfile(final File profileDir) {
    29     if (profileDir == null) {
    30       throw new IllegalArgumentException("No profile provided.");
    31     }
    33     if (this.storages.containsKey(profileDir)) {
    34       return this.storages.get(profileDir);
    35     }
    37     final HealthReportDatabaseStorage helper;
    38     helper = new HealthReportDatabaseStorage(this.context, profileDir);
    39     this.storages.put(profileDir, helper);
    40     return helper;
    41   }
    43   public synchronized void closeDatabaseHelpers() {
    44     for (HealthReportDatabaseStorage helper : storages.values()) {
    45       try {
    46         helper.close();
    47       } catch (Exception e) {
    48         Logger.warn(LOG_TAG, "Failed to close database helper.", e);
    49       }
    50     }
    51     storages.clear();
    52   }
    53 }

mercurial