| 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 builder) { |
| 28 HttpUrlRequestFactory factory = null; | 28 HttpUrlRequestFactory factory = null; |
| 29 if (!config.legacyMode()) { | 29 if (!builder.legacyMode()) { |
| 30 factory = createChromiumFactory(context, config); | 30 factory = createChromiumFactory(context, builder); |
| 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, builder); |
| 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; |
| 38 } | 38 } |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * Returns true if the factory is enabled. | 41 * Returns true if the factory is enabled. |
| 42 */ | 42 */ |
| 43 public abstract boolean isEnabled(); | 43 public abstract boolean isEnabled(); |
| 44 | 44 |
| (...skipping 28 matching lines...) Expand all 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 builder) { |
| 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); | 92 HttpUrlRequestFactory chromiumFactory = constructor.newInstance(cont
ext, builder); |
| 93 HttpUrlRequestFactory chromiumFactory = | |
| 94 constructor.newInstance(context, config); | |
| 95 if (chromiumFactory.isEnabled()) { | 93 if (chromiumFactory.isEnabled()) { |
| 96 factory = chromiumFactory; | 94 factory = chromiumFactory; |
| 97 } | 95 } |
| 98 } catch (ClassNotFoundException e) { | 96 } catch (ClassNotFoundException e) { |
| 99 // Leave as null | 97 // Leave as null |
| 100 } catch (Exception e) { | 98 } catch (Exception e) { |
| 101 throw new IllegalStateException( | 99 throw new IllegalStateException( |
| 102 "Cannot instantiate: " + CHROMIUM_URL_REQUEST_FACTORY, | 100 "Cannot instantiate: " + CHROMIUM_URL_REQUEST_FACTORY, |
| 103 e); | 101 e); |
| 104 } | 102 } |
| 105 return factory; | 103 return factory; |
| 106 } | 104 } |
| 107 } | 105 } |
| OLD | NEW |