| 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; | |
| 8 import android.util.Log; | 7 import android.util.Log; |
| 9 | 8 |
| 10 import java.lang.reflect.Constructor; | 9 import java.lang.reflect.Constructor; |
| 11 import java.nio.channels.WritableByteChannel; | 10 import java.nio.channels.WritableByteChannel; |
| 12 import java.util.Map; | 11 import java.util.Map; |
| 13 | 12 |
| 14 /** | 13 /** |
| 15 * A factory for {@link HttpUrlRequest}'s, which uses the best HTTP stack | 14 * A factory for {@link HttpUrlRequest}'s, which uses the best HTTP stack |
| 16 * available on the current platform. | 15 * available on the current platform. |
| 17 * @deprecated Use {@link UrlRequestContext} instead. | 16 * @deprecated Use {@link CronetEngine} instead. |
| 18 */ | 17 */ |
| 19 @Deprecated | 18 @Deprecated |
| 20 public abstract class HttpUrlRequestFactory { | 19 public abstract class HttpUrlRequestFactory { |
| 21 private static final String TAG = "HttpUrlRequestFactory"; | 20 private static final String TAG = "HttpUrlRequestFactory"; |
| 22 | 21 |
| 23 private static final String CHROMIUM_URL_REQUEST_FACTORY = | 22 private static final String CHROMIUM_URL_REQUEST_FACTORY = |
| 24 "org.chromium.net.ChromiumUrlRequestFactory"; | 23 "org.chromium.net.ChromiumUrlRequestFactory"; |
| 25 | 24 |
| 26 public static HttpUrlRequestFactory createFactory( | 25 public static HttpUrlRequestFactory createFactory(CronetEngine.Builder build
er) { |
| 27 Context context, UrlRequestContextConfig config) { | |
| 28 HttpUrlRequestFactory factory = null; | 26 HttpUrlRequestFactory factory = null; |
| 29 if (!config.legacyMode()) { | 27 if (!builder.legacyMode()) { |
| 30 factory = createChromiumFactory(context, config); | 28 factory = createChromiumFactory(builder); |
| 31 } | 29 } |
| 32 if (factory == null) { | 30 if (factory == null) { |
| 33 // Default to HttpUrlConnection-based networking. | 31 // Default to HttpUrlConnection-based networking. |
| 34 factory = new HttpUrlConnectionUrlRequestFactory(context, config); | 32 factory = new HttpUrlConnectionUrlRequestFactory(builder); |
| 35 } | 33 } |
| 36 Log.i(TAG, "Using network stack: " + factory.getName()); | 34 Log.i(TAG, "Using network stack: " + factory.getName()); |
| 37 return factory; | 35 return factory; |
| 38 } | 36 } |
| 39 | 37 |
| 40 /** | 38 /** |
| 41 * Returns true if the factory is enabled. | 39 * Returns true if the factory is enabled. |
| 42 */ | 40 */ |
| 43 public abstract boolean isEnabled(); | 41 public abstract boolean isEnabled(); |
| 44 | 42 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 72 * log. | 70 * log. |
| 73 */ | 71 */ |
| 74 public abstract void startNetLogToFile(String fileName, boolean logAll); | 72 public abstract void startNetLogToFile(String fileName, boolean logAll); |
| 75 | 73 |
| 76 /** | 74 /** |
| 77 * Stops NetLog logging and flushes file to disk. If a logging session is | 75 * Stops NetLog logging and flushes file to disk. If a logging session is |
| 78 * not in progress this call is ignored. | 76 * not in progress this call is ignored. |
| 79 */ | 77 */ |
| 80 public abstract void stopNetLog(); | 78 public abstract void stopNetLog(); |
| 81 | 79 |
| 82 private static HttpUrlRequestFactory createChromiumFactory( | 80 private static HttpUrlRequestFactory createChromiumFactory(CronetEngine.Buil
der builder) { |
| 83 Context context, UrlRequestContextConfig config) { | |
| 84 HttpUrlRequestFactory factory = null; | 81 HttpUrlRequestFactory factory = null; |
| 85 try { | 82 try { |
| 86 Class<? extends HttpUrlRequestFactory> factoryClass = | 83 Class<? extends HttpUrlRequestFactory> factoryClass = |
| 87 HttpUrlRequestFactory.class.getClassLoader() | 84 HttpUrlRequestFactory.class.getClassLoader() |
| 88 .loadClass(CHROMIUM_URL_REQUEST_FACTORY) | 85 .loadClass(CHROMIUM_URL_REQUEST_FACTORY) |
| 89 .asSubclass(HttpUrlRequestFactory.class); | 86 .asSubclass(HttpUrlRequestFactory.class); |
| 90 Constructor<? extends HttpUrlRequestFactory> constructor = | 87 Constructor<? extends HttpUrlRequestFactory> constructor = |
| 91 factoryClass.getConstructor( | 88 factoryClass.getConstructor(CronetEngine.Builder.class); |
| 92 Context.class, UrlRequestContextConfig.class); | 89 HttpUrlRequestFactory chromiumFactory = constructor.newInstance(buil
der); |
| 93 HttpUrlRequestFactory chromiumFactory = | |
| 94 constructor.newInstance(context, config); | |
| 95 if (chromiumFactory.isEnabled()) { | 90 if (chromiumFactory.isEnabled()) { |
| 96 factory = chromiumFactory; | 91 factory = chromiumFactory; |
| 97 } | 92 } |
| 98 } catch (ClassNotFoundException e) { | 93 } catch (ClassNotFoundException e) { |
| 99 // Leave as null | 94 // Leave as null |
| 100 } catch (Exception e) { | 95 } catch (Exception e) { |
| 101 throw new IllegalStateException( | 96 throw new IllegalStateException( |
| 102 "Cannot instantiate: " + CHROMIUM_URL_REQUEST_FACTORY, | 97 "Cannot instantiate: " + CHROMIUM_URL_REQUEST_FACTORY, |
| 103 e); | 98 e); |
| 104 } | 99 } |
| 105 return factory; | 100 return factory; |
| 106 } | 101 } |
| 107 } | 102 } |
| OLD | NEW |