| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_ | 5 #ifndef COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_ |
| 6 #define COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_ | 6 #define COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_ |
| 7 | 7 |
| 8 #include <jni.h> | 8 #include <jni.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/android/scoped_java_ref.h" | 12 #include "base/android/scoped_java_ref.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/threading/thread.h" | |
| 16 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 17 #include "net/base/upload_data_stream.h" | 16 #include "net/base/upload_data_stream.h" |
| 18 | 17 |
| 19 namespace cronet { | 18 namespace cronet { |
| 20 | 19 |
| 21 /** | 20 /** |
| 22 * This class allows a net::UploadDataStream to be driven directly from | 21 * This class allows a net::UploadDataStream to be driven directly from |
| 23 * Java, for use in tests. | 22 * Java, for use in tests. |
| 24 */ | 23 */ |
| 25 class TestUploadDataStreamHandler { | 24 class TestUploadDataStreamHandler { |
| 26 public: | 25 public: |
| 27 TestUploadDataStreamHandler( | 26 TestUploadDataStreamHandler( |
| 28 std::unique_ptr<net::UploadDataStream> upload_data_stream, | 27 std::unique_ptr<net::UploadDataStream> upload_data_stream, |
| 29 JNIEnv* env, | 28 JNIEnv* env, |
| 30 jobject jtest_upload_data_stream_handler); | 29 jobject jtest_upload_data_stream_handler, |
| 30 jlong jsingle_thread_task_runner); |
| 31 | 31 |
| 32 ~TestUploadDataStreamHandler(); | 32 ~TestUploadDataStreamHandler(); |
| 33 | 33 |
| 34 // Destroys |network_thread_| created by this class. | 34 // Destroys |network_thread_| created by this class. |
| 35 void Destroy(JNIEnv* env, | 35 void Destroy(JNIEnv* env, |
| 36 const base::android::JavaParamRef<jobject>& jcaller); | 36 const base::android::JavaParamRef<jobject>& jcaller); |
| 37 | 37 |
| 38 // Posts a task to |network_thread_| to call the corresponding method of | 38 // Posts a task to |network_thread_| to call the corresponding method of |
| 39 // net::UploadDataStream on |upload_data_stream_|. | 39 // net::UploadDataStream on |upload_data_stream_|. |
| 40 | 40 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // when init or reset is called again. Created on a Java thread, but is only | 79 // when init or reset is called again. Created on a Java thread, but is only |
| 80 // accessed from |network_thread_|. | 80 // accessed from |network_thread_|. |
| 81 bool read_callback_invoked_; | 81 bool read_callback_invoked_; |
| 82 // Indicates the number of bytes read. It is reset to 0 when init, reset, or | 82 // Indicates the number of bytes read. It is reset to 0 when init, reset, or |
| 83 // read is called again. Created on a Java thread, but is only accessed from | 83 // read is called again. Created on a Java thread, but is only accessed from |
| 84 // |network_thread_|. | 84 // |network_thread_|. |
| 85 int bytes_read_; | 85 int bytes_read_; |
| 86 | 86 |
| 87 // Created and destroyed on the same Java thread. This is where methods of | 87 // Created and destroyed on the same Java thread. This is where methods of |
| 88 // net::UploadDataStream run on. | 88 // net::UploadDataStream run on. |
| 89 std::unique_ptr<base::Thread> network_thread_; | 89 base::SingleThreadTaskRunner* network_thread_; |
| 90 // Created on a Java thread. Accessed only on |network_thread_|. | 90 // Created on a Java thread. Accessed only on |network_thread_|. |
| 91 std::unique_ptr<net::UploadDataStream> upload_data_stream_; | 91 std::unique_ptr<net::UploadDataStream> upload_data_stream_; |
| 92 // Created and accessed only on |network_thread_|. | 92 // Created and accessed only on |network_thread_|. |
| 93 scoped_refptr<net::IOBufferWithSize> read_buffer_; | 93 scoped_refptr<net::IOBufferWithSize> read_buffer_; |
| 94 // A Java reference pointer for calling methods on the Java | 94 // A Java reference pointer for calling methods on the Java |
| 95 // TestUploadDataStreamHandler object. Initialized during construction. | 95 // TestUploadDataStreamHandler object. Initialized during construction. |
| 96 base::android::ScopedJavaGlobalRef<jobject> jtest_upload_data_stream_handler_; | 96 base::android::ScopedJavaGlobalRef<jobject> jtest_upload_data_stream_handler_; |
| 97 | 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(TestUploadDataStreamHandler); | 98 DISALLOW_COPY_AND_ASSIGN(TestUploadDataStreamHandler); |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 bool TestUploadDataStreamHandlerRegisterJni(JNIEnv* env); | 101 bool TestUploadDataStreamHandlerRegisterJni(JNIEnv* env); |
| 102 | 102 |
| 103 } // namespace cronet | 103 } // namespace cronet |
| 104 | 104 |
| 105 #endif // COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_ | 105 #endif // COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_ |
| OLD | NEW |