Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(547)

Unified Diff: components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java

Issue 726013002: [Cronet] Hook up library loader, system proxy and network change notifier to async api. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..5846ecebc29c64cd0627d3452d34cf601b263560 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,25 @@ public class CronetUrlRequestContext extends UrlRequestContext {
public CronetUrlRequestContext(Context context,
UrlRequestContextConfig config) {
+ CronetLibraryLoader.ensureInitialized(context, config);
nativeSetMinLogLevel(getLoggingLevel());
+ final String configString = config.toString();
mUrlRequestContextAdapter = nativeCreateRequestContextAdapter(
- context, config.toString());
+ context, configString);
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, configString);
mmenke 2015/01/08 19:06:16 This isn't threadsafe. shutdown can be called whi
mef 2015/01/08 21:17:03 Good point. This seems to be a problem with shutdo
+ }
+ };
+ new Handler(Looper.getMainLooper()).post(task);
}
@Override
@@ -146,4 +161,7 @@ public class CronetUrlRequestContext extends UrlRequestContext {
private native void nativeStopNetLog(long urlRequestContextAdapter);
private native int nativeSetMinLogLevel(int loggingLevel);
+
+ private native void nativeInitRequestContextOnMainThread(
+ long urlRequestContextAdapter, String config);
}

Powered by Google App Engine
This is Rietveld 408576698