Chromium Code Reviews| Index: components/cronet/android/test/upload_data_stream_handler.h | 
| diff --git a/components/cronet/android/test/upload_data_stream_handler.h b/components/cronet/android/test/upload_data_stream_handler.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..547e674888134f7043563700ad4f4eb5376c1e1b | 
| --- /dev/null | 
| +++ b/components/cronet/android/test/upload_data_stream_handler.h | 
| @@ -0,0 +1,98 @@ | 
| +// Copyright 2015 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. | 
| + | 
| +#ifndef COMPONENTS_CRONET_ANDROID_TEST_UPLOAD_DATA_STREAM_HANDLER_H_ | 
| +#define COMPONENTS_CRONET_ANDROID_TEST_UPLOAD_DATA_STREAM_HANDLER_H_ | 
| + | 
| +#include <jni.h> | 
| + | 
| +#include "base/android/scoped_java_ref.h" | 
| +#include "base/macros.h" | 
| +#include "base/memory/ref_counted.h" | 
| +#include "base/memory/scoped_ptr.h" | 
| +#include "base/threading/thread.h" | 
| +#include "components/cronet/android/cronet_upload_data_stream_adapter.h" | 
| +#include "net/base/io_buffer.h" | 
| + | 
| +namespace cronet { | 
| + | 
| +/** | 
| + * This class sets up the JNI for Java tests to invoke methods on the native | 
| + * CronetUploadDataStreamAdapter. | 
| 
 
mmenke
2015/02/18 21:06:24
This comment seems a bit misleading...  Maybe some
 
xunjieli
2015/02/19 14:59:11
Done.
 
 | 
| + */ | 
| +class UploadDataStreamHandler { | 
| + public: | 
| + UploadDataStreamHandler(CronetUploadDataStreamAdapter* adapter, | 
| 
 
mmenke
2015/02/18 21:06:24
Actually, can we just make this an UploadDataStrea
 
mmenke
2015/02/18 21:06:24
scoped_ptr<CronetUploadDataStreamAdapter>, to make
 
xunjieli
2015/02/19 14:59:11
Done.
 
xunjieli
2015/02/19 14:59:12
Done.
 
 | 
| + JNIEnv* env, | 
| + jobject jupload_data_stream_handler); | 
| + | 
| + ~UploadDataStreamHandler(); | 
| + | 
| + // Destroys |network_thread_| created by this class. | 
| + void Destroy(JNIEnv* env, jobject jcaller); | 
| + | 
| + // Posts a task to |network_thread_| to call the corresponding method of | 
| + // CronetUploadDataStreamAdapter on |adapter_|. | 
| + | 
| + void Init(JNIEnv* env, jobject jcaller); | 
| + void Read(JNIEnv* env, jobject jcaller); | 
| + void Reset(JNIEnv* env, jobject jcaller); | 
| + | 
| + // Posts a task to |network_thread_| to check whether init complete callback | 
| + // has been invoked by net::UploadDataStream, and notifies the Java side of | 
| + // the result. | 
| + void CheckInitCallbackNotInvoked(JNIEnv* env, jobject jcaller); | 
| + // Posts a task to |network_thread_| to check whether read complete callback | 
| + // has been invoked by net::UploadDataStream, and notifies the Java side of | 
| + // the result. | 
| + void CheckReadCallbackNotInvoked(JNIEnv* env, jobject jcaller); | 
| + | 
| + private: | 
| + // Complete callbacks that are passed to the |adapter_|. | 
| + void OnInitCompleted(int res); | 
| + void OnReadCompleted(int res); | 
| + | 
| + // Helper methods that run corresponding task on |network_thread_|. | 
| + | 
| + void InitOnNetworkThread(); | 
| + void ReadOnNetworkThread(); | 
| + void ResetOnNetworkThread(); | 
| + void CheckInitCallbackNotInvokedOnNetworkThread(); | 
| + void CheckReadCallbackNotInvokedOnNetworkThread(); | 
| + | 
| + // Notify the Java UploadDataStreamHandler that read has completed. | 
| + void NotifyJavaReadCompleted(); | 
| + | 
| + // True if |OnInitCompleted| callback has been invoked. It is set to false | 
| + // when init or reset is called again. Created on a Java thread, but are only | 
| 
 
mmenke
2015/02/18 21:06:24
are -> is
 
xunjieli
2015/02/19 14:59:11
Done.
 
 | 
| + // accessed from |network_thread_|. | 
| + bool init_callback_invoked_; | 
| + // True if |OnReadCompleted| callback has been invoked. It is set to false | 
| + // when init or reset is called again. Created on a Java thread, but are only | 
| 
 
mmenke
2015/02/18 21:06:24
are -> is
 
xunjieli
2015/02/19 14:59:11
Done.
 
 | 
| + // accessed from |network_thread_|. | 
| + bool read_callback_invoked_; | 
| + // Indicates the number of bytes read. It is reset to 0 when init, reset, or | 
| 
 
mmenke
2015/02/18 21:06:24
are -> is
 
xunjieli
2015/02/19 14:59:11
Done.
 
 | 
| + // read is called again. Created on a Java thread, but are only accessed from | 
| + // |network_thread_|. | 
| + int bytes_read_; | 
| + | 
| + // Created and destroyed on the same Java thread. This is where methods of | 
| + // CronetUploadDataStreamAdapter run on. | 
| + scoped_ptr<base::Thread> network_thread_; | 
| + // Created on a Java thread. Accessed only on |network_thread_|. | 
| + scoped_ptr<CronetUploadDataStreamAdapter> adapter_; | 
| + // Created and accessed only on |network_thread_|. | 
| + scoped_refptr<net::IOBufferWithSize> read_buffer_; | 
| + // A Java reference pointer for calling methods on the Java | 
| + // UploadDataStreamHandler object. Initialized during construction. | 
| + base::android::ScopedJavaGlobalRef<jobject> jupload_data_stream_handler_; | 
| + | 
| + DISALLOW_COPY_AND_ASSIGN(UploadDataStreamHandler); | 
| +}; | 
| + | 
| +bool UploadDataStreamHandlerRegisterJni(JNIEnv* env); | 
| + | 
| +} // namespace cronet | 
| + | 
| +#endif // COMPONENTS_CRONET_ANDROID_TEST_UPLOAD_DATA_STREAM_HANDLER_H_ |