Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / android / java / src / org / chromium / chrome / browser / dom_distiller / DomDistillerServiceFactory.java
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.
4
5 package org.chromium.chrome.browser.dom_distiller;
6
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;
11
12 import java.util.HashMap;
13
14 /**
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.
19  */
20 @JNINamespace("dom_distiller::android")
21 public class DomDistillerServiceFactory {
22
23     private static final HashMap<Profile, DomDistillerService> sServiceMap =
24             new HashMap<Profile, DomDistillerService>();
25
26     /**
27      * Returns Java DomDistillerService for given Profile.
28      */
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);
35         }
36         return service;
37     }
38
39     private static native DomDistillerService nativeGetForProfile(Profile profile);
40 }