Chromium Code Reviews| Index: android_webview/java/src/org/chromium/android_webview/MessagePort.java |
| diff --git a/android_webview/java/src/org/chromium/android_webview/MessagePort.java b/android_webview/java/src/org/chromium/android_webview/MessagePort.java |
| index ef0e8d779655c66aa3de642ee04a95c85bf6d227..8073df46a280645d42c464bda58c8af174d04000 100644 |
| --- a/android_webview/java/src/org/chromium/android_webview/MessagePort.java |
| +++ b/android_webview/java/src/org/chromium/android_webview/MessagePort.java |
| @@ -19,28 +19,58 @@ public class MessagePort { |
| void onMessage(String message); |
| }; |
| - private static final String TAG = "AwMessagePortService"; |
| + private static final String TAG = "MessagePort"; |
| private int mPortId; |
| private MessageHandler mHandler; |
| + private AwMessagePortService mMessagePortService; |
| + // A port is put into a closed state when transferred. Such a port can no longer |
| + // send or receive messages. |
| + private boolean mClosed; |
| - public MessagePort(int portId) { |
| + public MessagePort(int portId, AwMessagePortService messagePortService) { |
| mPortId = portId; |
| + mMessagePortService = messagePortService; |
| } |
| public int portId() { |
| return mPortId; |
| } |
| + public void close() { |
| + mClosed = true; |
|
mnaganov (inactive)
2015/01/27 13:30:17
I guess, it is an error to attempt to close the po
sgurun-gerrit only
2015/01/29 03:06:08
Done.
|
| + } |
| + |
| + public boolean isClosed() { |
| + return mClosed; |
| + } |
| + |
| public void setMessageHandler(MessageHandler handler) { |
| mHandler = handler; |
| } |
| public void onMessage(String message) { |
| + if (isClosed()) { |
| + Log.w(TAG, "Port [" + mPortId + "] received message in closed state"); |
| + return; |
| + } |
| if (mHandler == null) { |
| Log.w(TAG, "No handler set for port [" + mPortId + "], dropping message " + message); |
| return; |
| } |
| mHandler.onMessage(message); |
| } |
| + |
| + public void postMessage(String message, MessagePort[] msgPorts) throws IllegalStateException { |
| + if (isClosed()) { |
| + throw new IllegalStateException("Messageport is already closed"); |
| + } |
| + int[] portIds = null; |
| + if (msgPorts != null) { |
| + portIds = new int[msgPorts.length]; |
| + for (int i = 0; i < msgPorts.length; i++) |
| + portIds[i] = msgPorts[i].portId(); |
| + } |
| + mMessagePortService.postMessage(mPortId, message, portIds); |
| + } |
| } |