Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: components/cronet/android/org_chromium_net_UrlRequest.cc

Issue 442803002: Remove explicit JNI references by adding UrlRequest.readFromUploadChannel callback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove spurious space. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 base::android::ScopedJavaLocalRef<jobject> java_buffer(
74 cronet::Java_UrlRequest_onBytesRead(env, owner_, bytebuf); 74 env, env->NewDirectByteBuffer(request->Data(), bytes_read));
75 env->DeleteLocalRef(bytebuf); 75 cronet::Java_UrlRequest_onBytesRead(env, owner_, java_buffer.obj());
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 ReadFromUploadChannel(net::IOBuffer* buf,
85 int buf_length) OVERRIDE {
86 JNIEnv* env = base::android::AttachCurrentThread();
87 base::android::ScopedJavaLocalRef<jobject> java_buffer(
88 env, env->NewDirectByteBuffer(buf->data(), buf_length));
89 jint bytes_read = cronet::Java_UrlRequest_readFromUploadChannel(
90 env, owner_, java_buffer.obj());
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 size); 178 size);
169 env->ReleaseByteArrayElements(content, content_bytes, 0); 179 env->ReleaseByteArrayElements(content, content_bytes, 0);
170 } 180 }
171 } 181 }
172 } 182 }
173 183
174 static void SetUploadChannel(JNIEnv* env, 184 static void SetUploadChannel(JNIEnv* env,
175 jobject object, 185 jobject object,
176 jlong urlRequestPeer, 186 jlong urlRequestPeer,
177 jstring content_type, 187 jstring content_type,
178 jobject content,
179 jlong content_length) { 188 jlong content_length) {
180 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); 189 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer);
181 SetPostContentType(env, request, content_type); 190 SetPostContentType(env, request, content_type);
182 191
183 request->SetUploadChannel(env, content, content_length); 192 request->SetUploadChannel(env, content_length);
184 } 193 }
185 194
186 195
187 /* synchronized */ 196 /* synchronized */
188 static void Start(JNIEnv* env, jobject object, jlong urlRequestPeer) { 197 static void Start(JNIEnv* env, jobject object, jlong urlRequestPeer) {
189 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer); 198 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer);
190 if (request != NULL) { 199 if (request != NULL) {
191 request->Start(); 200 request->Start();
192 } 201 }
193 } 202 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « components/cronet/android/java/src/org/chromium/net/UrlRequest.java ('k') | components/cronet/android/url_request_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698