Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.util.Log; | 9 import android.util.Log; |
| 10 | 10 |
| 11 import java.io.File; | 11 import java.io.File; |
| 12 import java.io.IOException; | |
| 12 import java.lang.annotation.Retention; | 13 import java.lang.annotation.Retention; |
| 13 import java.lang.annotation.RetentionPolicy; | 14 import java.lang.annotation.RetentionPolicy; |
| 14 import java.lang.reflect.Constructor; | 15 import java.lang.reflect.Constructor; |
| 15 import java.net.IDN; | 16 import java.net.IDN; |
| 16 import java.net.Proxy; | 17 import java.net.Proxy; |
| 17 import java.net.URL; | 18 import java.net.URL; |
| 18 import java.net.URLConnection; | 19 import java.net.URLConnection; |
| 19 import java.net.URLStreamHandlerFactory; | 20 import java.net.URLStreamHandlerFactory; |
| 20 import java.util.Date; | 21 import java.util.Date; |
| 21 import java.util.HashSet; | 22 import java.util.HashSet; |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 * priorities see {@link #createRequest(String, UrlRequest.Callback, | 562 * priorities see {@link #createRequest(String, UrlRequest.Callback, |
| 562 * Executor, int priority)}. | 563 * Executor, int priority)}. |
| 563 * | 564 * |
| 564 * @param url {@link URL} for the request. | 565 * @param url {@link URL} for the request. |
| 565 * @param callback callback object that gets invoked on different events. | 566 * @param callback callback object that gets invoked on different events. |
| 566 * @param executor {@link Executor} on which all callbacks will be invoked. | 567 * @param executor {@link Executor} on which all callbacks will be invoked. |
| 567 * @return new request. | 568 * @return new request. |
| 568 * @deprecated Use {@link UrlRequest.Builder#build}. | 569 * @deprecated Use {@link UrlRequest.Builder#build}. |
| 569 */ | 570 */ |
| 570 @Deprecated | 571 @Deprecated |
| 571 public abstract UrlRequest createRequest( | 572 public final UrlRequest createRequest( |
| 572 String url, UrlRequest.Callback callback, Executor executor); | 573 String url, UrlRequest.Callback callback, Executor executor) { |
| 574 return createRequest(url, callback, executor, UrlRequest.Builder.REQUEST _PRIORITY_MEDIUM); | |
| 575 } | |
| 573 | 576 |
| 574 /** | 577 /** |
| 575 * Creates a {@link UrlRequest} object. All callbacks will | 578 * Creates a {@link UrlRequest} object. All callbacks will |
| 576 * be called on {@code executor}'s thread. {@code executor} must not run | 579 * be called on {@code executor}'s thread. {@code executor} must not run |
| 577 * tasks on the current thread to prevent blocking networking operations | 580 * tasks on the current thread to prevent blocking networking operations |
| 578 * and causing exceptions during shutdown. | 581 * and causing exceptions during shutdown. |
| 579 * | 582 * |
| 580 * @param url {@link URL} for the request. | 583 * @param url {@link URL} for the request. |
| 581 * @param callback callback object that gets invoked on different events. | 584 * @param callback callback object that gets invoked on different events. |
| 582 * @param executor {@link Executor} on which all callbacks will be invoked. | 585 * @param executor {@link Executor} on which all callbacks will be invoked. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 753 | 756 |
| 754 /** | 757 /** |
| 755 * Establishes a new connection to the resource specified by the {@link URL} {@code url}. | 758 * Establishes a new connection to the resource specified by the {@link URL} {@code url}. |
| 756 * <p> | 759 * <p> |
| 757 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain | 760 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain |
| 758 * limitations, see {@link #createURLStreamHandlerFactory} for details. | 761 * limitations, see {@link #createURLStreamHandlerFactory} for details. |
| 759 * | 762 * |
| 760 * @param url URL of resource to connect to. | 763 * @param url URL of resource to connect to. |
| 761 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine. | 764 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine. |
| 762 */ | 765 */ |
| 763 public abstract URLConnection openConnection(URL url); | 766 public abstract URLConnection openConnection(URL url) throws IOException; |
| 764 | 767 |
| 765 /** | 768 /** |
| 766 * Establishes a new connection to the resource specified by the {@link URL} {@code url} | 769 * Establishes a new connection to the resource specified by the {@link URL} {@code url} |
| 767 * using the given proxy. | 770 * using the given proxy. |
| 768 * <p> | 771 * <p> |
| 769 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain | 772 * <b>Note:</b> Cronet's {@link java.net.HttpURLConnection} implementation i s subject to certain |
| 770 * limitations, see {@link #createURLStreamHandlerFactory} for details. | 773 * limitations, see {@link #createURLStreamHandlerFactory} for details. |
| 771 * | 774 * |
| 772 * @param url URL of resource to connect to. | 775 * @param url URL of resource to connect to. |
| 773 * @param proxy proxy to use when establishing connection. | 776 * @param proxy proxy to use when establishing connection. |
| 774 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine. | 777 * @return an {@link java.net.HttpURLConnection} instance implemented by thi s CronetEngine. |
| 775 * @hide | 778 * @hide |
| 776 * @deprecated Marked as deprecated because @hide doesn't properly hide but | 779 * @deprecated Marked as deprecated because @hide doesn't properly hide but |
| 777 * javadocs are built with nodeprecated="yes". | 780 * javadocs are built with nodeprecated="yes". |
| 778 * TODO(pauljensen): Expose once implemented, http://crbug.com/41811 1 | 781 * TODO(pauljensen): Expose once implemented, http://crbug.com/41811 1 |
| 779 */ | 782 */ |
| 780 @SuppressWarnings("DepAnn") public abstract URLConnection openConnection(URL url, Proxy proxy); | 783 @SuppressWarnings("DepAnn") |
| 784 public abstract URLConnection openConnection(URL url, Proxy proxy) throws IO Exception; | |
| 781 | 785 |
| 782 /** | 786 /** |
| 783 * Creates a {@link URLStreamHandlerFactory} to handle HTTP and HTTPS | 787 * Creates a {@link URLStreamHandlerFactory} to handle HTTP and HTTPS |
| 784 * traffic. An instance of this class can be installed via | 788 * traffic. An instance of this class can be installed via |
| 785 * {@link URL#setURLStreamHandlerFactory} thus using this CronetEngine by de fault for | 789 * {@link URL#setURLStreamHandlerFactory} thus using this CronetEngine by de fault for |
| 786 * all requests created via {@link URL#openConnection}. | 790 * all requests created via {@link URL#openConnection}. |
| 787 * <p> | 791 * <p> |
| 788 * Cronet does not use certain HTTP features provided via the system: | 792 * Cronet does not use certain HTTP features provided via the system: |
| 789 * <ul> | 793 * <ul> |
| 790 * <li>the HTTP cache installed via | 794 * <li>the HTTP cache installed via |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 823 @Deprecated | 827 @Deprecated |
| 824 public static CronetEngine createContext(Builder builder) { | 828 public static CronetEngine createContext(Builder builder) { |
| 825 CronetEngine cronetEngine = null; | 829 CronetEngine cronetEngine = null; |
| 826 if (builder.getUserAgent() == null) { | 830 if (builder.getUserAgent() == null) { |
| 827 builder.setUserAgent(builder.getDefaultUserAgent()); | 831 builder.setUserAgent(builder.getDefaultUserAgent()); |
| 828 } | 832 } |
| 829 if (!builder.legacyMode()) { | 833 if (!builder.legacyMode()) { |
| 830 cronetEngine = createCronetEngine(builder); | 834 cronetEngine = createCronetEngine(builder); |
| 831 } | 835 } |
| 832 if (cronetEngine == null) { | 836 if (cronetEngine == null) { |
| 833 // TODO(mef): Fallback to stub implementation. Once stub | 837 cronetEngine = new JavaCronetEngine(builder.getUserAgent()); |
|
pauljensen
2015/12/29 16:35:53
I'm worried about this automatic silent fallback.
Charles
2016/01/05 21:53:56
The problem with that is that you now need a code
| |
| 834 // implementation is available merge with createCronetFactory. | |
| 835 cronetEngine = createCronetEngine(builder); | |
| 836 } | 838 } |
| 837 Log.i(TAG, "Using network stack: " + cronetEngine.getVersionString()); | 839 Log.i(TAG, "Using network stack: " + cronetEngine.getVersionString()); |
| 838 return cronetEngine; | 840 return cronetEngine; |
| 839 } | 841 } |
| 840 | 842 |
| 841 private static CronetEngine createCronetEngine(Builder builder) { | 843 private static CronetEngine createCronetEngine(Builder builder) { |
| 842 CronetEngine cronetEngine = null; | 844 CronetEngine cronetEngine = null; |
| 843 try { | 845 try { |
| 844 Class<? extends CronetEngine> engineClass = | 846 Class<? extends CronetEngine> engineClass = |
| 845 CronetEngine.class.getClassLoader() | 847 CronetEngine.class.getClassLoader() |
| 846 .loadClass(CRONET_URL_REQUEST_CONTEXT) | 848 .loadClass(CRONET_URL_REQUEST_CONTEXT) |
| 847 .asSubclass(CronetEngine.class); | 849 .asSubclass(CronetEngine.class); |
| 848 Constructor<? extends CronetEngine> constructor = | 850 Constructor<? extends CronetEngine> constructor = |
| 849 engineClass.getConstructor(Builder.class); | 851 engineClass.getConstructor(Builder.class); |
| 850 CronetEngine possibleEngine = constructor.newInstance(builder); | 852 CronetEngine possibleEngine = constructor.newInstance(builder); |
| 851 if (possibleEngine.isEnabled()) { | 853 if (possibleEngine.isEnabled()) { |
| 852 cronetEngine = possibleEngine; | 854 cronetEngine = possibleEngine; |
| 853 } | 855 } |
| 854 } catch (ClassNotFoundException e) { | 856 } catch (ClassNotFoundException e) { |
| 855 // Leave as null. | 857 // Leave as null. |
| 856 } catch (Exception e) { | 858 } catch (Exception e) { |
| 857 throw new IllegalStateException("Cannot instantiate: " + CRONET_URL_ REQUEST_CONTEXT, e); | 859 throw new IllegalStateException("Cannot instantiate: " + CRONET_URL_ REQUEST_CONTEXT, e); |
| 858 } | 860 } |
| 859 return cronetEngine; | 861 return cronetEngine; |
| 860 } | 862 } |
| 861 } | 863 } |
| OLD | NEW |