Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/cronet/android/org_chromium_net_UrlRequest.h" | 5 #include "components/cronet/android/org_chromium_net_UrlRequest.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "components/cronet/android/url_request_context_peer.h" | 10 #include "components/cronet/android/url_request_context_peer.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 | 63 |
| 64 virtual void OnResponseStarted(URLRequestPeer* request) OVERRIDE { | 64 virtual void OnResponseStarted(URLRequestPeer* request) OVERRIDE { |
| 65 JNIEnv* env = base::android::AttachCurrentThread(); | 65 JNIEnv* env = base::android::AttachCurrentThread(); |
| 66 cronet::Java_UrlRequest_onResponseStarted(env, owner_); | 66 cronet::Java_UrlRequest_onResponseStarted(env, owner_); |
| 67 } | 67 } |
| 68 | 68 |
| 69 virtual void OnBytesRead(URLRequestPeer* request) OVERRIDE { | 69 virtual void OnBytesRead(URLRequestPeer* request) OVERRIDE { |
| 70 int bytes_read = request->bytes_read(); | 70 int bytes_read = request->bytes_read(); |
| 71 if (bytes_read != 0) { | 71 if (bytes_read != 0) { |
| 72 JNIEnv* env = base::android::AttachCurrentThread(); | 72 JNIEnv* env = base::android::AttachCurrentThread(); |
| 73 jobject bytebuf = env->NewDirectByteBuffer(request->Data(), bytes_read); | 73 jobject java_buffer = |
| 74 cronet::Java_UrlRequest_onBytesRead(env, owner_, bytebuf); | 74 env->NewDirectByteBuffer(request->Data(), bytes_read); |
| 75 env->DeleteLocalRef(bytebuf); | 75 cronet::Java_UrlRequest_onBytesRead(env, owner_, java_buffer); |
| 76 env->DeleteLocalRef(java_buffer); | |
| 76 } | 77 } |
| 77 } | 78 } |
| 78 | 79 |
| 79 virtual void OnRequestFinished(URLRequestPeer* request) OVERRIDE { | 80 virtual void OnRequestFinished(URLRequestPeer* request) OVERRIDE { |
| 80 JNIEnv* env = base::android::AttachCurrentThread(); | 81 JNIEnv* env = base::android::AttachCurrentThread(); |
| 81 cronet::Java_UrlRequest_finish(env, owner_); | 82 cronet::Java_UrlRequest_finish(env, owner_); |
| 82 } | 83 } |
| 83 | 84 |
| 85 virtual int ReadFromUploadChannel(net::IOBuffer* buf, | |
| 86 int buf_length) OVERRIDE { | |
| 87 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 88 jobject jbuf = env->NewDirectByteBuffer( | |
|
mmenke
2014/08/05 21:08:02
You renamed the wrong one, though I agree with tha
mef
2014/08/05 21:38:45
Done.
| |
| 89 reinterpret_cast<void*>(buf->data()), buf_length); | |
| 90 jint bytes_read = | |
| 91 cronet::Java_UrlRequest_readFromUploadChannel(env, owner_, jbuf); | |
| 92 env->DeleteLocalRef(jbuf); | |
| 93 return bytes_read; | |
| 94 } | |
| 95 | |
| 84 protected: | 96 protected: |
| 85 virtual ~JniURLRequestPeerDelegate() { | 97 virtual ~JniURLRequestPeerDelegate() { |
| 86 JNIEnv* env = base::android::AttachCurrentThread(); | 98 JNIEnv* env = base::android::AttachCurrentThread(); |
| 87 env->DeleteGlobalRef(owner_); | 99 env->DeleteGlobalRef(owner_); |
| 88 } | 100 } |
| 89 | 101 |
| 90 private: | 102 private: |
| 91 jobject owner_; | 103 jobject owner_; |
| 92 | 104 |
| 93 DISALLOW_COPY_AND_ASSIGN(JniURLRequestPeerDelegate); | 105 DISALLOW_COPY_AND_ASSIGN(JniURLRequestPeerDelegate); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 size); | 181 size); |
| 170 env->ReleaseByteArrayElements(content, content_bytes, 0); | 182 env->ReleaseByteArrayElements(content, content_bytes, 0); |
| 171 } | 183 } |
| 172 } | 184 } |
| 173 } | 185 } |
| 174 | 186 |
| 175 static void SetUploadChannel(JNIEnv* env, | 187 static void SetUploadChannel(JNIEnv* env, |
| 176 jobject object, | 188 jobject object, |
| 177 jlong urlRequestPeer, | 189 jlong urlRequestPeer, |
| 178 jstring content_type, | 190 jstring content_type, |
| 179 jobject content, | |
| 180 jlong content_length) { | 191 jlong content_length) { |
| 181 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 192 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); |
| 182 SetPostContentType(env, request, content_type); | 193 SetPostContentType(env, request, content_type); |
| 183 | 194 |
| 184 request->SetUploadChannel(env, content, content_length); | 195 request->SetUploadChannel(env, content_length); |
| 185 } | 196 } |
| 186 | 197 |
| 187 | 198 |
| 188 /* synchronized */ | 199 /* synchronized */ |
| 189 static void Start(JNIEnv* env, jobject object, jlong urlRequestPeer) { | 200 static void Start(JNIEnv* env, jobject object, jlong urlRequestPeer) { |
| 190 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 201 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); |
| 191 if (request != NULL) { | 202 if (request != NULL) { |
| 192 request->Start(); | 203 request->Start(); |
| 193 } | 204 } |
| 194 } | 205 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 | 345 |
| 335 // Some implementations (notably HttpURLConnection) include a mapping for the | 346 // Some implementations (notably HttpURLConnection) include a mapping for the |
| 336 // null key; in HTTP's case, this maps to the HTTP status line. | 347 // null key; in HTTP's case, this maps to the HTTP status line. |
| 337 ScopedJavaLocalRef<jstring> status_line = | 348 ScopedJavaLocalRef<jstring> status_line = |
| 338 ConvertUTF8ToJavaString(env, headers->GetStatusLine()); | 349 ConvertUTF8ToJavaString(env, headers->GetStatusLine()); |
| 339 Java_UrlRequest_onAppendResponseHeader( | 350 Java_UrlRequest_onAppendResponseHeader( |
| 340 env, object, headersMap, NULL, status_line.Release()); | 351 env, object, headersMap, NULL, status_line.Release()); |
| 341 } | 352 } |
| 342 | 353 |
| 343 } // namespace cronet | 354 } // namespace cronet |
| OLD | NEW |