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..097134fa6127966e9751903e007ee3d943d18ffb 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(const std::string& host, int port, |
| + ProxyConfig* config) { |
| + 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(host, port, &proxy_config); |
| + network_task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind( |
| + &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); |
| + } |
| + |
| private: |
| friend class base::RefCountedThreadSafe<Delegate>; |
| @@ -245,8 +267,14 @@ class ProxyConfigServiceAndroid::Delegate |
| explicit JNIDelegateImpl(Delegate* delegate) : delegate_(delegate) {} |
| // ProxyConfigServiceAndroid::JNIDelegate overrides. |
| - virtual void ProxySettingsChanged(JNIEnv*, jobject) OVERRIDE { |
| - delegate_->ProxySettingsChanged(); |
| + virtual void ProxySettingsChanged(JNIEnv* env, jobject jself, |
| + jstring jhost, jint jport) OVERRIDE { |
| + jsize len = env->GetStringLength(jhost); |
| + const char *chars = env->GetStringUTFChars(jhost, NULL); |
| + std::string host(chars, len); |
| + env->ReleaseStringUTFChars(jhost, chars); |
|
Philippe
2013/10/15 16:45:59
Sorry for not pointing you to that earlier, but yo
|
| + |
| + delegate_->ProxySettingsChangedTo(host, jport); |
| } |
| private: |