1116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Copyright 2014 The Chromium Authors. All rights reserved. 2116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Use of this source code is governed by a BSD-style license that can be 3116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// found in the LICENSE file. 4116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 5116680a4aac90f2aa7413d9095a592090648e557Ben Murdochpackage org.chromium.chrome.browser.dom_distiller; 6116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 7116680a4aac90f2aa7413d9095a592090648e557Ben Murdochimport org.chromium.base.JNINamespace; 8116680a4aac90f2aa7413d9095a592090648e557Ben Murdochimport org.chromium.base.ThreadUtils; 9116680a4aac90f2aa7413d9095a592090648e557Ben Murdochimport org.chromium.chrome.browser.profiles.Profile; 10116680a4aac90f2aa7413d9095a592090648e557Ben Murdochimport org.chromium.components.dom_distiller.core.DomDistillerService; 11116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 12116680a4aac90f2aa7413d9095a592090648e557Ben Murdochimport java.util.HashMap; 13116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 14116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch/** 15116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch * DomDistillerServiceFactory maps Profiles to instances of 16116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch * {@link DomDistillerService} instances. Each {@link Profile} will at most 17116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch * have one instance of this service. If the service does not already exist, 18116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch * it will be created on the first access. 19116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch */ 20116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch@JNINamespace("dom_distiller::android") 21116680a4aac90f2aa7413d9095a592090648e557Ben Murdochpublic class DomDistillerServiceFactory { 22116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 23116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch private static final HashMap<Profile, DomDistillerService> sServiceMap = 24116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch new HashMap<Profile, DomDistillerService>(); 25116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 26116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /** 27116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch * Returns Java DomDistillerService for given Profile. 28116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch */ 29116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch public static DomDistillerService getForProfile(Profile profile) { 30116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch ThreadUtils.assertOnUiThread(); 31116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch DomDistillerService service = sServiceMap.get(profile); 32116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (service == null) { 33116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch service = (DomDistillerService) nativeGetForProfile(profile); 34116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch sServiceMap.put(profile, service); 35116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 36116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch return service; 37116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 38116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch private static native DomDistillerService nativeGetForProfile(Profile profile); 40116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 41