Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7732)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/invalidation/InvalidationServiceFactory.java

Issue 459513002: Massive refactor of the Android invalidation code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/invalidation/InvalidationServiceFactory.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/invalidation/InvalidationServiceFactory.java b/chrome/android/java/src/org/chromium/chrome/browser/invalidation/InvalidationServiceFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..e0086191c3a393727d945a45647fbe603ba9c068
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/invalidation/InvalidationServiceFactory.java
@@ -0,0 +1,47 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.invalidation;
+
+import android.content.Context;
+
+import org.chromium.base.JNINamespace;
+import org.chromium.base.ThreadUtils;
+import org.chromium.chrome.browser.profiles.Profile;
+import org.chromium.components.invalidation.InvalidationService;
+
+import java.util.HashMap;
+
+/**
+ * InvalidationServiceFactory maps Profiles to instances of
+ * {@link InvalidationService} instances. Each {@link Profile} will at most
+ * have one instance of this service. If the service does not already exist,
+ * it will be created on the first access.
+ */
+@JNINamespace("invalidation")
+public class InvalidationServiceFactory {
nyquist 2014/09/04 09:01:55 utility class (only statics), so add private empty
maxbogue 2014/09/05 16:42:45 Done.
+
+ private static final HashMap<Profile, InvalidationService> sServiceMap =
nyquist 2014/09/04 09:01:55 Just use Map for left hand side (Map<K, V> foo = n
maxbogue 2014/09/05 16:42:45 Done.
+ new HashMap<Profile, InvalidationService>();
+
+ /**
+ * Returns Java InvalidationService for the given Profile.
+ */
+ public static InvalidationService getForProfile(Profile profile) {
+ ThreadUtils.assertOnUiThread();
+ InvalidationService service = sServiceMap.get(profile);
+ if (service == null) {
+ service = (InvalidationService) nativeGetForProfile(profile);
nyquist 2014/09/04 09:01:55 unnecessary cast
maxbogue 2014/09/05 16:42:45 Done.
+ sServiceMap.put(profile, service);
+ }
+ return service;
+ }
+
+ public static InvalidationService getForTest(Context context) {
+ return (InvalidationService) nativeGetForTest(context);
nyquist 2014/09/04 09:01:55 unnecessary cast
maxbogue 2014/09/05 16:42:45 Done.
+ }
+
+ private static native InvalidationService nativeGetForProfile(Profile profile);
+ private static native InvalidationService nativeGetForTest(Context context);
+}

Powered by Google App Engine
This is Rietveld 408576698