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.invalidation;
7 import android.content.Context;
9 import org.chromium.base.JNINamespace;
10 import org.chromium.base.ThreadUtils;
11 import org.chromium.chrome.browser.profiles.Profile;
12 import org.chromium.components.invalidation.InvalidationService;
14 import java.util.HashMap;
18 * InvalidationServiceFactory maps Profiles to instances of
19 * {@link InvalidationService} instances. Each {@link Profile} will at most
20 * have one instance of this service. If the service does not already exist,
21 * it will be created on the first access.
23 @JNINamespace("invalidation")
24 public final class InvalidationServiceFactory {
26 private static final Map<Profile, InvalidationService> sServiceMap =
27 new HashMap<Profile, InvalidationService>();
29 private InvalidationServiceFactory() {}
32 * Returns Java InvalidationService for the given Profile.
34 public static InvalidationService getForProfile(Profile profile) {
35 ThreadUtils.assertOnUiThread();
36 InvalidationService service = sServiceMap.get(profile);
37 if (service == null) {
38 service = nativeGetForProfile(profile);
39 sServiceMap.put(profile, service);
44 public static InvalidationService getForTest(Context context) {
45 return nativeGetForTest(context);
48 private static native InvalidationService nativeGetForProfile(Profile profile);
49 private static native InvalidationService nativeGetForTest(Context context);