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

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

Issue 1363723002: [Cronet] Create Builders, rename UrlRequestContext to CronetEngine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Ben's tests Created 5 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.util.Log; 8 import android.util.Log;
9 9
10 import java.lang.reflect.Constructor; 10 import java.lang.reflect.Constructor;
11 import java.nio.channels.WritableByteChannel; 11 import java.nio.channels.WritableByteChannel;
12 import java.util.Map; 12 import java.util.Map;
13 13
14 /** 14 /**
15 * A factory for {@link HttpUrlRequest}'s, which uses the best HTTP stack 15 * A factory for {@link HttpUrlRequest}'s, which uses the best HTTP stack
16 * available on the current platform. 16 * available on the current platform.
17 * @deprecated Use {@link UrlRequestContext} instead. 17 * @deprecated Use {@link CronetEngine} instead.
18 */ 18 */
19 @Deprecated 19 @Deprecated
20 public abstract class HttpUrlRequestFactory { 20 public abstract class HttpUrlRequestFactory {
21 private static final String TAG = "HttpUrlRequestFactory"; 21 private static final String TAG = "HttpUrlRequestFactory";
22 22
23 private static final String CHROMIUM_URL_REQUEST_FACTORY = 23 private static final String CHROMIUM_URL_REQUEST_FACTORY =
24 "org.chromium.net.ChromiumUrlRequestFactory"; 24 "org.chromium.net.ChromiumUrlRequestFactory";
25 25
26 public static HttpUrlRequestFactory createFactory( 26 public static HttpUrlRequestFactory createFactory(
27 Context context, UrlRequestContextConfig config) { 27 Context context, CronetEngine.Builder config) {
28 HttpUrlRequestFactory factory = null; 28 HttpUrlRequestFactory factory = null;
29 if (!config.legacyMode()) { 29 if (!config.legacyMode()) {
30 factory = createChromiumFactory(context, config); 30 factory = createChromiumFactory(context, config);
31 } 31 }
32 if (factory == null) { 32 if (factory == null) {
33 // Default to HttpUrlConnection-based networking. 33 // Default to HttpUrlConnection-based networking.
34 factory = new HttpUrlConnectionUrlRequestFactory(context, config); 34 factory = new HttpUrlConnectionUrlRequestFactory(context, config);
35 } 35 }
36 Log.i(TAG, "Using network stack: " + factory.getName()); 36 Log.i(TAG, "Using network stack: " + factory.getName());
37 return factory; 37 return factory;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 */ 73 */
74 public abstract void startNetLogToFile(String fileName, boolean logAll); 74 public abstract void startNetLogToFile(String fileName, boolean logAll);
75 75
76 /** 76 /**
77 * Stops NetLog logging and flushes file to disk. If a logging session is 77 * Stops NetLog logging and flushes file to disk. If a logging session is
78 * not in progress this call is ignored. 78 * not in progress this call is ignored.
79 */ 79 */
80 public abstract void stopNetLog(); 80 public abstract void stopNetLog();
81 81
82 private static HttpUrlRequestFactory createChromiumFactory( 82 private static HttpUrlRequestFactory createChromiumFactory(
83 Context context, UrlRequestContextConfig config) { 83 Context context, CronetEngine.Builder config) {
84 HttpUrlRequestFactory factory = null; 84 HttpUrlRequestFactory factory = null;
85 try { 85 try {
86 Class<? extends HttpUrlRequestFactory> factoryClass = 86 Class<? extends HttpUrlRequestFactory> factoryClass =
87 HttpUrlRequestFactory.class.getClassLoader() 87 HttpUrlRequestFactory.class.getClassLoader()
88 .loadClass(CHROMIUM_URL_REQUEST_FACTORY) 88 .loadClass(CHROMIUM_URL_REQUEST_FACTORY)
89 .asSubclass(HttpUrlRequestFactory.class); 89 .asSubclass(HttpUrlRequestFactory.class);
90 Constructor<? extends HttpUrlRequestFactory> constructor = 90 Constructor<? extends HttpUrlRequestFactory> constructor =
91 factoryClass.getConstructor( 91 factoryClass.getConstructor(Context.class, CronetEngine.Buil der.class);
92 Context.class, UrlRequestContextConfig.class);
93 HttpUrlRequestFactory chromiumFactory = 92 HttpUrlRequestFactory chromiumFactory =
94 constructor.newInstance(context, config); 93 constructor.newInstance(context, config);
95 if (chromiumFactory.isEnabled()) { 94 if (chromiumFactory.isEnabled()) {
96 factory = chromiumFactory; 95 factory = chromiumFactory;
97 } 96 }
98 } catch (ClassNotFoundException e) { 97 } catch (ClassNotFoundException e) {
99 // Leave as null 98 // Leave as null
100 } catch (Exception e) { 99 } catch (Exception e) {
101 throw new IllegalStateException( 100 throw new IllegalStateException(
102 "Cannot instantiate: " + CHROMIUM_URL_REQUEST_FACTORY, 101 "Cannot instantiate: " + CHROMIUM_URL_REQUEST_FACTORY,
103 e); 102 e);
104 } 103 }
105 return factory; 104 return factory;
106 } 105 }
107 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698