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

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java

Issue 956763002: Implement the close() API for Message ports (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address Nasko review Created 5 years, 10 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: android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java b/android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java
index 8d2c499d7c67989cfa831269bfa95fac24314ed6..ddc09a08423e9b5d875e6e416c98042389064805 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwMessagePortService.java
@@ -92,6 +92,12 @@ public class AwMessagePortService {
private SparseArray<MessagePort> mMessagePorts = new SparseArray<MessagePort>();
private Object mLock = new Object();
+ public void remove(int portId) {
+ synchronized (mLock) {
+ mMessagePorts.remove(portId);
+ }
+ }
+
public void put(int portId, MessagePort m) {
synchronized (mLock) {
mMessagePorts.put(portId, m);
@@ -123,12 +129,17 @@ public class AwMessagePortService {
mObserverList.removeObserver(observer);
}
+ public void closePort(int messagePortId) {
+ mPortStorage.remove(messagePortId);
+ if (mNativeMessagePortService == 0) return;
+ nativeClosePort(mNativeMessagePortService, messagePortId);
+ }
+
public void postMessage(int senderId, String message, int[] sentPorts) {
// verify that webview still owns the port (not transferred)
if (mPortStorage.get(senderId) == null) {
throw new IllegalStateException("Cannot post to unknown port " + senderId);
}
- removeSentPorts(sentPorts);
if (mNativeMessagePortService == 0) return;
nativePostAppToWebMessage(mNativeMessagePortService, senderId, message, sentPorts);
}
@@ -141,7 +152,7 @@ public class AwMessagePortService {
if (p == null) {
throw new IllegalStateException("Cannot transfer unknown port " + port);
}
- mPortStorage.put(port, null);
+ mPortStorage.remove(port);
}
}
}
@@ -190,4 +201,6 @@ public class AwMessagePortService {
private native long nativeInitAwMessagePortService();
private native void nativePostAppToWebMessage(long nativeAwMessagePortServiceImpl,
int senderId, String message, int[] portIds);
+ private native void nativeClosePort(long nativeAwMessagePortServiceImpl,
+ int messagePortId);
}

Powered by Google App Engine
This is Rietveld 408576698