summaryrefslogtreecommitdiffstats
path: root/net/android
diff options
context:
space:
mode:
authorellyjones@chromium.org <ellyjones@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-22 21:18:25 +0000
committerellyjones@chromium.org <ellyjones@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-22 21:18:25 +0000
commit2f880aa477985ccadb8f3151ed7ddefad06113f1 (patch)
tree5806b971f848d80edb1ae3c3ad7399c01e2f495a /net/android
parent96a45d875ae0cb3a26c2260c711e651f363985b9 (diff)
downloadchromium_src-2f880aa477985ccadb8f3151ed7ddefad06113f1.zip
chromium_src-2f880aa477985ccadb8f3151ed7ddefad06113f1.tar.gz
chromium_src-2f880aa477985ccadb8f3151ed7ddefad06113f1.tar.bz2
android: Use new proxy from PROXY_CHANGE intent
When we get a PROXY_CHANGE intent, the intent comes with the new proxy value; use this value instead of ignoring it and asking the system property store for the new proxy. This fixes a race condition where the system property store may not have the new proxy by the time we receive the intent. BUG=none yet TEST=trybot Review URL: https://codereview.chromium.org/26763005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230208 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/android')
-rw-r--r--net/android/java/src/org/chromium/net/ProxyChangeListener.java63
1 files changed, 60 insertions, 3 deletions
diff --git a/net/android/java/src/org/chromium/net/ProxyChangeListener.java b/net/android/java/src/org/chromium/net/ProxyChangeListener.java
index 9c59bcc..ce9aabb 100644
--- a/net/android/java/src/org/chromium/net/ProxyChangeListener.java
+++ b/net/android/java/src/org/chromium/net/ProxyChangeListener.java
@@ -10,6 +10,9 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.net.Proxy;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.base.NativeClassQualifiedName;
@@ -26,6 +29,15 @@ public class ProxyChangeListener {
private ProxyReceiver mProxyReceiver;
private Delegate mDelegate;
+ private static class ProxyConfig {
+ public ProxyConfig(String host, int port) {
+ mHost = host;
+ mPort = port;
+ }
+ public final String mHost;
+ public final int mPort;
+ };
+
public interface Delegate {
public void proxySettingsChanged();
}
@@ -69,12 +81,49 @@ public class ProxyChangeListener {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Proxy.PROXY_CHANGE_ACTION)) {
- proxySettingsChanged();
+ proxySettingsChanged(extractNewProxy(intent));
+ }
+ }
+
+ // Extract a ProxyConfig object from the supplied Intent's extra data
+ // bundle. The android.net.ProxyProperties class is not exported from
+ // tne Android SDK, so we have to use reflection to get at it and invoke
+ // methods on it. If we fail, return an empty proxy config (meaning
+ // 'direct').
+ // TODO(ellyjones): once android.net.ProxyProperties is exported,
+ // rewrite this.
+ private ProxyConfig extractNewProxy(Intent intent) {
+ try {
+ final String CLASS_NAME = "android.net.ProxyProperties";
+ final String GET_HOST_NAME = "getHost";
+ final String GET_PORT_NAME = "getPort";
+ Object props = intent.getExtras().get("proxy");
+ if (props == null) {
+ return null;
+ }
+ Class cls = Class.forName(CLASS_NAME);
+ Method getHostMethod = cls.getDeclaredMethod(GET_HOST_NAME);
+ Method getPortMethod = cls.getDeclaredMethod(GET_PORT_NAME);
+
+ String host = (String)getHostMethod.invoke(props);
+ int port = (Integer)getPortMethod.invoke(props);
+
+ return new ProxyConfig(host, port);
+ } catch (ClassNotFoundException ex) {
+ return null;
+ } catch (NoSuchMethodException ex) {
+ return null;
+ } catch (IllegalAccessException ex) {
+ return null;
+ } catch (InvocationTargetException ex) {
+ return null;
+ } catch (NullPointerException ex) {
+ return null;
}
}
}
- private void proxySettingsChanged() {
+ private void proxySettingsChanged(ProxyConfig cfg) {
if (!sEnabled) {
return;
}
@@ -86,7 +135,11 @@ public class ProxyChangeListener {
}
// Note that this code currently runs on a MESSAGE_LOOP_UI thread, but
// the C++ code must run the callbacks on the network thread.
- nativeProxySettingsChanged(mNativePtr);
+ if (cfg != null) {
+ nativeProxySettingsChangedTo(mNativePtr, cfg.mHost, cfg.mPort);
+ } else {
+ nativeProxySettingsChanged(mNativePtr);
+ }
}
private void registerReceiver() {
@@ -111,5 +164,9 @@ public class ProxyChangeListener {
* See net/proxy/proxy_config_service_android.cc
*/
@NativeClassQualifiedName("ProxyConfigServiceAndroid::JNIDelegate")
+ private native void nativeProxySettingsChangedTo(int nativePtr,
+ String host,
+ int port);
+ @NativeClassQualifiedName("ProxyConfigServiceAndroid::JNIDelegate")
private native void nativeProxySettingsChanged(int nativePtr);
}