Chromium Code Reviews| Index: components/cronet/android/test/src/org/chromium/cronet_test_apk/UploadDataStreamHandler.java |
| diff --git a/components/cronet/android/test/src/org/chromium/cronet_test_apk/UploadDataStreamHandler.java b/components/cronet/android/test/src/org/chromium/cronet_test_apk/UploadDataStreamHandler.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..da6cde9d4e34f1f31fde272eaa326132b04a6347 |
| --- /dev/null |
| +++ b/components/cronet/android/test/src/org/chromium/cronet_test_apk/UploadDataStreamHandler.java |
| @@ -0,0 +1,147 @@ |
| +// 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.cronet_test_apk; |
| + |
| +import android.os.ConditionVariable; |
| + |
| +import org.chromium.base.CalledByNative; |
| +import org.chromium.base.JNINamespace; |
| + |
| +@JNINamespace("cronet") |
| +public final class UploadDataStreamHandler { |
| + private long mUploadDataStreamHandler; |
| + private ConditionVariable mWaitInitComplete; |
| + private ConditionVariable mWaitInitCalled; |
| + private ConditionVariable mWaitReadComplete; |
| + private ConditionVariable mWaitResetComplete; |
| + // Waits for checkIfInitCallbackInvoked() returns result asynchronously. |
| + private ConditionVariable mWaitCheckInitCallback; |
| + // Waits for checkIfReadCallbackInvoked() returns result asynchronously. |
| + private ConditionVariable mWaitCheckReadCallback; |
| + |
| + private boolean mCheckInit = false; |
| + private boolean mCheckRead = false; |
| + // Indicates whether init completes synchronously. |
| + private int mInitSync = -1; |
| + |
| + public UploadDataStreamHandler(final long adapter) { |
| + mWaitReadComplete = new ConditionVariable(); |
| + mWaitInitComplete = new ConditionVariable(); |
| + mWaitInitCalled = new ConditionVariable(); |
| + mWaitResetComplete = new ConditionVariable(); |
| + mWaitCheckInitCallback = new ConditionVariable(); |
| + mWaitCheckReadCallback = new ConditionVariable(); |
| + mUploadDataStreamHandler = nativeCreateUploadDataStreamHandler(adapter); |
| + } |
| + |
| + // Returns whether init completes synchronously. |
| + public boolean init() { |
| + mWaitInitCalled.close(); |
| + nativeInit(mUploadDataStreamHandler); |
| + mWaitInitCalled.block(); |
| + if (mInitSync == 0) { |
| + return true; |
| + } |
| + return false; |
| + } |
| + |
| + public void read() { |
| + nativeRead(mUploadDataStreamHandler); |
| + } |
| + |
| + public void reset() { |
| + mWaitResetComplete.close(); |
| + nativeReset(mUploadDataStreamHandler); |
| + mWaitResetComplete.block(); |
| + } |
| + |
| + public boolean checkIfInitCallbackInvoked() { |
|
mmenke
2015/01/21 18:48:58
Suggest making this and the next method voids, and
xunjieli
2015/01/21 23:49:23
Done.
|
| + mWaitCheckInitCallback.close(); |
| + mCheckInit = false; |
|
mmenke
2015/01/21 18:48:58
This should be initialized to the opposite of what
xunjieli
2015/01/21 23:49:23
Done.
|
| + nativeCheckIfInitCallbackInvoked(mUploadDataStreamHandler); |
| + mWaitCheckInitCallback.block(); |
| + return mCheckInit; |
| + } |
| + |
| + public boolean checkIfReadCallbackInvoked() { |
| + mWaitCheckReadCallback.close(); |
| + mCheckRead = false; |
| + nativeCheckIfReadCallbackInvoked(mUploadDataStreamHandler); |
| + mWaitCheckReadCallback.block(); |
| + return mCheckRead; |
| + } |
| + |
| + public String getData() { |
| + String res = nativeGetData(mUploadDataStreamHandler); |
| + return nativeGetData(mUploadDataStreamHandler); |
| + } |
| + |
| + // Called on main test thread. |
| + public void waitForReadComplete() { |
| + mWaitReadComplete.block(); |
| + } |
| + |
| + // Called on main test thread. |
| + public void resetWaitForReadComplete() { |
| + mWaitReadComplete.close(); |
| + } |
| + |
| + // Called on main test thread. |
| + public void resetWaitForInitComplete() { |
| + mWaitInitComplete.close(); |
| + } |
| + |
| + // Called on main test thread. |
| + public void waitForInitComplete() { |
| + mWaitInitComplete.block(); |
| + } |
| + |
| + // Called on network thread. |
| + @CalledByNative |
| + private void onInitCalled(int res) { |
| + mInitSync = res; |
| + mWaitInitCalled.open(); |
| + } |
| + |
| + @CalledByNative |
| + // Called on network thread. |
| + private void onReadCompleted(int bytesRead) { |
| + mWaitReadComplete.open(); |
| + } |
| + |
| + @CalledByNative |
| + // Called on network thread. |
| + private void onInitCompleted(int res) { |
| + mWaitInitComplete.open(); |
| + } |
| + |
| + @CalledByNative |
| + // Called on network thread. |
| + private void onResetCompleted() { |
| + mWaitResetComplete.open(); |
| + } |
| + |
| + @CalledByNative |
| + // Called on network thread. |
| + private void onCheckIfInitCallbackInvoked(boolean res) { |
| + mCheckInit = res; |
| + mWaitCheckInitCallback.open(); |
| + } |
| + |
| + @CalledByNative |
| + // Called on network thread. |
| + private void onCheckIfReadCallbackInvoked(boolean res) { |
| + mCheckRead = res; |
| + mWaitCheckReadCallback.open(); |
| + } |
| + |
| + private static native void nativeInit(long uploadDataStreamAdapter); |
| + private static native void nativeRead(long uploadDataStreamAdapter); |
| + private static native void nativeReset(long uploadDataStreamAdapter); |
| + private static native String nativeGetData(long uploadDataStreamAdapter); |
| + private static native void nativeCheckIfInitCallbackInvoked(long uploadDataStreamAdapter); |
| + private static native void nativeCheckIfReadCallbackInvoked(long uploadDataStreamAdapter); |
| + private native long nativeCreateUploadDataStreamHandler(long uploadDataStreamAdapter); |
| +} |