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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 // Use Java System.getProperty to get configuration information. | 153 // Use Java System.getProperty to get configuration information. |
| 153 // TODO(pliard): Conversion to/from UTF8 ok here? | 154 // TODO(pliard): Conversion to/from UTF8 ok here? |
| 154 JNIEnv* env = AttachCurrentThread(); | 155 JNIEnv* env = AttachCurrentThread(); |
| 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, int port, | 163 void CreateStaticProxyConfig(const std::string& host, |
| 164 int port, | |
| 165 const std::vector<std::string>& exclusion_list, | |
| 163 ProxyConfig* config) { | 166 ProxyConfig* config) { |
| 164 if (port != 0) { | 167 if (port != 0) { |
| 165 std::string rules = base::StringPrintf("%s:%d", host.c_str(), port); | 168 std::string rules = base::StringPrintf("%s:%d", host.c_str(), port); |
| 166 config->proxy_rules().ParseFromString(rules); | 169 config->proxy_rules().ParseFromString(rules); |
| 170 config->proxy_rules().bypass_rules.Clear(); | |
| 171 | |
| 172 std::vector<std::string>::const_iterator itr; | |
|
eroman
2014/09/23 21:17:09
nit: "it" is a more common iterator variable name
sgurun-gerrit only
2014/10/10 00:58:55
Done.
| |
| 173 for (itr = exclusion_list.begin(); itr != exclusion_list.end(); ++itr) { | |
| 174 std::string pattern; | |
| 175 base::TrimWhitespaceASCII(*itr, base::TRIM_ALL, &pattern); | |
| 176 if (pattern.empty()) | |
| 177 continue; | |
| 178 VLOG(0) << "Add bypass rules:" << pattern.c_str(); | |
|
eroman
2014/09/23 21:17:09
Is this vlog necessary?
sgurun-gerrit only
2014/10/10 00:58:55
Done.
| |
| 179 config->proxy_rules().bypass_rules.AddRuleForHostname("", pattern, -1); | |
| 180 } | |
| 167 } else { | 181 } else { |
| 168 *config = ProxyConfig::CreateDirect(); | 182 *config = ProxyConfig::CreateDirect(); |
| 169 } | 183 } |
| 170 } | 184 } |
| 171 | 185 |
| 172 } // namespace | 186 } // namespace |
| 173 | 187 |
| 174 class ProxyConfigServiceAndroid::Delegate | 188 class ProxyConfigServiceAndroid::Delegate |
| 175 : public base::RefCountedThreadSafe<Delegate> { | 189 : public base::RefCountedThreadSafe<Delegate> { |
| 176 public: | 190 public: |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 DCHECK(OnJNIThread()); | 255 DCHECK(OnJNIThread()); |
| 242 ProxyConfig proxy_config; | 256 ProxyConfig proxy_config; |
| 243 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); | 257 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); |
| 244 network_task_runner_->PostTask( | 258 network_task_runner_->PostTask( |
| 245 FROM_HERE, | 259 FROM_HERE, |
| 246 base::Bind( | 260 base::Bind( |
| 247 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); | 261 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); |
| 248 } | 262 } |
| 249 | 263 |
| 250 // Called on the JNI thread. | 264 // Called on the JNI thread. |
| 251 void ProxySettingsChangedTo(const std::string& host, int port) { | 265 void ProxySettingsChangedTo(const std::string& host, int port, |
| 266 const std::vector<std::string>& exclusion_list) { | |
| 252 DCHECK(OnJNIThread()); | 267 DCHECK(OnJNIThread()); |
| 253 ProxyConfig proxy_config; | 268 ProxyConfig proxy_config; |
| 254 CreateStaticProxyConfig(host, port, &proxy_config); | 269 CreateStaticProxyConfig(host, port, exclusion_list, &proxy_config); |
| 255 network_task_runner_->PostTask( | 270 network_task_runner_->PostTask( |
| 256 FROM_HERE, | 271 FROM_HERE, |
| 257 base::Bind( | 272 base::Bind( |
| 258 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); | 273 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); |
| 259 } | 274 } |
| 260 | 275 |
| 261 private: | 276 private: |
| 262 friend class base::RefCountedThreadSafe<Delegate>; | 277 friend class base::RefCountedThreadSafe<Delegate>; |
| 263 | 278 |
| 264 class JNIDelegateImpl : public ProxyConfigServiceAndroid::JNIDelegate { | 279 class JNIDelegateImpl : public ProxyConfigServiceAndroid::JNIDelegate { |
| 265 public: | 280 public: |
| 266 explicit JNIDelegateImpl(Delegate* delegate) : delegate_(delegate) {} | 281 explicit JNIDelegateImpl(Delegate* delegate) : delegate_(delegate) {} |
| 267 | 282 |
| 268 // ProxyConfigServiceAndroid::JNIDelegate overrides. | 283 // ProxyConfigServiceAndroid::JNIDelegate overrides. |
| 269 virtual void ProxySettingsChangedTo(JNIEnv* env, jobject jself, | 284 virtual void ProxySettingsChangedTo(JNIEnv* env, jobject jself, |
| 270 jstring jhost, jint jport) OVERRIDE { | 285 jstring jhost, jint jport, |
| 286 jobjectArray jexclusion_list) OVERRIDE { | |
| 271 std::string host = ConvertJavaStringToUTF8(env, jhost); | 287 std::string host = ConvertJavaStringToUTF8(env, jhost); |
| 272 delegate_->ProxySettingsChangedTo(host, jport); | 288 std::vector<std::string> exclusion_list; |
| 289 base::android::AppendJavaStringArrayToStringVector( | |
| 290 env, jexclusion_list, &exclusion_list); | |
| 291 delegate_->ProxySettingsChangedTo(host, jport, exclusion_list); | |
| 273 } | 292 } |
| 274 | 293 |
| 275 virtual void ProxySettingsChanged(JNIEnv* env, jobject self) OVERRIDE { | 294 virtual void ProxySettingsChanged(JNIEnv* env, jobject self) OVERRIDE { |
| 276 delegate_->ProxySettingsChanged(); | 295 delegate_->ProxySettingsChanged(); |
| 277 } | 296 } |
| 278 | 297 |
| 279 private: | 298 private: |
| 280 Delegate* const delegate_; | 299 Delegate* const delegate_; |
| 281 }; | 300 }; |
| 282 | 301 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 network_task_runner, jni_task_runner, get_property_callback)) { | 376 network_task_runner, jni_task_runner, get_property_callback)) { |
| 358 delegate_->SetupJNI(); | 377 delegate_->SetupJNI(); |
| 359 delegate_->FetchInitialConfig(); | 378 delegate_->FetchInitialConfig(); |
| 360 } | 379 } |
| 361 | 380 |
| 362 void ProxyConfigServiceAndroid::ProxySettingsChanged() { | 381 void ProxyConfigServiceAndroid::ProxySettingsChanged() { |
| 363 delegate_->ProxySettingsChanged(); | 382 delegate_->ProxySettingsChanged(); |
| 364 } | 383 } |
| 365 | 384 |
| 366 } // namespace net | 385 } // namespace net |
| OLD | NEW |