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/context_utils.h" | 9 #include "base/android/context_utils.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 if (!GetProxyRules(get_property, &config->proxy_rules())) | 151 if (!GetProxyRules(get_property, &config->proxy_rules())) |
152 *config = ProxyConfig::CreateDirect(); | 152 *config = ProxyConfig::CreateDirect(); |
153 } | 153 } |
154 | 154 |
155 std::string GetJavaProperty(const std::string& property) { | 155 std::string GetJavaProperty(const std::string& property) { |
156 // Use Java System.getProperty to get configuration information. | 156 // Use Java System.getProperty to get configuration information. |
157 // TODO(pliard): Conversion to/from UTF8 ok here? | 157 // TODO(pliard): Conversion to/from UTF8 ok here? |
158 JNIEnv* env = AttachCurrentThread(); | 158 JNIEnv* env = AttachCurrentThread(); |
159 ScopedJavaLocalRef<jstring> str = ConvertUTF8ToJavaString(env, property); | 159 ScopedJavaLocalRef<jstring> str = ConvertUTF8ToJavaString(env, property); |
160 ScopedJavaLocalRef<jstring> result = | 160 ScopedJavaLocalRef<jstring> result = |
161 Java_ProxyChangeListener_getProperty(env, str.obj()); | 161 Java_ProxyChangeListener_getProperty(env, str); |
162 return result.is_null() ? | 162 return result.is_null() ? |
163 std::string() : ConvertJavaStringToUTF8(env, result.obj()); | 163 std::string() : ConvertJavaStringToUTF8(env, result.obj()); |
164 } | 164 } |
165 | 165 |
166 void CreateStaticProxyConfig(const std::string& host, | 166 void CreateStaticProxyConfig(const std::string& host, |
167 int port, | 167 int port, |
168 const std::string& pac_url, | 168 const std::string& pac_url, |
169 const std::vector<std::string>& exclusion_list, | 169 const std::vector<std::string>& exclusion_list, |
170 ProxyConfig* config) { | 170 ProxyConfig* config) { |
171 if (!pac_url.empty()) { | 171 if (!pac_url.empty()) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 206 |
207 void SetupJNI() { | 207 void SetupJNI() { |
208 DCHECK(OnJNIThread()); | 208 DCHECK(OnJNIThread()); |
209 JNIEnv* env = AttachCurrentThread(); | 209 JNIEnv* env = AttachCurrentThread(); |
210 if (java_proxy_change_listener_.is_null()) { | 210 if (java_proxy_change_listener_.is_null()) { |
211 java_proxy_change_listener_.Reset( | 211 java_proxy_change_listener_.Reset( |
212 Java_ProxyChangeListener_create( | 212 Java_ProxyChangeListener_create( |
213 env, base::android::GetApplicationContext())); | 213 env, base::android::GetApplicationContext())); |
214 CHECK(!java_proxy_change_listener_.is_null()); | 214 CHECK(!java_proxy_change_listener_.is_null()); |
215 } | 215 } |
216 Java_ProxyChangeListener_start( | 216 Java_ProxyChangeListener_start(env, java_proxy_change_listener_, |
217 env, | 217 reinterpret_cast<intptr_t>(&jni_delegate_)); |
218 java_proxy_change_listener_.obj(), | |
219 reinterpret_cast<intptr_t>(&jni_delegate_)); | |
220 } | 218 } |
221 | 219 |
222 void FetchInitialConfig() { | 220 void FetchInitialConfig() { |
223 DCHECK(OnJNIThread()); | 221 DCHECK(OnJNIThread()); |
224 ProxyConfig proxy_config; | 222 ProxyConfig proxy_config; |
225 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); | 223 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); |
226 network_task_runner_->PostTask( | 224 network_task_runner_->PostTask( |
227 FROM_HERE, | 225 FROM_HERE, |
228 base::Bind(&Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); | 226 base::Bind(&Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); |
229 } | 227 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 private: | 322 private: |
325 Delegate* const delegate_; | 323 Delegate* const delegate_; |
326 }; | 324 }; |
327 | 325 |
328 virtual ~Delegate() {} | 326 virtual ~Delegate() {} |
329 | 327 |
330 void ShutdownOnJNIThread() { | 328 void ShutdownOnJNIThread() { |
331 if (java_proxy_change_listener_.is_null()) | 329 if (java_proxy_change_listener_.is_null()) |
332 return; | 330 return; |
333 JNIEnv* env = AttachCurrentThread(); | 331 JNIEnv* env = AttachCurrentThread(); |
334 Java_ProxyChangeListener_stop(env, java_proxy_change_listener_.obj()); | 332 Java_ProxyChangeListener_stop(env, java_proxy_change_listener_); |
335 } | 333 } |
336 | 334 |
337 // Called on the network thread. | 335 // Called on the network thread. |
338 void SetNewConfigOnNetworkThread(const ProxyConfig& proxy_config) { | 336 void SetNewConfigOnNetworkThread(const ProxyConfig& proxy_config) { |
339 DCHECK(OnNetworkThread()); | 337 DCHECK(OnNetworkThread()); |
340 proxy_config_ = proxy_config; | 338 proxy_config_ = proxy_config; |
341 FOR_EACH_OBSERVER(Observer, observers_, | 339 FOR_EACH_OBSERVER(Observer, observers_, |
342 OnProxyConfigChanged(proxy_config, | 340 OnProxyConfigChanged(proxy_config, |
343 ProxyConfigService::CONFIG_VALID)); | 341 ProxyConfigService::CONFIG_VALID)); |
344 } | 342 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 network_task_runner, jni_task_runner, get_property_callback)) { | 405 network_task_runner, jni_task_runner, get_property_callback)) { |
408 delegate_->SetupJNI(); | 406 delegate_->SetupJNI(); |
409 delegate_->FetchInitialConfig(); | 407 delegate_->FetchInitialConfig(); |
410 } | 408 } |
411 | 409 |
412 void ProxyConfigServiceAndroid::ProxySettingsChanged() { | 410 void ProxyConfigServiceAndroid::ProxySettingsChanged() { |
413 delegate_->ProxySettingsChanged(); | 411 delegate_->ProxySettingsChanged(); |
414 } | 412 } |
415 | 413 |
416 } // namespace net | 414 } // namespace net |
OLD | NEW |