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 |
44 // A hint that a host supports QUIC. | 59 // A hint that a host supports QUIC. |
45 static class QuicHint { | 60 static class QuicHint { |
46 // The host. | 61 // The host. |
47 final String mHost; | 62 final String mHost; |
48 // Port of the server that supports QUIC. | 63 // Port of the server that supports QUIC. |
49 final int mPort; | 64 final int mPort; |
50 // Alternate protocol port. | 65 // Alternate protocol port. |
51 final int mAlternatePort; | 66 final int mAlternatePort; |
52 | 67 |
53 QuicHint(String host, int port, int alternatePort) { | 68 QuicHint(String host, int port, int alternatePort) { |
(...skipping 25 matching lines...) Expand all Loading... |
79 private static final Pattern INVALID_PKP_HOST_NAME = Pattern.compile("^[
0-9\\.]*$"); | 94 private static final Pattern INVALID_PKP_HOST_NAME = Pattern.compile("^[
0-9\\.]*$"); |
80 | 95 |
81 // Private fields are simply storage of configuration for the resulting
CronetEngine. | 96 // Private fields are simply storage of configuration for the resulting
CronetEngine. |
82 // See setters below for verbose descriptions. | 97 // See setters below for verbose descriptions. |
83 private final Context mContext; | 98 private final Context mContext; |
84 private final List<QuicHint> mQuicHints = new LinkedList<QuicHint>(); | 99 private final List<QuicHint> mQuicHints = new LinkedList<QuicHint>(); |
85 private final List<Pkp> mPkps = new LinkedList<Pkp>(); | 100 private final List<Pkp> mPkps = new LinkedList<Pkp>(); |
86 private String mUserAgent; | 101 private String mUserAgent; |
87 private String mStoragePath; | 102 private String mStoragePath; |
88 private boolean mLegacyModeEnabled; | 103 private boolean mLegacyModeEnabled; |
| 104 private LibraryLoader mLibraryLoader; |
89 private String mLibraryName; | 105 private String mLibraryName; |
90 private boolean mQuicEnabled; | 106 private boolean mQuicEnabled; |
91 private boolean mHttp2Enabled; | 107 private boolean mHttp2Enabled; |
92 private boolean mSdchEnabled; | 108 private boolean mSdchEnabled; |
93 private String mDataReductionProxyKey; | 109 private String mDataReductionProxyKey; |
94 private String mDataReductionProxyPrimaryProxy; | 110 private String mDataReductionProxyPrimaryProxy; |
95 private String mDataReductionProxyFallbackProxy; | 111 private String mDataReductionProxyFallbackProxy; |
96 private String mDataReductionProxySecureProxyCheckUrl; | 112 private String mDataReductionProxySecureProxyCheckUrl; |
97 private boolean mDisableCache; | 113 private boolean mDisableCache; |
98 private int mHttpCacheMode; | 114 private int mHttpCacheMode; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 196 |
181 /** | 197 /** |
182 * Overrides the name of the native library backing Cronet. | 198 * Overrides the name of the native library backing Cronet. |
183 * @return the builder to facilitate chaining. | 199 * @return the builder to facilitate chaining. |
184 */ | 200 */ |
185 Builder setLibraryName(String libName) { | 201 Builder setLibraryName(String libName) { |
186 mLibraryName = libName; | 202 mLibraryName = libName; |
187 return this; | 203 return this; |
188 } | 204 } |
189 | 205 |
190 String libraryName() { | 206 /** |
191 return mLibraryName; | 207 * Sets a {@link LibraryLoader} to be used to load the native library. |
| 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 } |
192 } | 222 } |
193 | 223 |
194 /** | 224 /** |
195 * Sets whether <a href="https://www.chromium.org/quic">QUIC</a> protoco
l | 225 * Sets whether <a href="https://www.chromium.org/quic">QUIC</a> protoco
l |
196 * is enabled. Defaults to disabled. | 226 * is enabled. Defaults to disabled. |
197 * @return the builder to facilitate chaining. | 227 * @return the builder to facilitate chaining. |
198 */ | 228 */ |
199 public Builder enableQUIC(boolean value) { | 229 public Builder enableQUIC(boolean value) { |
200 mQuicEnabled = value; | 230 mQuicEnabled = value; |
201 return this; | 231 return this; |
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 * Interface to listen for finished requests that were created via this Cron
etEngine instance. | 1056 * Interface to listen for finished requests that were created via this Cron
etEngine instance. |
1027 * | 1057 * |
1028 * @deprecated not really deprecated but hidden for now as it's a prototype. | 1058 * @deprecated not really deprecated but hidden for now as it's a prototype. |
1029 */ | 1059 */ |
1030 @Deprecated | 1060 @Deprecated |
1031 public interface RequestFinishedListener { // TODO(klm): Add a convenience a
bstract class. | 1061 public interface RequestFinishedListener { // TODO(klm): Add a convenience a
bstract class. |
1032 /** Invoked with request info. */ | 1062 /** Invoked with request info. */ |
1033 void onRequestFinished(UrlRequestInfo requestInfo); | 1063 void onRequestFinished(UrlRequestInfo requestInfo); |
1034 } | 1064 } |
1035 } | 1065 } |
OLD | NEW |