| 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.support.annotation.Nullable; | 9 import android.support.annotation.Nullable; |
| 10 import android.util.Log; | 10 import android.util.Log; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 * An engine to process {@link UrlRequest}s, which uses the best HTTP stack | 34 * An engine to process {@link UrlRequest}s, which uses the best HTTP stack |
| 35 * available on the current platform. | 35 * available on the current platform. |
| 36 */ | 36 */ |
| 37 public abstract class CronetEngine { | 37 public abstract class CronetEngine { |
| 38 /** | 38 /** |
| 39 * A builder for {@link CronetEngine}s, which allows runtime configuration o
f | 39 * A builder for {@link CronetEngine}s, which allows runtime configuration o
f |
| 40 * {@code CronetEngine}. Configuration options are set on the builder and | 40 * {@code CronetEngine}. Configuration options are set on the builder and |
| 41 * then {@link #build} is called to create the {@code CronetEngine}. | 41 * then {@link #build} is called to create the {@code CronetEngine}. |
| 42 */ | 42 */ |
| 43 public static class Builder { | 43 public static class Builder { |
| 44 /** | |
| 45 * A class which provides a method for loading the cronet native library
. Apps needing to | |
| 46 * implement custom library loading logic can inherit from this class an
d pass an instance | |
| 47 * to {@link CronetEngine.Builder#setLibraryLoader}. For example, this m
ight be required | |
| 48 * to work around {@code UnsatisfiedLinkError}s caused by flaky installa
tion on certain | |
| 49 * older devices. | |
| 50 */ | |
| 51 public abstract static class LibraryLoader { | |
| 52 /** | |
| 53 * Loads the native library. | |
| 54 * @param libName name of the library to load | |
| 55 */ | |
| 56 public abstract void loadLibrary(String libName); | |
| 57 } | |
| 58 | |
| 59 // A hint that a host supports QUIC. | 44 // A hint that a host supports QUIC. |
| 60 static class QuicHint { | 45 static class QuicHint { |
| 61 // The host. | 46 // The host. |
| 62 final String mHost; | 47 final String mHost; |
| 63 // Port of the server that supports QUIC. | 48 // Port of the server that supports QUIC. |
| 64 final int mPort; | 49 final int mPort; |
| 65 // Alternate protocol port. | 50 // Alternate protocol port. |
| 66 final int mAlternatePort; | 51 final int mAlternatePort; |
| 67 | 52 |
| 68 QuicHint(String host, int port, int alternatePort) { | 53 QuicHint(String host, int port, int alternatePort) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 94 private static final Pattern INVALID_PKP_HOST_NAME = Pattern.compile("^[
0-9\\.]*$"); | 79 private static final Pattern INVALID_PKP_HOST_NAME = Pattern.compile("^[
0-9\\.]*$"); |
| 95 | 80 |
| 96 // Private fields are simply storage of configuration for the resulting
CronetEngine. | 81 // Private fields are simply storage of configuration for the resulting
CronetEngine. |
| 97 // See setters below for verbose descriptions. | 82 // See setters below for verbose descriptions. |
| 98 private final Context mContext; | 83 private final Context mContext; |
| 99 private final List<QuicHint> mQuicHints = new LinkedList<QuicHint>(); | 84 private final List<QuicHint> mQuicHints = new LinkedList<QuicHint>(); |
| 100 private final List<Pkp> mPkps = new LinkedList<Pkp>(); | 85 private final List<Pkp> mPkps = new LinkedList<Pkp>(); |
| 101 private String mUserAgent; | 86 private String mUserAgent; |
| 102 private String mStoragePath; | 87 private String mStoragePath; |
| 103 private boolean mLegacyModeEnabled; | 88 private boolean mLegacyModeEnabled; |
| 104 private LibraryLoader mLibraryLoader; | |
| 105 private String mLibraryName; | 89 private String mLibraryName; |
| 106 private boolean mQuicEnabled; | 90 private boolean mQuicEnabled; |
| 107 private boolean mHttp2Enabled; | 91 private boolean mHttp2Enabled; |
| 108 private boolean mSdchEnabled; | 92 private boolean mSdchEnabled; |
| 109 private String mDataReductionProxyKey; | 93 private String mDataReductionProxyKey; |
| 110 private String mDataReductionProxyPrimaryProxy; | 94 private String mDataReductionProxyPrimaryProxy; |
| 111 private String mDataReductionProxyFallbackProxy; | 95 private String mDataReductionProxyFallbackProxy; |
| 112 private String mDataReductionProxySecureProxyCheckUrl; | 96 private String mDataReductionProxySecureProxyCheckUrl; |
| 113 private boolean mDisableCache; | 97 private boolean mDisableCache; |
| 114 private int mHttpCacheMode; | 98 private int mHttpCacheMode; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 180 |
| 197 /** | 181 /** |
| 198 * Overrides the name of the native library backing Cronet. | 182 * Overrides the name of the native library backing Cronet. |
| 199 * @return the builder to facilitate chaining. | 183 * @return the builder to facilitate chaining. |
| 200 */ | 184 */ |
| 201 Builder setLibraryName(String libName) { | 185 Builder setLibraryName(String libName) { |
| 202 mLibraryName = libName; | 186 mLibraryName = libName; |
| 203 return this; | 187 return this; |
| 204 } | 188 } |
| 205 | 189 |
| 206 /** | 190 String libraryName() { |
| 207 * Sets a {@link LibraryLoader} to be used to load the native library. | 191 return mLibraryName; |
| 208 * If not set, the library will be loaded using {@link System#loadLibrar
y}. | |
| 209 * @return the builder to facilitate chaining. | |
| 210 */ | |
| 211 public Builder setLibraryLoader(LibraryLoader loader) { | |
| 212 mLibraryLoader = loader; | |
| 213 return this; | |
| 214 } | |
| 215 | |
| 216 void loadLibrary() { | |
| 217 if (mLibraryLoader == null) { | |
| 218 System.loadLibrary(mLibraryName); | |
| 219 } else { | |
| 220 mLibraryLoader.loadLibrary(mLibraryName); | |
| 221 } | |
| 222 } | 192 } |
| 223 | 193 |
| 224 /** | 194 /** |
| 225 * Sets whether <a href="https://www.chromium.org/quic">QUIC</a> protoco
l | 195 * Sets whether <a href="https://www.chromium.org/quic">QUIC</a> protoco
l |
| 226 * is enabled. Defaults to disabled. | 196 * is enabled. Defaults to disabled. |
| 227 * @return the builder to facilitate chaining. | 197 * @return the builder to facilitate chaining. |
| 228 */ | 198 */ |
| 229 public Builder enableQUIC(boolean value) { | 199 public Builder enableQUIC(boolean value) { |
| 230 mQuicEnabled = value; | 200 mQuicEnabled = value; |
| 231 return this; | 201 return this; |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1056 * 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. |
| 1057 * | 1027 * |
| 1058 * @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. |
| 1059 */ | 1029 */ |
| 1060 @Deprecated | 1030 @Deprecated |
| 1061 public interface RequestFinishedListener { // TODO(klm): Add a convenience a
bstract class. | 1031 public interface RequestFinishedListener { // TODO(klm): Add a convenience a
bstract class. |
| 1062 /** Invoked with request info. */ | 1032 /** Invoked with request info. */ |
| 1063 void onRequestFinished(UrlRequestInfo requestInfo); | 1033 void onRequestFinished(UrlRequestInfo requestInfo); |
| 1064 } | 1034 } |
| 1065 } | 1035 } |
| OLD | NEW |