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

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

Issue 1619673004: Add API for custom library loading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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;
(...skipping 23 matching lines...) Expand all
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 callback for loading the "cronet" library.
xunjieli 2016/01/21 19:50:53 Suggest making this into an abstract class, and mL
mgersh 2016/01/22 17:41:16 I made it into an interface instead, since it look
46 */
47 public static class LibraryLoader {
48 /**
49 * Load the native library.
50 */
51 public void loadLibrary(Context context, String name) {
xunjieli 2016/01/21 19:50:53 I don't think we need the context as an argument.
mgersh 2016/01/22 17:41:16 Done.
52 // The context isn't used here, but other implementations might need it
53 System.loadLibrary(name);
54 }
55 }
56
44 // A hint that a host supports QUIC. 57 // A hint that a host supports QUIC.
45 static class QuicHint { 58 static class QuicHint {
46 // The host. 59 // The host.
47 final String mHost; 60 final String mHost;
48 // Port of the server that supports QUIC. 61 // Port of the server that supports QUIC.
49 final int mPort; 62 final int mPort;
50 // Alternate protocol port. 63 // Alternate protocol port.
51 final int mAlternatePort; 64 final int mAlternatePort;
52 65
53 QuicHint(String host, int port, int alternatePort) { 66 QuicHint(String host, int port, int alternatePort) {
(...skipping 25 matching lines...) Expand all
79 private static final Pattern INVALID_PKP_HOST_NAME = Pattern.compile("^[ 0-9\\.]*$"); 92 private static final Pattern INVALID_PKP_HOST_NAME = Pattern.compile("^[ 0-9\\.]*$");
80 93
81 // Private fields are simply storage of configuration for the resulting CronetEngine. 94 // Private fields are simply storage of configuration for the resulting CronetEngine.
82 // See setters below for verbose descriptions. 95 // See setters below for verbose descriptions.
83 private final Context mContext; 96 private final Context mContext;
84 private final List<QuicHint> mQuicHints = new LinkedList<QuicHint>(); 97 private final List<QuicHint> mQuicHints = new LinkedList<QuicHint>();
85 private final List<Pkp> mPkps = new LinkedList<Pkp>(); 98 private final List<Pkp> mPkps = new LinkedList<Pkp>();
86 private String mUserAgent; 99 private String mUserAgent;
87 private String mStoragePath; 100 private String mStoragePath;
88 private boolean mLegacyModeEnabled; 101 private boolean mLegacyModeEnabled;
102 private LibraryLoader mLibraryLoader;
89 private String mLibraryName; 103 private String mLibraryName;
90 private boolean mQuicEnabled; 104 private boolean mQuicEnabled;
91 private boolean mHttp2Enabled; 105 private boolean mHttp2Enabled;
92 private boolean mSdchEnabled; 106 private boolean mSdchEnabled;
93 private String mDataReductionProxyKey; 107 private String mDataReductionProxyKey;
94 private String mDataReductionProxyPrimaryProxy; 108 private String mDataReductionProxyPrimaryProxy;
95 private String mDataReductionProxyFallbackProxy; 109 private String mDataReductionProxyFallbackProxy;
96 private String mDataReductionProxySecureProxyCheckUrl; 110 private String mDataReductionProxySecureProxyCheckUrl;
97 private boolean mDisableCache; 111 private boolean mDisableCache;
98 private int mHttpCacheMode; 112 private int mHttpCacheMode;
99 private long mHttpCacheMaxSize; 113 private long mHttpCacheMaxSize;
100 private String mExperimentalOptions; 114 private String mExperimentalOptions;
101 private long mMockCertVerifier; 115 private long mMockCertVerifier;
102 116
103 /** 117 /**
104 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache. 118 * Default config enables SPDY, disables QUIC, SDCH and HTTP cache.
105 * @param context Android {@link Context} for engine to use. 119 * @param context Android {@link Context} for engine to use.
106 */ 120 */
107 public Builder(Context context) { 121 public Builder(Context context) {
108 mContext = context; 122 mContext = context;
109 setLibraryName("cronet"); 123 setLibraryName("cronet");
124 setLibraryLoader(new LibraryLoader());
110 enableLegacyMode(false); 125 enableLegacyMode(false);
111 enableQUIC(false); 126 enableQUIC(false);
112 enableHTTP2(true); 127 enableHTTP2(true);
113 enableSDCH(false); 128 enableSDCH(false);
114 enableHttpCache(HTTP_CACHE_DISABLED, 0); 129 enableHttpCache(HTTP_CACHE_DISABLED, 0);
115 } 130 }
116 131
117 /** 132 /**
118 * Constructs a User-Agent string including Cronet version, and 133 * Constructs a User-Agent string including Cronet version, and
119 * application name and version. 134 * application name and version.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 195
181 /** 196 /**
182 * Overrides the name of the native library backing Cronet. 197 * Overrides the name of the native library backing Cronet.
183 * @return the builder to facilitate chaining. 198 * @return the builder to facilitate chaining.
184 */ 199 */
185 Builder setLibraryName(String libName) { 200 Builder setLibraryName(String libName) {
186 mLibraryName = libName; 201 mLibraryName = libName;
187 return this; 202 return this;
188 } 203 }
189 204
190 String libraryName() { 205 /**
191 return mLibraryName; 206 * Overrides the callback to load the native library.
207 * @return the builder to facilitate chaining.
208 */
209 public Builder setLibraryLoader(LibraryLoader loader) {
210 mLibraryLoader = loader;
211 return this;
212 }
213
214 void loadLibrary(Context context) {
215 mLibraryLoader.loadLibrary(context, mLibraryName);
xunjieli 2016/01/21 19:50:53 Suggest do the following: If mLibraryLoader is nul
mgersh 2016/01/22 17:41:16 Done.
192 } 216 }
193 217
194 /** 218 /**
195 * Sets whether <a href="https://www.chromium.org/quic">QUIC</a> protoco l 219 * Sets whether <a href="https://www.chromium.org/quic">QUIC</a> protoco l
196 * is enabled. Defaults to disabled. 220 * is enabled. Defaults to disabled.
197 * @return the builder to facilitate chaining. 221 * @return the builder to facilitate chaining.
198 */ 222 */
199 public Builder enableQUIC(boolean value) { 223 public Builder enableQUIC(boolean value) {
200 mQuicEnabled = value; 224 mQuicEnabled = value;
201 return this; 225 return this;
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 * Interface to listen for finished requests that were created via this Cron etEngine instance. 1050 * Interface to listen for finished requests that were created via this Cron etEngine instance.
1027 * 1051 *
1028 * @deprecated not really deprecated but hidden for now as it's a prototype. 1052 * @deprecated not really deprecated but hidden for now as it's a prototype.
1029 */ 1053 */
1030 @Deprecated 1054 @Deprecated
1031 public interface RequestFinishedListener { // TODO(klm): Add a convenience a bstract class. 1055 public interface RequestFinishedListener { // TODO(klm): Add a convenience a bstract class.
1032 /** Invoked with request info. */ 1056 /** Invoked with request info. */
1033 void onRequestFinished(UrlRequestInfo requestInfo); 1057 void onRequestFinished(UrlRequestInfo requestInfo);
1034 } 1058 }
1035 } 1059 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698