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

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

Issue 475533003: Upstream changes to enable chunked uploads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « no previous file | components/cronet/android/java/src/org/chromium/net/ChromiumUrlRequest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/chromium_url_request.h" 5 #include "components/cronet/android/chromium_url_request.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_adapter.h" 10 #include "components/cronet/android/url_request_adapter.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 55
56 // A delegate of URLRequestAdapter that delivers callbacks to the Java layer. 56 // A delegate of URLRequestAdapter that delivers callbacks to the Java layer.
57 class JniURLRequestAdapterDelegate 57 class JniURLRequestAdapterDelegate
58 : public URLRequestAdapter::URLRequestAdapterDelegate { 58 : public URLRequestAdapter::URLRequestAdapterDelegate {
59 public: 59 public:
60 JniURLRequestAdapterDelegate(JNIEnv* env, jobject owner) { 60 JniURLRequestAdapterDelegate(JNIEnv* env, jobject owner) {
61 owner_ = env->NewGlobalRef(owner); 61 owner_ = env->NewGlobalRef(owner);
62 } 62 }
63 63
64 virtual void OnAppendChunkCompleted(URLRequestAdapter* request) OVERRIDE {
65 JNIEnv* env = base::android::AttachCurrentThread();
66 cronet::Java_ChromiumUrlRequest_onAppendChunkCompleted(env, owner_);
67 }
68
64 virtual void OnResponseStarted(URLRequestAdapter* request) OVERRIDE { 69 virtual void OnResponseStarted(URLRequestAdapter* request) OVERRIDE {
65 JNIEnv* env = base::android::AttachCurrentThread(); 70 JNIEnv* env = base::android::AttachCurrentThread();
66 cronet::Java_ChromiumUrlRequest_onResponseStarted(env, owner_); 71 cronet::Java_ChromiumUrlRequest_onResponseStarted(env, owner_);
67 } 72 }
68 73
69 virtual void OnBytesRead(URLRequestAdapter* request) OVERRIDE { 74 virtual void OnBytesRead(URLRequestAdapter* request) OVERRIDE {
70 int bytes_read = request->bytes_read(); 75 int bytes_read = request->bytes_read();
71 if (bytes_read != 0) { 76 if (bytes_read != 0) {
72 JNIEnv* env = base::android::AttachCurrentThread(); 77 JNIEnv* env = base::android::AttachCurrentThread();
73 base::android::ScopedJavaLocalRef<jobject> java_buffer( 78 base::android::ScopedJavaLocalRef<jobject> java_buffer(
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 jlong urlRequestAdapter, 197 jlong urlRequestAdapter,
193 jstring content_type, 198 jstring content_type,
194 jlong content_length) { 199 jlong content_length) {
195 URLRequestAdapter* request = 200 URLRequestAdapter* request =
196 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 201 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter);
197 SetPostContentType(env, request, content_type); 202 SetPostContentType(env, request, content_type);
198 203
199 request->SetUploadChannel(env, content_length); 204 request->SetUploadChannel(env, content_length);
200 } 205 }
201 206
207 static void EnableChunkedUpload(JNIEnv* env,
208 jobject jcaller,
209 jlong urlRequestAdapter,
210 jstring content_type) {
211 URLRequestAdapter* request =
212 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter);
213 SetPostContentType(env, request, content_type);
214 request->EnableChunkedUpload();
215 }
216
217 static void AppendChunkToUpload(JNIEnv* env,
218 jobject jcaller,
219 jlong urlRequestAdapter,
220 jobject chunk_byte_buffer,
221 jint chunk_size,
222 jboolean is_last_chunk) {
223 URLRequestAdapter* request =
224 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter);
225 if (request != NULL && chunk_byte_buffer != NULL) {
226 void* chunk = env->GetDirectBufferAddress(chunk_byte_buffer);
227 request->AppendChunkToUpload(
228 reinterpret_cast<const char*>(chunk), chunk_size, is_last_chunk);
229 }
230 }
231
202 /* synchronized */ 232 /* synchronized */
203 static void Start(JNIEnv* env, jobject object, jlong urlRequestAdapter) { 233 static void Start(JNIEnv* env, jobject object, jlong urlRequestAdapter) {
204 URLRequestAdapter* request = 234 URLRequestAdapter* request =
205 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter); 235 reinterpret_cast<URLRequestAdapter*>(urlRequestAdapter);
206 if (request != NULL) { 236 if (request != NULL) {
207 request->Start(); 237 request->Start();
208 } 238 }
209 } 239 }
210 240
211 /* synchronized */ 241 /* synchronized */
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 391
362 // Some implementations (notably HttpURLConnection) include a mapping for the 392 // Some implementations (notably HttpURLConnection) include a mapping for the
363 // null key; in HTTP's case, this maps to the HTTP status line. 393 // null key; in HTTP's case, this maps to the HTTP status line.
364 ScopedJavaLocalRef<jstring> status_line = 394 ScopedJavaLocalRef<jstring> status_line =
365 ConvertUTF8ToJavaString(env, headers->GetStatusLine()); 395 ConvertUTF8ToJavaString(env, headers->GetStatusLine());
366 Java_ChromiumUrlRequest_onAppendResponseHeader( 396 Java_ChromiumUrlRequest_onAppendResponseHeader(
367 env, object, headersMap, NULL, status_line.Release()); 397 env, object, headersMap, NULL, status_line.Release());
368 } 398 }
369 399
370 } // namespace cronet 400 } // namespace cronet
OLDNEW
« no previous file with comments | « no previous file | components/cronet/android/java/src/org/chromium/net/ChromiumUrlRequest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698