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

Unified Diff: net/proxy/proxy_config_service_android.cc

Issue 26763005: android: Use new proxy from PROXY_CHANGE intent (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Catch NPE from intent.getExtras() Created 7 years, 2 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
« no previous file with comments | « net/proxy/proxy_config_service_android.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..23a420605efa6bf9ef174b38856687be2cf292ab 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,7 +267,13 @@ class ProxyConfigServiceAndroid::Delegate
explicit JNIDelegateImpl(Delegate* delegate) : delegate_(delegate) {}
// ProxyConfigServiceAndroid::JNIDelegate overrides.
- virtual void ProxySettingsChanged(JNIEnv*, jobject) OVERRIDE {
+ virtual void ProxySettingsChangedTo(JNIEnv* env, jobject jself,
+ jstring jhost, jint jport) OVERRIDE {
+ std::string host = ConvertJavaStringToUTF8(env, jhost);
+ delegate_->ProxySettingsChangedTo(host, jport);
+ }
+
+ virtual void ProxySettingsChanged(JNIEnv* env, jobject self) OVERRIDE {
delegate_->ProxySettingsChanged();
}
« no previous file with comments | « net/proxy/proxy_config_service_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698