Chromium Code Reviews| Index: components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java |
| diff --git a/components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java b/components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0fa69b619e84a90f8776ad7c82d02cf5e3d21d70 |
| --- /dev/null |
| +++ b/components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.net; |
| + |
| +import android.content.Context; |
| +import android.os.Process; |
| +import android.util.Log; |
| + |
| +import org.chromium.base.CalledByNative; |
| +import org.chromium.base.JNINamespace; |
| + |
| +import java.util.concurrent.Executor; |
| + |
| +/** |
| + * UrlRequest factory using Chromium HTTP stack implementation. |
| + */ |
| +@JNINamespace("cronet") |
| +public class CronetUrlRequestContext implements UrlRequestFactory { |
| + private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG. |
| + private static final int LOG_DEBUG = -1; // LOG(FATAL...INFO), VLOG(1) |
| + private static final int LOG_VERBOSE = -2; // LOG(FATAL...INFO), VLOG(2) |
| + static final String LOG_TAG = "ChromiumNetwork"; |
| + |
| + private long mUrlRequestContextAdapter = 0; |
| + private Thread mNetworkThread; |
| + |
| + /** |
| + * Constructor. |
| + * |
| + */ |
| + public CronetUrlRequestContext(Context context, String userAgent, String config) { |
|
Charles
2014/09/23 22:33:13
silly 80 char limit violation
mef
2014/09/24 18:56:26
Done.
|
| + mUrlRequestContextAdapter = nativeCreateRequestContextAdapter( |
| + context, userAgent, getLoggingLevel(), config); |
| + if (mUrlRequestContextAdapter == 0) |
| + throw new NullPointerException("Context Adapter creation failed"); |
| + } |
| + |
| + @Override |
| + public UrlRequest createRequest(String url, UrlRequestListener listener, |
| + Executor executor) { |
| + return new CronetUrlRequest(this, url, |
| + UrlRequest.REQUEST_PRIORITY_MEDIUM, listener, executor); |
| + } |
| + |
| + long getCronetUrlRequestContextAdapter() { |
| + return mUrlRequestContextAdapter; |
| + } |
| + |
| + /** |
| + * @return loggingLevel see {@link #LOG_NONE}, {@link #LOG_DEBUG} and |
| + * {@link #LOG_VERBOSE}. |
| + */ |
| + private int getLoggingLevel() { |
| + int loggingLevel; |
| + if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { |
| + loggingLevel = LOG_VERBOSE; |
| + } else if (Log.isLoggable(LOG_TAG, Log.DEBUG)) { |
| + loggingLevel = LOG_DEBUG; |
| + } else { |
| + loggingLevel = LOG_NONE; |
| + } |
| + return loggingLevel; |
| + } |
| + |
| + @CalledByNative |
| + private void initNetworkThread() { |
| + mNetworkThread = Thread.currentThread(); |
| + Thread.currentThread().setName("ChromiumNet"); |
| + Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| + } |
| + |
| + // Native methods are implemented in cronet_url_request_context.cc. |
| + private native long nativeCreateRequestContextAdapter(Context context, |
| + String userAgent, int loggingLevel, String config); |
| + |
| + private native void nativeReleaseRequestContextAdapter( |
| + long urlRequestContextAdapter); |
| + |
| + private native void nativeInitializeStatistics(); |
| + |
| + private native String nativeGetStatisticsJSON(String filter); |
| + |
| + private native void nativeStartNetLogToFile( |
| + long urlRequestContextAdapter, String fileName); |
| + |
| + private native void nativeStopNetLog(long urlRequestContextAdapter); |
| +} |