| 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_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // Use Java System.getProperty to get configuration information. | 152 // Use Java System.getProperty to get configuration information. |
| 153 // TODO(pliard): Conversion to/from UTF8 ok here? | 153 // TODO(pliard): Conversion to/from UTF8 ok here? |
| 154 JNIEnv* env = AttachCurrentThread(); | 154 JNIEnv* env = AttachCurrentThread(); |
| 155 ScopedJavaLocalRef<jstring> str = ConvertUTF8ToJavaString(env, property); | 155 ScopedJavaLocalRef<jstring> str = ConvertUTF8ToJavaString(env, property); |
| 156 ScopedJavaLocalRef<jstring> result = | 156 ScopedJavaLocalRef<jstring> result = |
| 157 Java_ProxyChangeListener_getProperty(env, str.obj()); | 157 Java_ProxyChangeListener_getProperty(env, str.obj()); |
| 158 return result.is_null() ? | 158 return result.is_null() ? |
| 159 std::string() : ConvertJavaStringToUTF8(env, result.obj()); | 159 std::string() : ConvertJavaStringToUTF8(env, result.obj()); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void CreateStaticProxyConfig(const std::string& host, int port, | 162 void CreateStaticProxyConfig(const std::string& host, |
| 163 int port, |
| 164 const std::string& pac_url, |
| 163 ProxyConfig* config) { | 165 ProxyConfig* config) { |
| 164 if (port != 0) { | 166 if (!pac_url.empty()) { |
| 167 config->set_pac_url(GURL(pac_url)); |
| 168 config->set_pac_mandatory(false); |
| 169 } else if (port != 0) { |
| 165 std::string rules = base::StringPrintf("%s:%d", host.c_str(), port); | 170 std::string rules = base::StringPrintf("%s:%d", host.c_str(), port); |
| 166 config->proxy_rules().ParseFromString(rules); | 171 config->proxy_rules().ParseFromString(rules); |
| 167 } else { | 172 } else { |
| 168 *config = ProxyConfig::CreateDirect(); | 173 *config = ProxyConfig::CreateDirect(); |
| 169 } | 174 } |
| 170 } | 175 } |
| 171 | 176 |
| 172 } // namespace | 177 } // namespace |
| 173 | 178 |
| 174 class ProxyConfigServiceAndroid::Delegate | 179 class ProxyConfigServiceAndroid::Delegate |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 DCHECK(OnJNIThread()); | 246 DCHECK(OnJNIThread()); |
| 242 ProxyConfig proxy_config; | 247 ProxyConfig proxy_config; |
| 243 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); | 248 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); |
| 244 network_task_runner_->PostTask( | 249 network_task_runner_->PostTask( |
| 245 FROM_HERE, | 250 FROM_HERE, |
| 246 base::Bind( | 251 base::Bind( |
| 247 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); | 252 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); |
| 248 } | 253 } |
| 249 | 254 |
| 250 // Called on the JNI thread. | 255 // Called on the JNI thread. |
| 251 void ProxySettingsChangedTo(const std::string& host, int port) { | 256 void ProxySettingsChangedTo(const std::string& host, |
| 257 int port, |
| 258 const std::string& pac_url) { |
| 252 DCHECK(OnJNIThread()); | 259 DCHECK(OnJNIThread()); |
| 253 ProxyConfig proxy_config; | 260 ProxyConfig proxy_config; |
| 254 CreateStaticProxyConfig(host, port, &proxy_config); | 261 CreateStaticProxyConfig(host, port, pac_url, &proxy_config); |
| 255 network_task_runner_->PostTask( | 262 network_task_runner_->PostTask( |
| 256 FROM_HERE, | 263 FROM_HERE, |
| 257 base::Bind( | 264 base::Bind( |
| 258 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); | 265 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); |
| 259 } | 266 } |
| 260 | 267 |
| 261 private: | 268 private: |
| 262 friend class base::RefCountedThreadSafe<Delegate>; | 269 friend class base::RefCountedThreadSafe<Delegate>; |
| 263 | 270 |
| 264 class JNIDelegateImpl : public ProxyConfigServiceAndroid::JNIDelegate { | 271 class JNIDelegateImpl : public ProxyConfigServiceAndroid::JNIDelegate { |
| 265 public: | 272 public: |
| 266 explicit JNIDelegateImpl(Delegate* delegate) : delegate_(delegate) {} | 273 explicit JNIDelegateImpl(Delegate* delegate) : delegate_(delegate) {} |
| 267 | 274 |
| 268 // ProxyConfigServiceAndroid::JNIDelegate overrides. | 275 // ProxyConfigServiceAndroid::JNIDelegate overrides. |
| 269 virtual void ProxySettingsChangedTo(JNIEnv* env, jobject jself, | 276 virtual void ProxySettingsChangedTo(JNIEnv* env, |
| 270 jstring jhost, jint jport) OVERRIDE { | 277 jobject jself, |
| 278 jstring jhost, |
| 279 jint jport, |
| 280 jstring jpac_url) OVERRIDE { |
| 271 std::string host = ConvertJavaStringToUTF8(env, jhost); | 281 std::string host = ConvertJavaStringToUTF8(env, jhost); |
| 272 delegate_->ProxySettingsChangedTo(host, jport); | 282 std::string pac_url; |
| 283 if (jpac_url) |
| 284 ConvertJavaStringToUTF8(env, jpac_url, &pac_url); |
| 285 delegate_->ProxySettingsChangedTo(host, jport, pac_url); |
| 273 } | 286 } |
| 274 | 287 |
| 275 virtual void ProxySettingsChanged(JNIEnv* env, jobject self) OVERRIDE { | 288 virtual void ProxySettingsChanged(JNIEnv* env, jobject self) OVERRIDE { |
| 276 delegate_->ProxySettingsChanged(); | 289 delegate_->ProxySettingsChanged(); |
| 277 } | 290 } |
| 278 | 291 |
| 279 private: | 292 private: |
| 280 Delegate* const delegate_; | 293 Delegate* const delegate_; |
| 281 }; | 294 }; |
| 282 | 295 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 network_task_runner, jni_task_runner, get_property_callback)) { | 370 network_task_runner, jni_task_runner, get_property_callback)) { |
| 358 delegate_->SetupJNI(); | 371 delegate_->SetupJNI(); |
| 359 delegate_->FetchInitialConfig(); | 372 delegate_->FetchInitialConfig(); |
| 360 } | 373 } |
| 361 | 374 |
| 362 void ProxyConfigServiceAndroid::ProxySettingsChanged() { | 375 void ProxyConfigServiceAndroid::ProxySettingsChanged() { |
| 363 delegate_->ProxySettingsChanged(); | 376 delegate_->ProxySettingsChanged(); |
| 364 } | 377 } |
| 365 | 378 |
| 366 } // namespace net | 379 } // namespace net |
| OLD | NEW |