1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.chrome.browser.dom_distiller;
7 import org.chromium.base.JNINamespace;
8 import org.chromium.base.ThreadUtils;
9 import org.chromium.chrome.browser.profiles.Profile;
10 import org.chromium.components.dom_distiller.core.DomDistillerService;
12 import java.util.HashMap;
15 * DomDistillerServiceFactory maps Profiles to instances of
16 * {@link DomDistillerService} instances. Each {@link Profile} will at most
17 * have one instance of this service. If the service does not already exist,
18 * it will be created on the first access.
20 @JNINamespace("dom_distiller::android")
21 public class DomDistillerServiceFactory {
23 private static final HashMap<Profile, DomDistillerService> sServiceMap =
24 new HashMap<Profile, DomDistillerService>();
27 * Returns Java DomDistillerService for given Profile.
29 public static DomDistillerService getForProfile(Profile profile) {
30 ThreadUtils.assertOnUiThread();
31 DomDistillerService service = sServiceMap.get(profile);
32 if (service == null) {
33 service = (DomDistillerService) nativeGetForProfile(profile);
34 sServiceMap.put(profile, service);
39 private static native DomDistillerService nativeGetForProfile(Profile profile);