Index: components/devtools_bridge/android/java/src/org/chromium/components/devtools_bridge/AbstractDataChannel.java |
diff --git a/components/devtools_bridge/android/java/src/org/chromium/components/devtools_bridge/AbstractDataChannel.java b/components/devtools_bridge/android/java/src/org/chromium/components/devtools_bridge/AbstractDataChannel.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..90687546d501615a0d41f39681bcabb645703b8b |
--- /dev/null |
+++ b/components/devtools_bridge/android/java/src/org/chromium/components/devtools_bridge/AbstractDataChannel.java |
@@ -0,0 +1,49 @@ |
+// Copyright 2014 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.components.devtools_bridge; |
+ |
+import java.nio.ByteBuffer; |
+ |
+/** |
+ * Limited view on org.webrtc.DataChannel. Abstraction layer helps with: |
+ * 1. Mocking in tests. There is no need to emulate full set of features of the DataChannel. |
+ * 2. Allows both native and Java API implementation for WebRTC data channel. |
+ * 3. Hides unused features. |
+ * Only SCTP data channels supported. |
+ */ |
+public abstract class AbstractDataChannel { |
mnaganov (inactive)
2014/09/12 13:37:29
Do we need to mention here that data channel is th
SeRya
2014/09/15 15:20:00
It's worth to be mentioned indeed.
|
+ /** |
+ * Observer's callbacks are called on WebRTC signaling thread (or it's equivalent in tests). |
+ */ |
+ public interface Observer { |
+ // Only 2 states of channel are important here: OPEN and everything else. |
+ void onStateChange(boolean open); |
mnaganov (inactive)
2014/09/12 13:37:29
Does it make sense to use an enum here -- for clar
SeRya
2014/09/15 15:20:00
Done.
|
+ |
+ // TEXT and BINARY messages should be handled equally. Size of the message is |
+ // |message|.remaining(). |message| may reference to a native buffer on stack so |
+ // the reference to the buffer must not outlive the invokation. |
mnaganov (inactive)
2014/09/12 13:37:29
typo: invocation
SeRya
2014/09/15 15:20:00
Done.
|
+ void onMessage(ByteBuffer message); |
+ } |
+ |
+ // Type is only significant for JavaScript-based counterpart. TEXT messages will |
+ // be observed as strings, BINARY as ByteArray's. |
+ public enum MessageType { |
+ TEXT, BINARY |
+ } |
+ |
+ public abstract void registerObserver(Observer observer); |
+ |
+ // Observer unregistration synchronized with signaling thread. If some data modified |
+ // in observer callbacks without additional synchronization it's safe to access |
+ // this data on the current thread after calling this method. |
+ public abstract void unregisterObserver(); |
+ |
+ // Message size is |message|.remaining(). |
+ public abstract void send(ByteBuffer message, MessageType type); |
+ |
+ public abstract void close(); |
+ |
+ public abstract void dispose(); |
+} |