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..e7d399dc805573d3264dcc32bd1ada034d0c6337 |
| --- /dev/null |
| +++ b/components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java |
| @@ -0,0 +1,98 @@ |
| +// 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.Build; |
| +import android.os.Process; |
| +import android.util.Log; |
| + |
| +import org.chromium.base.CalledByNative; |
| +import org.chromium.base.JNINamespace; |
| + |
| +import java.util.concurrent.Executor; |
| + |
| +/** |
| + * UrlRequest context using Chromium HTTP stack implementation. |
| + */ |
| +@JNINamespace("cronet") |
| +public class CronetUrlRequestContext extends UrlRequestContext { |
| + 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; |
| + |
| + public CronetUrlRequestContext(Context context, |
| + UrlRequestContextConfig config) { |
| + mUrlRequestContextAdapter = nativeCreateRequestContextAdapter( |
| + context, getLoggingLevel(), config.toString()); |
| + 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); |
| + } |
| + |
| + @Override |
| + public boolean isEnabled() { |
| + return Build.VERSION.SDK_INT >= 14; |
| + } |
| + |
| + @Override |
| + public String getName() { |
| + return "Cronet/" + Version.getVersion(); |
| + } |
| + |
| + long getCronetUrlRequestContextAdapter() { |
|
xunjieli
2014/10/23 14:04:33
nit: is this method private or public?
mef
2014/10/24 03:31:45
Package as it needs to be accessed by CronetUrlReq
|
| + 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, |
| + int loggingLevel, String config); |
| + |
| + private native void nativeReleaseRequestContextAdapter( |
| + long urlRequestContextAdapter); |
|
mmenke
2014/10/23 16:26:01
This is never called.
Seems like we have two opti
mef
2014/10/24 03:31:45
Previous interface did it in finalize, but I guess
mmenke
2014/10/24 03:46:19
My suggestion is go with the exception, and if we
mef
2014/10/24 19:57:55
Sounds good. We can also set a 'shutdown' flag, so
|
| + |
| + private native void nativeInitializeStatistics(); |
| + |
| + private native String nativeGetStatisticsJSON(String filter); |
| + |
| + private native void nativeStartNetLogToFile( |
| + long urlRequestContextAdapter, String fileName); |
| + |
| + private native void nativeStopNetLog(long urlRequestContextAdapter); |
| +} |