This source file includes following definitions.
- getFactory
- newRequest
- newRequest
- isEnabled
- getName
- createRequest
- createRequest
package org.chromium.net;
import android.content.Context;
import android.util.Log;
import java.lang.reflect.Constructor;
import java.nio.channels.WritableByteChannel;
import java.util.Map;
public abstract class HttpUrlRequestFactory {
private static final Object sLock = new Object();
private static final String TAG = "HttpUrlRequestFactory";
private static final String CHROMIUM_URL_REQUEST_FACTORY =
"org.chromium.net.ChromiumUrlRequestFactory";
private static HttpUrlRequestFactory sFactory;
private static HttpUrlRequestFactory getFactory(
Context context) {
synchronized (sLock) {
if (sFactory == null) {
try {
Class<? extends HttpUrlRequestFactory> factoryClass =
HttpUrlRequestFactory.class.getClassLoader().
loadClass(CHROMIUM_URL_REQUEST_FACTORY).
asSubclass(HttpUrlRequestFactory.class);
Constructor<? extends HttpUrlRequestFactory> constructor =
factoryClass.getConstructor(Context.class);
HttpUrlRequestFactory chromiumFactory =
constructor.newInstance(context);
if (chromiumFactory.isEnabled()) {
sFactory = chromiumFactory;
}
} catch (ClassNotFoundException e) {
} catch (Exception e) {
throw new IllegalStateException(
"Cannot instantiate: " +
CHROMIUM_URL_REQUEST_FACTORY,
e);
}
if (sFactory == null) {
sFactory = new HttpUrlConnectionUrlRequestFactory(context);
}
Log.i(TAG, "Using network stack: " + sFactory.getName());
}
return sFactory;
}
}
public static HttpUrlRequest newRequest(Context context, String url,
int requestPriority, Map<String, String> headers,
HttpUrlRequestListener listener) {
return getFactory(context).createRequest(url, requestPriority, headers,
listener);
}
public static HttpUrlRequest newRequest(Context context, String url,
int requestPriority, Map<String, String> headers,
WritableByteChannel channel, HttpUrlRequestListener listener) {
return getFactory(context).createRequest(url, requestPriority, headers,
channel, listener);
}
protected abstract boolean isEnabled();
protected abstract String getName();
protected abstract HttpUrlRequest createRequest(String url,
int requestPriority, Map<String, String> headers,
HttpUrlRequestListener listener);
protected abstract HttpUrlRequest createRequest(String url,
int requestPriority, Map<String, String> headers,
WritableByteChannel channel, HttpUrlRequestListener listener);
}