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 #include "test_upload_data_stream_handler.h" | 5 #include "test_upload_data_stream_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 157 } |
158 | 158 |
159 void TestUploadDataStreamHandler::NotifyJavaReadCompleted() { | 159 void TestUploadDataStreamHandler::NotifyJavaReadCompleted() { |
160 DCHECK(network_thread_->task_runner()->BelongsToCurrentThread()); | 160 DCHECK(network_thread_->task_runner()->BelongsToCurrentThread()); |
161 JNIEnv* env = base::android::AttachCurrentThread(); | 161 JNIEnv* env = base::android::AttachCurrentThread(); |
162 std::string data_read = ""; | 162 std::string data_read = ""; |
163 if (read_buffer_.get() && bytes_read_ > 0) | 163 if (read_buffer_.get() && bytes_read_ > 0) |
164 data_read = std::string(read_buffer_->data(), bytes_read_); | 164 data_read = std::string(read_buffer_->data(), bytes_read_); |
165 cronet::Java_TestUploadDataStreamHandler_onReadCompleted( | 165 cronet::Java_TestUploadDataStreamHandler_onReadCompleted( |
166 env, jtest_upload_data_stream_handler_.obj(), bytes_read_, | 166 env, jtest_upload_data_stream_handler_.obj(), bytes_read_, |
167 base::android::ConvertUTF8ToJavaString(env, data_read).Release()); | 167 base::android::ConvertUTF8ToJavaString(env, data_read).obj()); |
168 } | 168 } |
169 | 169 |
170 static jlong CreateTestUploadDataStreamHandler( | 170 static jlong CreateTestUploadDataStreamHandler( |
171 JNIEnv* env, | 171 JNIEnv* env, |
172 jobject jtest_upload_data_stream_handler, | 172 jobject jtest_upload_data_stream_handler, |
173 jlong jupload_data_stream) { | 173 jlong jupload_data_stream) { |
174 scoped_ptr<net::UploadDataStream> upload_data_stream( | 174 scoped_ptr<net::UploadDataStream> upload_data_stream( |
175 reinterpret_cast<net::UploadDataStream*>(jupload_data_stream)); | 175 reinterpret_cast<net::UploadDataStream*>(jupload_data_stream)); |
176 TestUploadDataStreamHandler* handler = new TestUploadDataStreamHandler( | 176 TestUploadDataStreamHandler* handler = new TestUploadDataStreamHandler( |
177 upload_data_stream.Pass(), env, jtest_upload_data_stream_handler); | 177 upload_data_stream.Pass(), env, jtest_upload_data_stream_handler); |
178 return reinterpret_cast<jlong>(handler); | 178 return reinterpret_cast<jlong>(handler); |
179 } | 179 } |
180 | 180 |
181 bool TestUploadDataStreamHandlerRegisterJni(JNIEnv* env) { | 181 bool TestUploadDataStreamHandlerRegisterJni(JNIEnv* env) { |
182 return RegisterNativesImpl(env); | 182 return RegisterNativesImpl(env); |
183 } | 183 } |
184 | 184 |
185 } // namespace cronet | 185 } // namespace cronet |
OLD | NEW |