Index: chrome/android/java/src/org/chromium/chrome/browser/push_messaging/PushMessagingServiceObserver.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/push_messaging/PushMessagingServiceObserver.java b/chrome/android/java/src/org/chromium/chrome/browser/push_messaging/PushMessagingServiceObserver.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2da8508e701c26d48a73f2093f7970cb0c1193fa |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/push_messaging/PushMessagingServiceObserver.java |
@@ -0,0 +1,56 @@ |
+// Copyright 2015 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.push_messaging; |
+ |
+import org.chromium.base.ThreadUtils; |
+import org.chromium.base.VisibleForTesting; |
+import org.chromium.base.annotations.CalledByNative; |
+import org.chromium.base.annotations.JNINamespace; |
+ |
+import javax.annotation.Nullable; |
+ |
+/** |
+ * Observes events and changes in the PushMessagingService. |
+ * |
+ * Threading model: UI thread only. |
+ * |
+ * TODO(peter): Delete this class once delivery receipts are implemented and use those instead. This |
+ * really only exists for test purposes. |
+ */ |
+@JNINamespace("chrome::android") |
+public class PushMessagingServiceObserver { |
+ /** |
+ * The listener that needs to be notified of events and changes observed by the |
+ * PushMessagingServiceObserver. May be null. |
+ */ |
+ @Nullable private static Listener sListener; |
+ |
+ /** |
+ * Interface for the listener that needs to be notified of events and changes observed by the |
+ * PushMessagingServiceObserver. |
+ */ |
+ public interface Listener { |
+ /** |
+ * Called when a push message has been handled. |
+ */ |
+ void onMessageHandled(); |
+ } |
+ |
+ @VisibleForTesting |
+ public static void setListenerForTesting(@Nullable Listener listener) { |
+ ThreadUtils.assertOnUiThread(); |
+ sListener = listener; |
+ } |
+ |
+ @CalledByNative |
+ private static void onMessageHandled() { |
+ ThreadUtils.assertOnUiThread(); |
+ if (sListener != null) { |
+ sListener.onMessageHandled(); |
+ } |
+ } |
+ |
+ private PushMessagingServiceObserver() {} // Private. Not meant to be instantiated. |
+} |