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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 cronet::Java_UrlRequest_onBytesRead(env, owner_, bytebuf); | 74 cronet::Java_UrlRequest_onBytesRead(env, owner_, bytebuf); |
| 75 env->DeleteLocalRef(bytebuf); | 75 env->DeleteLocalRef(bytebuf); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 virtual void OnRequestFinished(URLRequestPeer* request) OVERRIDE { | 79 virtual void OnRequestFinished(URLRequestPeer* request) OVERRIDE { |
| 80 JNIEnv* env = base::android::AttachCurrentThread(); | 80 JNIEnv* env = base::android::AttachCurrentThread(); |
| 81 cronet::Java_UrlRequest_finish(env, owner_); | 81 cronet::Java_UrlRequest_finish(env, owner_); |
| 82 } | 82 } |
| 83 | 83 |
| 84 virtual int OnReadUploadData(net::IOBuffer* buf, int buf_length) { | |
|
mmenke
2014/08/05 19:32:41
OVERRIDE
mef
2014/08/05 20:44:28
Done.
| |
| 85 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 86 jobject jbuf = env->NewDirectByteBuffer( | |
|
mmenke
2014/08/05 19:32:41
jbuf seems to violate the C++ style guide - I'd su
mef
2014/08/05 20:44:28
Done.
| |
| 87 reinterpret_cast<void*>(buf->data()), buf_length); | |
| 88 jint bytes_read = | |
| 89 cronet::Java_UrlRequest_onReadUploadChannel(env, owner_, jbuf); | |
| 90 env->DeleteLocalRef(jbuf); | |
|
mmenke
2014/08/05 19:32:41
Is this call actually needed? Seems like it's not
mef
2014/08/05 20:44:28
IIUIC this is explicit refcounting, so we have to
mmenke
2014/08/05 21:08:02
Hrm...I missed that ,ost use ScopedJavaLocalRef, w
mef
2014/08/05 21:38:45
Done.
| |
| 91 return bytes_read; | |
| 92 } | |
| 93 | |
| 84 protected: | 94 protected: |
| 85 virtual ~JniURLRequestPeerDelegate() { | 95 virtual ~JniURLRequestPeerDelegate() { |
| 86 JNIEnv* env = base::android::AttachCurrentThread(); | 96 JNIEnv* env = base::android::AttachCurrentThread(); |
| 87 env->DeleteGlobalRef(owner_); | 97 env->DeleteGlobalRef(owner_); |
| 88 } | 98 } |
| 89 | 99 |
| 90 private: | 100 private: |
| 91 jobject owner_; | 101 jobject owner_; |
| 92 | 102 |
| 93 DISALLOW_COPY_AND_ASSIGN(JniURLRequestPeerDelegate); | 103 DISALLOW_COPY_AND_ASSIGN(JniURLRequestPeerDelegate); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 size); | 179 size); |
| 170 env->ReleaseByteArrayElements(content, content_bytes, 0); | 180 env->ReleaseByteArrayElements(content, content_bytes, 0); |
| 171 } | 181 } |
| 172 } | 182 } |
| 173 } | 183 } |
| 174 | 184 |
| 175 static void SetUploadChannel(JNIEnv* env, | 185 static void SetUploadChannel(JNIEnv* env, |
| 176 jobject object, | 186 jobject object, |
| 177 jlong urlRequestPeer, | 187 jlong urlRequestPeer, |
| 178 jstring content_type, | 188 jstring content_type, |
| 179 jobject content, | |
| 180 jlong content_length) { | 189 jlong content_length) { |
| 181 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 190 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); |
| 182 SetPostContentType(env, request, content_type); | 191 SetPostContentType(env, request, content_type); |
| 183 | 192 |
| 184 request->SetUploadChannel(env, content, content_length); | 193 request->SetUploadChannel(env, content_length); |
| 185 } | 194 } |
| 186 | 195 |
| 187 | 196 |
| 188 /* synchronized */ | 197 /* synchronized */ |
| 189 static void Start(JNIEnv* env, jobject object, jlong urlRequestPeer) { | 198 static void Start(JNIEnv* env, jobject object, jlong urlRequestPeer) { |
| 190 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); | 199 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); |
| 191 if (request != NULL) { | 200 if (request != NULL) { |
| 192 request->Start(); | 201 request->Start(); |
| 193 } | 202 } |
| 194 } | 203 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 | 343 |
| 335 // Some implementations (notably HttpURLConnection) include a mapping for the | 344 // Some implementations (notably HttpURLConnection) include a mapping for the |
| 336 // null key; in HTTP's case, this maps to the HTTP status line. | 345 // null key; in HTTP's case, this maps to the HTTP status line. |
| 337 ScopedJavaLocalRef<jstring> status_line = | 346 ScopedJavaLocalRef<jstring> status_line = |
| 338 ConvertUTF8ToJavaString(env, headers->GetStatusLine()); | 347 ConvertUTF8ToJavaString(env, headers->GetStatusLine()); |
| 339 Java_UrlRequest_onAppendResponseHeader( | 348 Java_UrlRequest_onAppendResponseHeader( |
| 340 env, object, headersMap, NULL, status_line.Release()); | 349 env, object, headersMap, NULL, status_line.Release()); |
| 341 } | 350 } |
| 342 | 351 |
| 343 } // namespace cronet | 352 } // namespace cronet |
| OLD | NEW |