Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/proxy/proxy_config_service_android.h" | 5 #include "net/proxy/proxy_config_service_android.h" |
| 6 | 6 |
| 7 #include <sys/system_properties.h> | 7 #include <sys/system_properties.h> |
| 8 | 8 |
| 9 #include "base/android/jni_array.h" | |
| 9 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 14 #include "base/location.h" | 15 #include "base/location.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 17 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 18 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 ScopedJavaLocalRef<jstring> str = ConvertUTF8ToJavaString(env, property); | 156 ScopedJavaLocalRef<jstring> str = ConvertUTF8ToJavaString(env, property); |
| 156 ScopedJavaLocalRef<jstring> result = | 157 ScopedJavaLocalRef<jstring> result = |
| 157 Java_ProxyChangeListener_getProperty(env, str.obj()); | 158 Java_ProxyChangeListener_getProperty(env, str.obj()); |
| 158 return result.is_null() ? | 159 return result.is_null() ? |
| 159 std::string() : ConvertJavaStringToUTF8(env, result.obj()); | 160 std::string() : ConvertJavaStringToUTF8(env, result.obj()); |
| 160 } | 161 } |
| 161 | 162 |
| 162 void CreateStaticProxyConfig(const std::string& host, | 163 void CreateStaticProxyConfig(const std::string& host, |
| 163 int port, | 164 int port, |
| 164 const std::string& pac_url, | 165 const std::string& pac_url, |
| 166 const std::vector<std::string>& exclusion_list, | |
| 165 ProxyConfig* config) { | 167 ProxyConfig* config) { |
| 166 if (!pac_url.empty()) { | 168 if (!pac_url.empty()) { |
| 167 config->set_pac_url(GURL(pac_url)); | 169 config->set_pac_url(GURL(pac_url)); |
| 168 config->set_pac_mandatory(false); | 170 config->set_pac_mandatory(false); |
| 169 } else if (port != 0) { | 171 } else if (port != 0) { |
| 170 std::string rules = base::StringPrintf("%s:%d", host.c_str(), port); | 172 std::string rules = base::StringPrintf("%s:%d", host.c_str(), port); |
| 171 config->proxy_rules().ParseFromString(rules); | 173 config->proxy_rules().ParseFromString(rules); |
| 174 config->proxy_rules().bypass_rules.Clear(); | |
| 175 | |
| 176 std::vector<std::string>::const_iterator it; | |
| 177 for (it = exclusion_list.begin(); it != exclusion_list.end(); ++it) { | |
| 178 std::string pattern; | |
| 179 base::TrimWhitespaceASCII(*it, base::TRIM_ALL, &pattern); | |
| 180 if (pattern.empty()) | |
| 181 continue; | |
| 182 config->proxy_rules().bypass_rules.AddRuleForHostname("", pattern, -1); | |
|
sgurun-gerrit only
2014/10/10 00:58:55
himm, I am not fully sure if I am doing it right h
sgurun-gerrit only
2014/10/11 00:53:59
So it seems that the exclusion list that is manual
| |
| 183 } | |
| 172 } else { | 184 } else { |
| 173 *config = ProxyConfig::CreateDirect(); | 185 *config = ProxyConfig::CreateDirect(); |
| 174 } | 186 } |
| 175 } | 187 } |
| 176 | 188 |
| 177 } // namespace | 189 } // namespace |
| 178 | 190 |
| 179 class ProxyConfigServiceAndroid::Delegate | 191 class ProxyConfigServiceAndroid::Delegate |
| 180 : public base::RefCountedThreadSafe<Delegate> { | 192 : public base::RefCountedThreadSafe<Delegate> { |
| 181 public: | 193 public: |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); | 260 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); |
| 249 network_task_runner_->PostTask( | 261 network_task_runner_->PostTask( |
| 250 FROM_HERE, | 262 FROM_HERE, |
| 251 base::Bind( | 263 base::Bind( |
| 252 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); | 264 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); |
| 253 } | 265 } |
| 254 | 266 |
| 255 // Called on the JNI thread. | 267 // Called on the JNI thread. |
| 256 void ProxySettingsChangedTo(const std::string& host, | 268 void ProxySettingsChangedTo(const std::string& host, |
| 257 int port, | 269 int port, |
| 258 const std::string& pac_url) { | 270 const std::string& pac_url, |
| 271 const std::vector<std::string>& exclusion_list) { | |
| 259 DCHECK(OnJNIThread()); | 272 DCHECK(OnJNIThread()); |
| 260 ProxyConfig proxy_config; | 273 ProxyConfig proxy_config; |
| 261 CreateStaticProxyConfig(host, port, pac_url, &proxy_config); | 274 CreateStaticProxyConfig(host, port, pac_url, exclusion_list, &proxy_config); |
| 262 network_task_runner_->PostTask( | 275 network_task_runner_->PostTask( |
| 263 FROM_HERE, | 276 FROM_HERE, |
| 264 base::Bind( | 277 base::Bind( |
| 265 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); | 278 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); |
| 266 } | 279 } |
| 267 | 280 |
| 268 private: | 281 private: |
| 269 friend class base::RefCountedThreadSafe<Delegate>; | 282 friend class base::RefCountedThreadSafe<Delegate>; |
| 270 | 283 |
| 271 class JNIDelegateImpl : public ProxyConfigServiceAndroid::JNIDelegate { | 284 class JNIDelegateImpl : public ProxyConfigServiceAndroid::JNIDelegate { |
| 272 public: | 285 public: |
| 273 explicit JNIDelegateImpl(Delegate* delegate) : delegate_(delegate) {} | 286 explicit JNIDelegateImpl(Delegate* delegate) : delegate_(delegate) {} |
| 274 | 287 |
| 275 // ProxyConfigServiceAndroid::JNIDelegate overrides. | 288 // ProxyConfigServiceAndroid::JNIDelegate overrides. |
| 276 virtual void ProxySettingsChangedTo(JNIEnv* env, | 289 virtual void ProxySettingsChangedTo(JNIEnv* env, |
| 277 jobject jself, | 290 jobject jself, |
| 278 jstring jhost, | 291 jstring jhost, |
| 279 jint jport, | 292 jint jport, |
| 280 jstring jpac_url) override { | 293 jstring jpac_url, |
| 294 jobjectArray jexclusion_list) override { | |
| 281 std::string host = ConvertJavaStringToUTF8(env, jhost); | 295 std::string host = ConvertJavaStringToUTF8(env, jhost); |
| 282 std::string pac_url; | 296 std::string pac_url; |
| 283 if (jpac_url) | 297 if (jpac_url) |
| 284 ConvertJavaStringToUTF8(env, jpac_url, &pac_url); | 298 ConvertJavaStringToUTF8(env, jpac_url, &pac_url); |
| 285 delegate_->ProxySettingsChangedTo(host, jport, pac_url); | 299 std::vector<std::string> exclusion_list; |
| 300 base::android::AppendJavaStringArrayToStringVector( | |
| 301 env, jexclusion_list, &exclusion_list); | |
| 302 delegate_->ProxySettingsChangedTo(host, jport, pac_url, exclusion_list); | |
| 286 } | 303 } |
| 287 | 304 |
| 288 virtual void ProxySettingsChanged(JNIEnv* env, jobject self) override { | 305 virtual void ProxySettingsChanged(JNIEnv* env, jobject self) override { |
| 289 delegate_->ProxySettingsChanged(); | 306 delegate_->ProxySettingsChanged(); |
| 290 } | 307 } |
| 291 | 308 |
| 292 private: | 309 private: |
| 293 Delegate* const delegate_; | 310 Delegate* const delegate_; |
| 294 }; | 311 }; |
| 295 | 312 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 network_task_runner, jni_task_runner, get_property_callback)) { | 387 network_task_runner, jni_task_runner, get_property_callback)) { |
| 371 delegate_->SetupJNI(); | 388 delegate_->SetupJNI(); |
| 372 delegate_->FetchInitialConfig(); | 389 delegate_->FetchInitialConfig(); |
| 373 } | 390 } |
| 374 | 391 |
| 375 void ProxyConfigServiceAndroid::ProxySettingsChanged() { | 392 void ProxyConfigServiceAndroid::ProxySettingsChanged() { |
| 376 delegate_->ProxySettingsChanged(); | 393 delegate_->ProxySettingsChanged(); |
| 377 } | 394 } |
| 378 | 395 |
| 379 } // namespace net | 396 } // namespace net |
| OLD | NEW |