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 |
| index 4c7afc6c0f2278fc2be06da86220681d7d2ee5ac..a852415374923e0febdbf70dacfe4433d6dfebde 100644 |
| --- a/components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java |
| +++ b/components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java |
| @@ -6,6 +6,8 @@ package org.chromium.net; |
| import android.content.Context; |
| import android.os.Build; |
| +import android.os.Handler; |
| +import android.os.Looper; |
| import android.os.Process; |
| import android.util.Log; |
| @@ -31,12 +33,24 @@ public class CronetUrlRequestContext extends UrlRequestContext { |
| public CronetUrlRequestContext(Context context, |
| UrlRequestContextConfig config) { |
| + CronetLibraryLoader.loadAndInitialize(context, config); |
|
xunjieli
2015/01/05 14:48:03
Maybe rename "loadAndInitialize" to sth like "init
mef
2015/01/05 16:59:21
Done. ensureInitialized seems to be commonly used
|
| nativeSetMinLogLevel(getLoggingLevel()); |
| mUrlRequestContextAdapter = nativeCreateRequestContextAdapter( |
| context, config.toString()); |
| if (mUrlRequestContextAdapter == 0) { |
| throw new NullPointerException("Context Adapter creation failed"); |
| } |
| + // Post a task to UI thread to init native Chromium URLRequestContext. |
| + // TODO(xunjieli): This constructor is not supposed to be invoked on |
| + // the main thread. Consider making the following code into a blocking |
| + // API to handle the case where we are already on main thread. |
| + Runnable task = new Runnable() { |
| + public void run() { |
| + nativeInitRequestContextOnMainThread( |
| + mUrlRequestContextAdapter); |
| + } |
| + }; |
| + new Handler(Looper.getMainLooper()).post(task); |
| } |
| @Override |
| @@ -146,4 +160,7 @@ public class CronetUrlRequestContext extends UrlRequestContext { |
| private native void nativeStopNetLog(long urlRequestContextAdapter); |
| private native int nativeSetMinLogLevel(int loggingLevel); |
| + |
| + private native void nativeInitRequestContextOnMainThread( |
| + long urlRequestContextAdapter); |
| } |