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

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

Issue 1492583002: Add HttpUrlConnection backed implementation of CronetEngine. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix accidental println Created 4 years, 11 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.content.Context; 7 import android.content.Context;
8 import android.support.annotation.IntDef; 8 import android.support.annotation.IntDef;
9 import android.support.annotation.Nullable; 9 import android.support.annotation.Nullable;
10 import android.util.Log; 10 import android.util.Log;
11 11
12 import java.io.File; 12 import java.io.File;
13 import java.io.IOException;
13 import java.lang.annotation.Retention; 14 import java.lang.annotation.Retention;
14 import java.lang.annotation.RetentionPolicy; 15 import java.lang.annotation.RetentionPolicy;
15 import java.lang.reflect.Constructor; 16 import java.lang.reflect.Constructor;
16 import java.net.IDN; 17 import java.net.IDN;
17 import java.net.Proxy; 18 import java.net.Proxy;
18 import java.net.URL; 19 import java.net.URL;
19 import java.net.URLConnection; 20 import java.net.URLConnection;
20 import java.net.URLStreamHandlerFactory; 21 import java.net.URLStreamHandlerFactory;
21 import java.util.Collection; 22 import java.util.Collection;
23 import java.util.Collections;
22 import java.util.Date; 24 import java.util.Date;
23 import java.util.HashSet; 25 import java.util.HashSet;
24 import java.util.LinkedList; 26 import java.util.LinkedList;
25 import java.util.List; 27 import java.util.List;
26 import java.util.Map; 28 import java.util.Map;
27 import java.util.Set; 29 import java.util.Set;
28 import java.util.concurrent.Executor; 30 import java.util.concurrent.Executor;
29 import java.util.regex.Pattern; 31 import java.util.regex.Pattern;
30 32
31 /** 33 /**
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 * priorities see {@link #createRequest(String, UrlRequest.Callback, 566 * priorities see {@link #createRequest(String, UrlRequest.Callback,
565 * Executor, int priority)}. 567 * Executor, int priority)}.
566 * 568 *
567 * @param url {@link URL} for the request. 569 * @param url {@link URL} for the request.
568 * @param callback callback object that gets invoked on different events. 570 * @param callback callback object that gets invoked on different events.
569 * @param executor {@link Executor} on which all callbacks will be invoked. 571 * @param executor {@link Executor} on which all callbacks will be invoked.
570 * @return new request. 572 * @return new request.
571 * @deprecated Use {@link UrlRequest.Builder#build}. 573 * @deprecated Use {@link UrlRequest.Builder#build}.
572 */ 574 */
573 @Deprecated 575 @Deprecated
574 public abstract UrlRequest createRequest( 576 public final UrlRequest createRequest(
575 String url, UrlRequest.Callback callback, Executor executor); 577 String url, UrlRequest.Callback callback, Executor executor) {
578 return createRequest(url, callback, executor, UrlRequest.Builder.REQUEST _PRIORITY_MEDIUM);
579 }
576 580
577 /** 581 /**
578 * Creates a {@link UrlRequest} object. All callbacks will 582 * Creates a {@link UrlRequest} object. All callbacks will
579 * be called on {@code executor}'s thread. {@code executor} must not run 583 * be called on {@code executor}'s thread. {@code executor} must not run
580 * tasks on the current thread to prevent blocking networking operations 584 * tasks on the current thread to prevent blocking networking operations
581 * and causing exceptions during shutdown. 585 * and causing exceptions during shutdown.
582 * 586 *
583 * @param url {@link URL} for the request. 587 * @param url {@link URL} for the request.
584 * @param callback callback object that gets invoked on different events. 588 * @param callback callback object that gets invoked on different events.
585 * @param executor {@link Executor} on which all callbacks will be invoked. 589 * @param executor {@link Executor} on which all callbacks will be invoked.
586 * @param priority priority of the request which should be one of the 590 * @param priority priority of the request which should be one of the
587 * {@link UrlRequest.Builder#REQUEST_PRIORITY_IDLE REQUEST_PRIORITY_ *} 591 * {@link UrlRequest.Builder#REQUEST_PRIORITY_IDLE REQUEST_PRIORITY_ *}
588 * values. 592 * values.
589 * @return new request. 593 * @return new request.
590 * @deprecated Use {@link UrlRequest.Builder#build}. 594 * @deprecated Use {@link UrlRequest.Builder#build}.
591 */ 595 */
592 @Deprecated 596 @Deprecated
593 public abstract UrlRequest createRequest(String url, UrlRequest.Callback cal lback, 597 public final UrlRequest createRequest(String url, UrlRequest.Callback callba ck,
594 Executor executor, @UrlRequest.Builder.RequestPriority int priority) ; 598 Executor executor, @UrlRequest.Builder.RequestPriority int priority) {
599 return createRequest(url, callback, executor, priority, Collections.empt yList());
600 }
595 601
596 /** 602 /**
597 * Creates a {@link UrlRequest} object. All callbacks will 603 * Creates a {@link UrlRequest} object. All callbacks will
598 * be called on {@code executor}'s thread. {@code executor} must not run 604 * be called on {@code executor}'s thread. {@code executor} must not run
599 * tasks on the current thread to prevent blocking networking operations 605 * tasks on the current thread to prevent blocking networking operations
600 * and causing exceptions during shutdown. 606 * and causing exceptions during shutdown.
601 * 607 *
602 * @param url {@link URL} for the request. 608 * @param url {@link URL} for the request.
603 * @param callback callback object that gets invoked on different events. 609 * @param callback callback object that gets invoked on different events.
604 * @param executor {@link Executor} on which all callbacks will be invoked. 610 * @param executor {@link Executor} on which all callbacks will be invoked.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 780
775 /** 781 /**
776 * Establishes a new connection to the resource specified by the {@link URL} {@code url}. 782 * Establishes a new connection to the resource specified by the {@link URL} {@code url}.
777 * <p> 783 * <p>
778 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain 784 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain
779 * limitations, see {@link #createURLStreamHandlerFactory} for details. 785 * limitations, see {@link #createURLStreamHandlerFactory} for details.
780 * 786 *
781 * @param url URL of resource to connect to. 787 * @param url URL of resource to connect to.
782 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine. 788 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine.
783 */ 789 */
784 public abstract URLConnection openConnection(URL url); 790 public abstract URLConnection openConnection(URL url) throws IOException;
785 791
786 /** 792 /**
787 * Establishes a new connection to the resource specified by the {@link URL} {@code url} 793 * Establishes a new connection to the resource specified by the {@link URL} {@code url}
788 * using the given proxy. 794 * using the given proxy.
789 * <p> 795 * <p>
790 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain 796 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain
791 * limitations, see {@link #createURLStreamHandlerFactory} for details. 797 * limitations, see {@link #createURLStreamHandlerFactory} for details.
792 * 798 *
793 * @param url URL of resource to connect to. 799 * @param url URL of resource to connect to.
794 * @param proxy proxy to use when establishing connection. 800 * @param proxy proxy to use when establishing connection.
795 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine. 801 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine.
796 * @hide 802 * @hide
797 * @deprecated Marked as deprecated because @hide doesn't properly hide but 803 * @deprecated Marked as deprecated because @hide doesn't properly hide but
798 * javadocs are built with nodeprecated="yes". 804 * javadocs are built with nodeprecated="yes".
799 * TODO(pauljensen): Expose once implemented, http://crbug.com/41811 1 805 * TODO(pauljensen): Expose once implemented, http://crbug.com/41811 1
800 */ 806 */
801 @Deprecated 807 @Deprecated
802 @SuppressWarnings("DepAnn") 808 @SuppressWarnings("DepAnn")
803 public abstract URLConnection openConnection(URL url, Proxy proxy); 809 public abstract URLConnection openConnection(URL url, Proxy proxy) throws IO Exception;
804 810
805 /** 811 /**
806 * Creates a {@link URLStreamHandlerFactory} to handle HTTP and HTTPS 812 * Creates a {@link URLStreamHandlerFactory} to handle HTTP and HTTPS
807 * traffic. An instance of this class can be installed via 813 * traffic. An instance of this class can be installed via
808 * {@link URL#setURLStreamHandlerFactory} thus using this CronetEngine by de fault for 814 * {@link URL#setURLStreamHandlerFactory} thus using this CronetEngine by de fault for
809 * all requests created via {@link URL#openConnection}. 815 * all requests created via {@link URL#openConnection}.
810 * <p> 816 * <p>
811 * Cronet does not use certain HTTP features provided via the system: 817 * Cronet does not use certain HTTP features provided via the system:
812 * <ul> 818 * <ul>
813 * <li>the HTTP cache installed via 819 * <li>the HTTP cache installed via
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 @Deprecated 852 @Deprecated
847 public static CronetEngine createContext(Builder builder) { 853 public static CronetEngine createContext(Builder builder) {
848 CronetEngine cronetEngine = null; 854 CronetEngine cronetEngine = null;
849 if (builder.getUserAgent() == null) { 855 if (builder.getUserAgent() == null) {
850 builder.setUserAgent(builder.getDefaultUserAgent()); 856 builder.setUserAgent(builder.getDefaultUserAgent());
851 } 857 }
852 if (!builder.legacyMode()) { 858 if (!builder.legacyMode()) {
853 cronetEngine = createCronetEngine(builder); 859 cronetEngine = createCronetEngine(builder);
854 } 860 }
855 if (cronetEngine == null) { 861 if (cronetEngine == null) {
856 // TODO(mef): Fallback to stub implementation. Once stub 862 cronetEngine = new JavaCronetEngine(builder.getUserAgent());
857 // implementation is available merge with createCronetFactory.
858 cronetEngine = createCronetEngine(builder);
859 } 863 }
860 Log.i(TAG, "Using network stack: " + cronetEngine.getVersionString()); 864 Log.i(TAG, "Using network stack: " + cronetEngine.getVersionString());
861 return cronetEngine; 865 return cronetEngine;
862 } 866 }
863 867
864 private static CronetEngine createCronetEngine(Builder builder) { 868 private static CronetEngine createCronetEngine(Builder builder) {
865 CronetEngine cronetEngine = null; 869 CronetEngine cronetEngine = null;
866 try { 870 try {
867 Class<? extends CronetEngine> engineClass = 871 Class<? extends CronetEngine> engineClass =
868 CronetEngine.class.getClassLoader() 872 CronetEngine.class.getClassLoader()
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 * Interface to listen for finished requests that were created via this Cron etEngine instance. 1026 * Interface to listen for finished requests that were created via this Cron etEngine instance.
1023 * 1027 *
1024 * @deprecated not really deprecated but hidden for now as it's a prototype. 1028 * @deprecated not really deprecated but hidden for now as it's a prototype.
1025 */ 1029 */
1026 @Deprecated 1030 @Deprecated
1027 public interface RequestFinishedListener { // TODO(klm): Add a convenience a bstract class. 1031 public interface RequestFinishedListener { // TODO(klm): Add a convenience a bstract class.
1028 /** Invoked with request info. */ 1032 /** Invoked with request info. */
1029 void onRequestFinished(UrlRequestInfo requestInfo); 1033 void onRequestFinished(UrlRequestInfo requestInfo);
1030 } 1034 }
1031 } 1035 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698