| 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_array.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 const scoped_refptr<base::SequencedTaskRunner>& jni_task_runner, | 197 const scoped_refptr<base::SequencedTaskRunner>& jni_task_runner, |
| 198 const GetPropertyCallback& get_property_callback) | 198 const GetPropertyCallback& get_property_callback) |
| 199 : jni_delegate_(this), | 199 : jni_delegate_(this), |
| 200 network_task_runner_(network_task_runner), | 200 network_task_runner_(network_task_runner), |
| 201 jni_task_runner_(jni_task_runner), | 201 jni_task_runner_(jni_task_runner), |
| 202 get_property_callback_(get_property_callback), | 202 get_property_callback_(get_property_callback), |
| 203 exclude_pac_url_(false) { | 203 exclude_pac_url_(false) { |
| 204 } | 204 } |
| 205 | 205 |
| 206 void SetupJNI() { | 206 void SetupJNI() { |
| 207 DCHECK(OnJNIThread()); | 207 DCHECK(InJNISequence()); |
| 208 JNIEnv* env = AttachCurrentThread(); | 208 JNIEnv* env = AttachCurrentThread(); |
| 209 if (java_proxy_change_listener_.is_null()) { | 209 if (java_proxy_change_listener_.is_null()) { |
| 210 java_proxy_change_listener_.Reset(Java_ProxyChangeListener_create(env)); | 210 java_proxy_change_listener_.Reset(Java_ProxyChangeListener_create(env)); |
| 211 CHECK(!java_proxy_change_listener_.is_null()); | 211 CHECK(!java_proxy_change_listener_.is_null()); |
| 212 } | 212 } |
| 213 Java_ProxyChangeListener_start(env, java_proxy_change_listener_, | 213 Java_ProxyChangeListener_start(env, java_proxy_change_listener_, |
| 214 reinterpret_cast<intptr_t>(&jni_delegate_)); | 214 reinterpret_cast<intptr_t>(&jni_delegate_)); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void FetchInitialConfig() { | 217 void FetchInitialConfig() { |
| 218 DCHECK(OnJNIThread()); | 218 DCHECK(InJNISequence()); |
| 219 ProxyConfig proxy_config; | 219 ProxyConfig proxy_config; |
| 220 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); | 220 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); |
| 221 network_task_runner_->PostTask( | 221 network_task_runner_->PostTask( |
| 222 FROM_HERE, | 222 FROM_HERE, base::Bind(&Delegate::SetNewConfigInNetworkSequence, this, |
| 223 base::Bind(&Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); | 223 proxy_config)); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void Shutdown() { | 226 void Shutdown() { |
| 227 if (OnJNIThread()) { | 227 if (InJNISequence()) { |
| 228 ShutdownOnJNIThread(); | 228 ShutdownInJNISequence(); |
| 229 } else { | 229 } else { |
| 230 jni_task_runner_->PostTask( | 230 jni_task_runner_->PostTask( |
| 231 FROM_HERE, | 231 FROM_HERE, base::Bind(&Delegate::ShutdownInJNISequence, this)); |
| 232 base::Bind(&Delegate::ShutdownOnJNIThread, this)); | |
| 233 } | 232 } |
| 234 } | 233 } |
| 235 | 234 |
| 236 // Called only on the network thread. | 235 // Called only in the network sequence. |
| 237 void AddObserver(Observer* observer) { | 236 void AddObserver(Observer* observer) { |
| 238 DCHECK(OnNetworkThread()); | 237 DCHECK(InNetworkSequence()); |
| 239 observers_.AddObserver(observer); | 238 observers_.AddObserver(observer); |
| 240 } | 239 } |
| 241 | 240 |
| 242 void RemoveObserver(Observer* observer) { | 241 void RemoveObserver(Observer* observer) { |
| 243 DCHECK(OnNetworkThread()); | 242 DCHECK(InNetworkSequence()); |
| 244 observers_.RemoveObserver(observer); | 243 observers_.RemoveObserver(observer); |
| 245 } | 244 } |
| 246 | 245 |
| 247 ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) { | 246 ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) { |
| 248 DCHECK(OnNetworkThread()); | 247 DCHECK(InNetworkSequence()); |
| 249 if (!config) | 248 if (!config) |
| 250 return ProxyConfigService::CONFIG_UNSET; | 249 return ProxyConfigService::CONFIG_UNSET; |
| 251 *config = proxy_config_; | 250 *config = proxy_config_; |
| 252 return ProxyConfigService::CONFIG_VALID; | 251 return ProxyConfigService::CONFIG_VALID; |
| 253 } | 252 } |
| 254 | 253 |
| 255 // Called on the JNI thread. | 254 // Called in the JNI sequence. |
| 256 void ProxySettingsChanged() { | 255 void ProxySettingsChanged() { |
| 257 DCHECK(OnJNIThread()); | 256 DCHECK(InJNISequence()); |
| 258 ProxyConfig proxy_config; | 257 ProxyConfig proxy_config; |
| 259 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); | 258 GetLatestProxyConfigInternal(get_property_callback_, &proxy_config); |
| 260 network_task_runner_->PostTask( | 259 network_task_runner_->PostTask( |
| 261 FROM_HERE, | 260 FROM_HERE, base::Bind(&Delegate::SetNewConfigInNetworkSequence, this, |
| 262 base::Bind( | 261 proxy_config)); |
| 263 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); | |
| 264 } | 262 } |
| 265 | 263 |
| 266 // Called on the JNI thread. | 264 // Called in the JNI sequence. |
| 267 void ProxySettingsChangedTo(const std::string& host, | 265 void ProxySettingsChangedTo(const std::string& host, |
| 268 int port, | 266 int port, |
| 269 const std::string& pac_url, | 267 const std::string& pac_url, |
| 270 const std::vector<std::string>& exclusion_list) { | 268 const std::vector<std::string>& exclusion_list) { |
| 271 DCHECK(OnJNIThread()); | 269 DCHECK(InJNISequence()); |
| 272 ProxyConfig proxy_config; | 270 ProxyConfig proxy_config; |
| 273 if (exclude_pac_url_) { | 271 if (exclude_pac_url_) { |
| 274 CreateStaticProxyConfig(host, port, "", exclusion_list, &proxy_config); | 272 CreateStaticProxyConfig(host, port, "", exclusion_list, &proxy_config); |
| 275 } else { | 273 } else { |
| 276 CreateStaticProxyConfig(host, port, pac_url, exclusion_list, | 274 CreateStaticProxyConfig(host, port, pac_url, exclusion_list, |
| 277 &proxy_config); | 275 &proxy_config); |
| 278 } | 276 } |
| 279 network_task_runner_->PostTask( | 277 network_task_runner_->PostTask( |
| 280 FROM_HERE, | 278 FROM_HERE, base::Bind(&Delegate::SetNewConfigInNetworkSequence, this, |
| 281 base::Bind( | 279 proxy_config)); |
| 282 &Delegate::SetNewConfigOnNetworkThread, this, proxy_config)); | |
| 283 } | 280 } |
| 284 | 281 |
| 285 void set_exclude_pac_url(bool enabled) { | 282 void set_exclude_pac_url(bool enabled) { |
| 286 exclude_pac_url_ = enabled; | 283 exclude_pac_url_ = enabled; |
| 287 } | 284 } |
| 288 | 285 |
| 289 private: | 286 private: |
| 290 friend class base::RefCountedThreadSafe<Delegate>; | 287 friend class base::RefCountedThreadSafe<Delegate>; |
| 291 | 288 |
| 292 class JNIDelegateImpl : public ProxyConfigServiceAndroid::JNIDelegate { | 289 class JNIDelegateImpl : public ProxyConfigServiceAndroid::JNIDelegate { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 315 const JavaParamRef<jobject>& self) override { | 312 const JavaParamRef<jobject>& self) override { |
| 316 delegate_->ProxySettingsChanged(); | 313 delegate_->ProxySettingsChanged(); |
| 317 } | 314 } |
| 318 | 315 |
| 319 private: | 316 private: |
| 320 Delegate* const delegate_; | 317 Delegate* const delegate_; |
| 321 }; | 318 }; |
| 322 | 319 |
| 323 virtual ~Delegate() {} | 320 virtual ~Delegate() {} |
| 324 | 321 |
| 325 void ShutdownOnJNIThread() { | 322 void ShutdownInJNISequence() { |
| 326 if (java_proxy_change_listener_.is_null()) | 323 if (java_proxy_change_listener_.is_null()) |
| 327 return; | 324 return; |
| 328 JNIEnv* env = AttachCurrentThread(); | 325 JNIEnv* env = AttachCurrentThread(); |
| 329 Java_ProxyChangeListener_stop(env, java_proxy_change_listener_); | 326 Java_ProxyChangeListener_stop(env, java_proxy_change_listener_); |
| 330 } | 327 } |
| 331 | 328 |
| 332 // Called on the network thread. | 329 // Called on the network sequence. |
| 333 void SetNewConfigOnNetworkThread(const ProxyConfig& proxy_config) { | 330 void SetNewConfigInNetworkSequence(const ProxyConfig& proxy_config) { |
| 334 DCHECK(OnNetworkThread()); | 331 DCHECK(InNetworkSequence()); |
| 335 proxy_config_ = proxy_config; | 332 proxy_config_ = proxy_config; |
| 336 for (auto& observer : observers_) { | 333 for (auto& observer : observers_) { |
| 337 observer.OnProxyConfigChanged(proxy_config, | 334 observer.OnProxyConfigChanged(proxy_config, |
| 338 ProxyConfigService::CONFIG_VALID); | 335 ProxyConfigService::CONFIG_VALID); |
| 339 } | 336 } |
| 340 } | 337 } |
| 341 | 338 |
| 342 bool OnJNIThread() const { | 339 bool InJNISequence() const { |
| 343 return jni_task_runner_->RunsTasksOnCurrentThread(); | 340 return jni_task_runner_->RunsTasksInCurrentSequence(); |
| 344 } | 341 } |
| 345 | 342 |
| 346 bool OnNetworkThread() const { | 343 bool InNetworkSequence() const { |
| 347 return network_task_runner_->RunsTasksOnCurrentThread(); | 344 return network_task_runner_->RunsTasksInCurrentSequence(); |
| 348 } | 345 } |
| 349 | 346 |
| 350 ScopedJavaGlobalRef<jobject> java_proxy_change_listener_; | 347 ScopedJavaGlobalRef<jobject> java_proxy_change_listener_; |
| 351 | 348 |
| 352 JNIDelegateImpl jni_delegate_; | 349 JNIDelegateImpl jni_delegate_; |
| 353 base::ObserverList<Observer> observers_; | 350 base::ObserverList<Observer> observers_; |
| 354 scoped_refptr<base::SequencedTaskRunner> network_task_runner_; | 351 scoped_refptr<base::SequencedTaskRunner> network_task_runner_; |
| 355 scoped_refptr<base::SequencedTaskRunner> jni_task_runner_; | 352 scoped_refptr<base::SequencedTaskRunner> jni_task_runner_; |
| 356 GetPropertyCallback get_property_callback_; | 353 GetPropertyCallback get_property_callback_; |
| 357 ProxyConfig proxy_config_; | 354 ProxyConfig proxy_config_; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 network_task_runner, jni_task_runner, get_property_callback)) { | 400 network_task_runner, jni_task_runner, get_property_callback)) { |
| 404 delegate_->SetupJNI(); | 401 delegate_->SetupJNI(); |
| 405 delegate_->FetchInitialConfig(); | 402 delegate_->FetchInitialConfig(); |
| 406 } | 403 } |
| 407 | 404 |
| 408 void ProxyConfigServiceAndroid::ProxySettingsChanged() { | 405 void ProxyConfigServiceAndroid::ProxySettingsChanged() { |
| 409 delegate_->ProxySettingsChanged(); | 406 delegate_->ProxySettingsChanged(); |
| 410 } | 407 } |
| 411 | 408 |
| 412 } // namespace net | 409 } // namespace net |
| OLD | NEW |