OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |