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

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

Issue 367763004: WIP: Some cronet modifications for the AndroidGSA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Second attempt on UploadChannel Created 6 years, 5 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
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"
11 #include "components/cronet/android/url_request_peer.h" 11 #include "components/cronet/android/url_request_peer.h"
12 #include "jni/UrlRequest_jni.h" 12 #include "jni/UrlRequest_jni.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "net/base/request_priority.h" 14 #include "net/base/request_priority.h"
15 15
16 using base::android::ConvertUTF8ToJavaString; 16 using base::android::ConvertUTF8ToJavaString;
17 using base::android::CheckException;
17 18
18 namespace cronet { 19 namespace cronet {
19 namespace { 20 namespace {
20 21
21 net::RequestPriority ConvertRequestPriority(jint request_priority) { 22 net::RequestPriority ConvertRequestPriority(jint request_priority) {
22 switch (request_priority) { 23 switch (request_priority) {
23 case REQUEST_PRIORITY_IDLE: 24 case REQUEST_PRIORITY_IDLE:
24 return net::IDLE; 25 return net::IDLE;
25 case REQUEST_PRIORITY_LOWEST: 26 case REQUEST_PRIORITY_LOWEST:
26 return net::LOWEST; 27 return net::LOWEST;
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 311
311 std::string name_string = base::android::ConvertJavaStringToUTF8(env, name); 312 std::string name_string = base::android::ConvertJavaStringToUTF8(env, name);
312 std::string value = request->GetHeader(name_string); 313 std::string value = request->GetHeader(name_string);
313 if (!value.empty()) { 314 if (!value.empty()) {
314 return ConvertUTF8ToJavaString(env, value.c_str()).Release(); 315 return ConvertUTF8ToJavaString(env, value.c_str()).Release();
315 } else { 316 } else {
316 return NULL; 317 return NULL;
317 } 318 }
318 } 319 }
319 320
321 static jobjectArray GetAllHeaders(JNIEnv* env,
322 jobject object,
323 jlong urlRequestPeer) {
324 URLRequestPeer* request = reinterpret_cast<URLRequestPeer*>(urlRequestPeer);
325 net::HttpRequestHeaders headers;
326 if (request == NULL || !request->GetFullRequestHeaders(&headers)) {
327 return NULL;
328 }
329
330 // TODO(miloslav): Better to just expose the size instead.
331 net::HttpRequestHeaders::Iterator counter(headers);
332 int count = 0;
333 while (counter.GetNext()) {
334 ++count;
335 }
336
337 jclass string_class = env->FindClass("java/lang/String");
338 jobjectArray result = env->NewObjectArray(2 * count, string_class, NULL);
339 CheckException(env);
340
341 net::HttpRequestHeaders::Iterator iterator(headers);
342 int index = 0;
343 while (iterator.GetNext()) {
344 DCHECK(index <= 2 * count - 2);
345 ScopedJavaLocalRef<jstring> name =
346 ConvertUTF8ToJavaString(env, iterator.name());
347 env->SetObjectArrayElement(result, index++, name.obj());
348
349 ScopedJavaLocalRef<jstring> value =
350 ConvertUTF8ToJavaString(env, iterator.value());
351 env->SetObjectArrayElement(result, index++, value.obj());
352 }
353 DCHECK(index == 2 * count);
354 return result;
355 }
320 } // namespace cronet 356 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698