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

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

Issue 2626523003: Cronet: a framework for providing alternative Cronet implementations (Closed)
Patch Set: Updated api.txt Created 3 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.net.http.HttpResponseCache; 8 import android.net.http.HttpResponseCache;
9 9
10 import java.io.IOException; 10 import java.io.IOException;
11 import java.net.URL; 11 import java.net.URL;
12 import java.net.URLConnection; 12 import java.net.URLConnection;
13 import java.net.URLStreamHandlerFactory; 13 import java.net.URLStreamHandlerFactory;
14 import java.util.Date; 14 import java.util.Date;
15 import java.util.List;
15 import java.util.Set; 16 import java.util.Set;
16 import java.util.concurrent.Executor; 17 import java.util.concurrent.Executor;
17 18
18 import javax.net.ssl.HttpsURLConnection; 19 import javax.net.ssl.HttpsURLConnection;
19 /** 20 /**
20 * An engine to process {@link UrlRequest}s, which uses the best HTTP stack 21 * An engine to process {@link UrlRequest}s, which uses the best HTTP stack
21 * available on the current platform. An instance of this class can be created 22 * available on the current platform. An instance of this class can be created
22 * using {@link Builder}. 23 * using {@link Builder}.
23 */ 24 */
24 public abstract class CronetEngine { 25 public abstract class CronetEngine {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 * {@link CronetEngine}. The default configuration enables HTTP/2 and 57 * {@link CronetEngine}. The default configuration enables HTTP/2 and
57 * disables QUIC, SDCH and the HTTP cache. 58 * disables QUIC, SDCH and the HTTP cache.
58 * 59 *
59 * @param context Android {@link Context}, which is used by 60 * @param context Android {@link Context}, which is used by
60 * {@link Builder} to retrieve the application 61 * {@link Builder} to retrieve the application
61 * context. A reference to only the application 62 * context. A reference to only the application
62 * context will be kept, so as to avoid extending 63 * context will be kept, so as to avoid extending
63 * the lifetime of {@code context} unnecessarily. 64 * the lifetime of {@code context} unnecessarily.
64 */ 65 */
65 public Builder(Context context) { 66 public Builder(Context context) {
66 mBuilderDelegate = ImplLoader.load(context); 67 CronetProviders providers = CronetProviders.instance();
68
69 // Check that there is at least one available provider.
70 List<CronetProvider> providerList = providers.getAvailableProviders( context);
71 if (providerList.size() == 0) {
72 throw new RuntimeException("Unable to find any Cronet provider."
73 + " Have you included all necessary jars?");
74 }
pauljensen 2017/01/18 17:03:04 nit: how about we get rid of this if statement, th
kapishnikov 2017/01/19 01:25:24 I added more error messages in a new PS ad some ex
75
76 // Try to load implementation using available providers. Assuming th at
77 // providers in the beginning of the list have higher priority.
78 ICronetEngineBuilder builderDelegate = null;
79 for (CronetProvider provider : providerList) {
80 Builder builder = provider.createBuilder();
81 if (builder != null) {
82 builderDelegate = builder.mBuilderDelegate;
83 break;
84 }
85 }
86
87 if (builderDelegate == null) {
88 throw new RuntimeException("Unable to load any Cronet implementa tion."
89 + " The list of available providers: " + providerList);
mef 2017/01/18 20:57:54 CronetProvider probably needs a meaningful toStrin
kapishnikov 2017/01/19 01:25:24 Good point. It will give the name of the class but
90 }
91
92 mBuilderDelegate = builderDelegate;
pauljensen 2017/01/18 17:03:04 nit: perhaps change the body of this function to t
kapishnikov 2017/01/19 01:25:24 Good idea. Done.
67 } 93 }
68 94
69 /** 95 /**
96 * Constructs {@link Builder} with a given delegate that provides the ac tual implementation
97 * of the {@code Builder} methods. This constructor is used only by the internal
98 * implementation.
99 *
100 * @param builderDelegate delegate that provides the actual implementati on.
101 *
102 * {@hide}
103 */
104 public Builder(ICronetEngineBuilder builderDelegate) {
105 mBuilderDelegate = builderDelegate;
106 }
107
108 /**
70 * Constructs a User-Agent string including application name and version , 109 * Constructs a User-Agent string including application name and version ,
71 * system build version, model and id, and Cronet version. 110 * system build version, model and id, and Cronet version.
72 * 111 *
73 * @return User-Agent string. 112 * @return User-Agent string.
74 */ 113 */
75 public String getDefaultUserAgent() { 114 public String getDefaultUserAgent() {
76 return mBuilderDelegate.getDefaultUserAgent(); 115 return mBuilderDelegate.getDefaultUserAgent();
77 } 116 }
78 117
79 /** 118 /**
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 * thread calling {@link Executor#execute} to prevent blocking networking 438 * thread calling {@link Executor#execute} to prevent blocking networking
400 * operations and causing exceptions during shutdown. 439 * operations and causing exceptions during shutdown.
401 * 440 *
402 * @param url URL for the generated requests. 441 * @param url URL for the generated requests.
403 * @param callback callback object that gets invoked on different events. 442 * @param callback callback object that gets invoked on different events.
404 * @param executor {@link Executor} on which all callbacks will be invoked. 443 * @param executor {@link Executor} on which all callbacks will be invoked.
405 */ 444 */
406 public abstract UrlRequest.Builder newUrlRequestBuilder( 445 public abstract UrlRequest.Builder newUrlRequestBuilder(
407 String url, UrlRequest.Callback callback, Executor executor); 446 String url, UrlRequest.Callback callback, Executor executor);
408 } 447 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698