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

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/CronetUrlRequest.java

Issue 923213002: Use "@NativeClassQualifiedName" in CronetUrlRequest.java (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nativeclass
Patch Set: Corrected a typo Created 5 years, 8 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 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import android.util.Log; 7 import android.util.Log;
8 import android.util.Pair; 8 import android.util.Pair;
9 9
10 import org.chromium.base.CalledByNative; 10 import org.chromium.base.CalledByNative;
11 import org.chromium.base.JNINamespace; 11 import org.chromium.base.JNINamespace;
12 import org.chromium.base.NativeClassQualifiedName;
12 13
13 import java.nio.ByteBuffer; 14 import java.nio.ByteBuffer;
14 import java.util.ArrayList; 15 import java.util.ArrayList;
15 import java.util.Collections; 16 import java.util.Collections;
16 import java.util.List; 17 import java.util.List;
17 import java.util.Map; 18 import java.util.Map;
18 import java.util.TreeMap; 19 import java.util.TreeMap;
19 import java.util.concurrent.Executor; 20 import java.util.concurrent.Executor;
20 21
21 /** 22 /**
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 93 }
93 mListener.onDataReceived(CronetUrlRequest.this, 94 mListener.onDataReceived(CronetUrlRequest.this,
94 mResponseInfo, mByteBuffer); 95 mResponseInfo, mByteBuffer);
95 mByteBuffer = null; 96 mByteBuffer = null;
96 synchronized (mUrlRequestAdapterLock) { 97 synchronized (mUrlRequestAdapterLock) {
97 mInOnDataReceived = false; 98 mInOnDataReceived = false;
98 if (isCanceled()) { 99 if (isCanceled()) {
99 destroyRequestAdapter(); 100 destroyRequestAdapter();
100 return; 101 return;
101 } 102 }
102 nativeReceiveData(mUrlRequestAdapter); 103 nativeReadData(mUrlRequestAdapter);
103 } 104 }
104 } catch (Exception e) { 105 } catch (Exception e) {
105 synchronized (mUrlRequestAdapterLock) { 106 synchronized (mUrlRequestAdapterLock) {
106 mInOnDataReceived = false; 107 mInOnDataReceived = false;
107 if (isCanceled()) { 108 if (isCanceled()) {
108 destroyRequestAdapter(); 109 destroyRequestAdapter();
109 } 110 }
110 } 111 }
111 onListenerException(e); 112 onListenerException(e);
112 } 113 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 throw new IllegalArgumentException("Invalid http method " + mInitialMethod); 285 throw new IllegalArgumentException("Invalid http method " + mInitialMethod);
285 } 286 }
286 } 287 }
287 288
288 boolean hasContentType = false; 289 boolean hasContentType = false;
289 for (Pair<String, String> header : mRequestHeaders) { 290 for (Pair<String, String> header : mRequestHeaders) {
290 if (header.first.equalsIgnoreCase("Content-Type") 291 if (header.first.equalsIgnoreCase("Content-Type")
291 && !header.second.isEmpty()) { 292 && !header.second.isEmpty()) {
292 hasContentType = true; 293 hasContentType = true;
293 } 294 }
294 if (!nativeAddHeader(mUrlRequestAdapter, header.first, heade r.second)) { 295 if (!nativeAddRequestHeader(mUrlRequestAdapter, header.first , header.second)) {
295 destroyRequestAdapter(); 296 destroyRequestAdapter();
296 throw new IllegalArgumentException( 297 throw new IllegalArgumentException(
297 "Invalid header " + header.first + "=" + header. second); 298 "Invalid header " + header.first + "=" + header. second);
298 } 299 }
299 } 300 }
300 if (mUploadDataStream != null) { 301 if (mUploadDataStream != null) {
301 if (!hasContentType) { 302 if (!hasContentType) {
302 throw new IllegalArgumentException( 303 throw new IllegalArgumentException(
303 "Requests with upload data must have a Content-T ype."); 304 "Requests with upload data must have a Content-T ype.");
304 } 305 }
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 throw new IllegalStateException("Request is already started."); 417 throw new IllegalStateException("Request is already started.");
417 } 418 }
418 } 419 }
419 } 420 }
420 421
421 private void destroyRequestAdapter() { 422 private void destroyRequestAdapter() {
422 synchronized (mUrlRequestAdapterLock) { 423 synchronized (mUrlRequestAdapterLock) {
423 if (mUrlRequestAdapter == 0) { 424 if (mUrlRequestAdapter == 0) {
424 return; 425 return;
425 } 426 }
426 nativeDestroyRequestAdapter(mUrlRequestAdapter); 427 nativeDestroy(mUrlRequestAdapter);
427 mRequestContext.onRequestDestroyed(this); 428 mRequestContext.onRequestDestroyed(this);
428 mUrlRequestAdapter = 0; 429 mUrlRequestAdapter = 0;
429 } 430 }
430 } 431 }
431 432
432 /** 433 /**
433 * If listener method throws an exception, request gets canceled 434 * If listener method throws an exception, request gets canceled
434 * and exception is reported via onFailed listener callback. 435 * and exception is reported via onFailed listener callback.
435 * Only called on the Executor. 436 * Only called on the Executor.
436 */ 437 */
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 if (isCanceled()) { 534 if (isCanceled()) {
534 return; 535 return;
535 } 536 }
536 try { 537 try {
537 mListener.onResponseStarted(CronetUrlRequest.this, 538 mListener.onResponseStarted(CronetUrlRequest.this,
538 mResponseInfo); 539 mResponseInfo);
539 synchronized (mUrlRequestAdapterLock) { 540 synchronized (mUrlRequestAdapterLock) {
540 if (isCanceled()) { 541 if (isCanceled()) {
541 return; 542 return;
542 } 543 }
543 nativeReceiveData(mUrlRequestAdapter); 544 nativeReadData(mUrlRequestAdapter);
544 } 545 }
545 } catch (Exception e) { 546 } catch (Exception e) {
546 onListenerException(e); 547 onListenerException(e);
547 } 548 }
548 } 549 }
549 }; 550 };
550 postTaskToExecutor(task); 551 postTaskToExecutor(task);
551 } 552 }
552 553
553 /** 554 /**
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 private void onAppendResponseHeader(HeadersList headersList, 651 private void onAppendResponseHeader(HeadersList headersList,
651 String name, String value) { 652 String name, String value) {
652 headersList.add(Pair.create(name, value)); 653 headersList.add(Pair.create(name, value));
653 } 654 }
654 655
655 // Native methods are implemented in cronet_url_request.cc. 656 // Native methods are implemented in cronet_url_request.cc.
656 657
657 private native long nativeCreateRequestAdapter( 658 private native long nativeCreateRequestAdapter(
658 long urlRequestContextAdapter, String url, int priority); 659 long urlRequestContextAdapter, String url, int priority);
659 660
660 private native boolean nativeAddHeader(long urlRequestAdapter, String name, 661 @NativeClassQualifiedName("CronetURLRequestAdapter")
661 String value); 662 private native boolean nativeSetHttpMethod(long nativePtr, String method);
662 663
663 private native boolean nativeSetHttpMethod(long urlRequestAdapter, 664 @NativeClassQualifiedName("CronetURLRequestAdapter")
664 String method); 665 private native boolean nativeAddRequestHeader(long nativePtr, String name, S tring value);
665 666
666 private native void nativeStart(long urlRequestAdapter); 667 @NativeClassQualifiedName("CronetURLRequestAdapter")
668 private native void nativeDisableCache(long nativePtr);
667 669
668 private native void nativeDestroyRequestAdapter(long urlRequestAdapter); 670 @NativeClassQualifiedName("CronetURLRequestAdapter")
671 private native void nativeStart(long nativePtr);
669 672
670 private native void nativeFollowDeferredRedirect(long urlRequestAdapter); 673 @NativeClassQualifiedName("CronetURLRequestAdapter")
674 private native void nativeFollowDeferredRedirect(long nativePtr);
671 675
672 private native void nativeReceiveData(long urlRequestAdapter); 676 @NativeClassQualifiedName("CronetURLRequestAdapter")
677 private native void nativeReadData(long nativePtr);
673 678
674 private native void nativePopulateResponseHeaders(long urlRequestAdapter, 679 @NativeClassQualifiedName("CronetURLRequestAdapter")
675 HeadersList headers); 680 private native void nativeDestroy(long nativePtr);
676 681
677 private native String nativeGetNegotiatedProtocol(long urlRequestAdapter); 682 @NativeClassQualifiedName("CronetURLRequestAdapter")
683 private native void nativePopulateResponseHeaders(long nativePtr, HeadersLis t headers);
678 684
679 private native String nativeGetHttpStatusText(long urlRequestAdapter); 685 @NativeClassQualifiedName("CronetURLRequestAdapter")
686 private native String nativeGetHttpStatusText(long nativePtr);
680 687
681 private native boolean nativeGetWasCached(long urlRequestAdapter); 688 @NativeClassQualifiedName("CronetURLRequestAdapter")
689 private native String nativeGetNegotiatedProtocol(long nativePtr);
682 690
683 private native long nativeGetTotalReceivedBytes(long urlRequestAdapter); 691 @NativeClassQualifiedName("CronetURLRequestAdapter")
692 private native boolean nativeGetWasCached(long nativePtr);
684 693
685 private native void nativeDisableCache(long urlRequestAdapter); 694 @NativeClassQualifiedName("CronetURLRequestAdapter")
695 private native long nativeGetTotalReceivedBytes(long nativePtr);
686 } 696 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698