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..ab73ebb8c925ddeb60fdaca959cc08cf0e972b6d 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,59 @@ 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() { |
| + assert !mClosed; |
| + mClosed = true; |
| + } |
| + |
| + 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++) |
|
mnaganov (inactive)
2015/01/29 16:56:20
nit: In Java you need to put curly brackets even a
sgurun-gerrit only
2015/01/29 19:15:40
Done.
|
| + portIds[i] = msgPorts[i].portId(); |
| + } |
| + mMessagePortService.postMessage(mPortId, message, portIds); |
| + } |
| } |