Chromium Code Reviews| Index: net/proxy/proxy_config_service_android.cc |
| diff --git a/net/proxy/proxy_config_service_android.cc b/net/proxy/proxy_config_service_android.cc |
| index 41bef8a4cd8dbdd91e772a2acc4104932f59e50c..f0a5446f372423b87c26e5542d5a90570e019fc7 100644 |
| --- a/net/proxy/proxy_config_service_android.cc |
| +++ b/net/proxy/proxy_config_service_android.cc |
| @@ -18,6 +18,7 @@ |
| #include "base/sequenced_task_runner.h" |
| #include "base/strings/string_tokenizer.h" |
| #include "base/strings/string_util.h" |
| +#include "base/strings/stringprintf.h" |
| #include "jni/ProxyChangeListener_jni.h" |
| #include "net/base/host_port_pair.h" |
| #include "net/proxy/proxy_config.h" |
| @@ -159,6 +160,16 @@ std::string GetJavaProperty(const std::string& property) { |
| std::string() : ConvertJavaStringToUTF8(env, result.obj()); |
| } |
| +void CreateStaticProxyConfig(ProxyConfig* config, const std::string& host, |
|
Philippe
2013/10/15 14:33:21
Nit: |config| should go last since it's an output
Elly Fong-Jones
2013/10/15 16:37:15
Done.
|
| + int port) { |
| + if (port != 0) { |
| + std::string rules = base::StringPrintf("%s:%d", host.c_str(), port); |
| + config->proxy_rules().ParseFromString(rules); |
| + } else { |
| + *config = ProxyConfig::CreateDirect(); |
| + } |
| +} |
| + |
| } // namespace |
| class ProxyConfigServiceAndroid::Delegate |
| @@ -237,6 +248,17 @@ class ProxyConfigServiceAndroid::Delegate |
| &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); |
| } |
| + // Called on the JNI thread. |
| + void ProxySettingsChangedTo(const std::string& host, int port) { |
| + DCHECK(OnJNIThread()); |
| + ProxyConfig proxy_config; |
| + CreateStaticProxyConfig(&proxy_config, host, port); |
| + network_task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind( |
| + &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); |
| + } |
| + |
| private: |
| friend class base::RefCountedThreadSafe<Delegate>; |
| @@ -245,8 +267,23 @@ class ProxyConfigServiceAndroid::Delegate |
| explicit JNIDelegateImpl(Delegate* delegate) : delegate_(delegate) {} |
| // ProxyConfigServiceAndroid::JNIDelegate overrides. |
| - virtual void ProxySettingsChanged(JNIEnv*, jobject) OVERRIDE { |
| - delegate_->ProxySettingsChanged(); |
| + // Pull the host and port out of the supplied ProxyConfig object and pass |
| + // them on to the delegate. |
| + virtual void ProxySettingsChanged(JNIEnv* env, jobject jself, |
|
Philippe
2013/10/15 14:33:21
See my comment in the Java file (TL;DR: please dir
Elly Fong-Jones
2013/10/15 16:37:15
Done.
|
| + jobject jcfg) OVERRIDE { |
| + jclass cls = env->GetObjectClass(jcfg); |
| + |
| + jfieldID hostfield = env->GetFieldID(cls, "host_", "Ljava/lang/String;"); |
| + jstring hoststr = (jstring)(env->GetObjectField(jcfg, hostfield)); |
| + jsize len = env->GetStringLength(hoststr); |
| + const char *chars = env->GetStringUTFChars(hoststr, NULL); |
| + std::string host(chars, len); |
| + env->ReleaseStringUTFChars(hoststr, chars); |
| + |
| + jfieldID portfield = env->GetFieldID(cls, "port_", "I"); |
| + jint port = env->GetIntField(jcfg, portfield); |
| + |
| + delegate_->ProxySettingsChangedTo(host, port); |
| } |
| private: |