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

Unified Diff: blimp/client/core/android/java/src/org/chromium/blimp/core/BlimpContentsObserverProxy.java

Issue 2059443002: Java versions of BlimpContents[,Observer] and BlimpNavigationController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-with-blimp
Patch Set: git merge origin/master - track master Created 4 years, 6 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: blimp/client/core/android/java/src/org/chromium/blimp/core/BlimpContentsObserverProxy.java
diff --git a/blimp/client/core/android/java/src/org/chromium/blimp/core/BlimpContentsObserverProxy.java b/blimp/client/core/android/java/src/org/chromium/blimp/core/BlimpContentsObserverProxy.java
new file mode 100644
index 0000000000000000000000000000000000000000..657c7bb852cd7ed35c548dc4512827d650607b75
--- /dev/null
+++ b/blimp/client/core/android/java/src/org/chromium/blimp/core/BlimpContentsObserverProxy.java
@@ -0,0 +1,53 @@
+// Copyright 2016 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.blimp.core;
+
+import org.chromium.base.ObserverList;
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+import org.chromium.blimp.core_public.BlimpContentsObserver;
+
+/**
+ * Serves as a compound observer proxy for dispatching BlimpContentsObserver callbacks,
+ * avoiding redundant JNI-related work when there are multiple Java-based observers.
+ */
+@JNINamespace("blimp::client")
+class BlimpContentsObserverProxy implements BlimpContentsObserver {
+ private final ObserverList<BlimpContentsObserver> mObservers = new ObserverList<>();
+
+ private long mNativeBlimpContentsObserverProxy;
+
+ BlimpContentsObserverProxy(BlimpContentsImpl blimpContentsImpl) {
+ mNativeBlimpContentsObserverProxy = nativeInit(blimpContentsImpl);
+ }
+
+ void destroy() {
+ if (mNativeBlimpContentsObserverProxy != 0) {
+ nativeDestroy(mNativeBlimpContentsObserverProxy);
+ mNativeBlimpContentsObserverProxy = 0;
+ }
+ mObservers.clear();
+ }
+
+ void addObserver(BlimpContentsObserver observer) {
+ assert mNativeBlimpContentsObserverProxy != 0;
+ mObservers.addObserver(observer);
+ }
+
+ void removeObserver(BlimpContentsObserver observer) {
+ mObservers.removeObserver(observer);
+ }
+
+ @Override
+ @CalledByNative
+ public void onUrlUpdated(String url) {
+ for (BlimpContentsObserver observer : mObservers) {
+ observer.onUrlUpdated(url);
+ }
+ }
+
+ private native long nativeInit(BlimpContentsImpl blimpContentsImpl);
+ private native void nativeDestroy(long nativeBlimpContentsObserverProxy);
+}

Powered by Google App Engine
This is Rietveld 408576698