| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/cronet/android/cronet_url_request_context_adapter.h" | 5 #include "components/cronet/android/cronet_url_request_context_adapter.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 if (pref_service_) | 141 if (pref_service_) |
| 142 pref_service_->CommitPendingWrite(); | 142 pref_service_->CommitPendingWrite(); |
| 143 StopNetLogOnNetworkThread(); | 143 StopNetLogOnNetworkThread(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread( | 146 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread( |
| 147 JNIEnv* env, | 147 JNIEnv* env, |
| 148 jobject jcaller) { | 148 jobject jcaller) { |
| 149 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref; | 149 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref; |
| 150 jcaller_ref.Reset(env, jcaller); | 150 jcaller_ref.Reset(env, jcaller); |
| 151 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( |
| 152 GetNetworkTaskRunner(), nullptr /* Ignored on Android */); |
| 151 net::ProxyConfigServiceAndroid* android_proxy_config_service = | 153 net::ProxyConfigServiceAndroid* android_proxy_config_service = |
| 152 static_cast<net::ProxyConfigServiceAndroid*>( | 154 static_cast<net::ProxyConfigServiceAndroid*>(proxy_config_service_.get()); |
| 153 net::ProxyService::CreateSystemProxyConfigService( | |
| 154 GetNetworkTaskRunner(), nullptr /* Ignored on Android */)); | |
| 155 // If a PAC URL is present, ignore it and use the address and port of | 155 // If a PAC URL is present, ignore it and use the address and port of |
| 156 // Android system's local HTTP proxy server. See: crbug.com/432539. | 156 // Android system's local HTTP proxy server. See: crbug.com/432539. |
| 157 // TODO(csharrison) Architect the wrapper better so we don't need to cast for |
| 158 // android ProxyConfigServices. |
| 157 android_proxy_config_service->set_exclude_pac_url(true); | 159 android_proxy_config_service->set_exclude_pac_url(true); |
| 158 proxy_config_service_.reset(android_proxy_config_service); | |
| 159 GetNetworkTaskRunner()->PostTask( | 160 GetNetworkTaskRunner()->PostTask( |
| 160 FROM_HERE, | 161 FROM_HERE, |
| 161 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, | 162 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, |
| 162 base::Unretained(this), Passed(&context_config_), | 163 base::Unretained(this), Passed(&context_config_), |
| 163 jcaller_ref)); | 164 jcaller_ref)); |
| 164 } | 165 } |
| 165 | 166 |
| 166 void CronetURLRequestContextAdapter::InitializeOnNetworkThread( | 167 void CronetURLRequestContextAdapter::InitializeOnNetworkThread( |
| 167 scoped_ptr<URLRequestContextConfig> config, | 168 scoped_ptr<URLRequestContextConfig> config, |
| 168 const base::android::ScopedJavaGlobalRef<jobject>& | 169 const base::android::ScopedJavaGlobalRef<jobject>& |
| (...skipping 24 matching lines...) Expand all Loading... |
| 193 } | 194 } |
| 194 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT) | 195 #endif // defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 195 context_builder.set_network_delegate(network_delegate.Pass()); | 196 context_builder.set_network_delegate(network_delegate.Pass()); |
| 196 context_builder.set_net_log(net_log_.get()); | 197 context_builder.set_net_log(net_log_.get()); |
| 197 | 198 |
| 198 // Android provides a local HTTP proxy server that handles proxying when a PAC | 199 // Android provides a local HTTP proxy server that handles proxying when a PAC |
| 199 // URL is present. Create a proxy service without a resolver and rely on this | 200 // URL is present. Create a proxy service without a resolver and rely on this |
| 200 // local HTTP proxy. See: crbug.com/432539. | 201 // local HTTP proxy. See: crbug.com/432539. |
| 201 context_builder.set_proxy_service( | 202 context_builder.set_proxy_service( |
| 202 net::ProxyService::CreateWithoutProxyResolver( | 203 net::ProxyService::CreateWithoutProxyResolver( |
| 203 proxy_config_service_.release(), net_log_.get())); | 204 proxy_config_service_.Pass(), net_log_.get())); |
| 204 config->ConfigureURLRequestContextBuilder(&context_builder); | 205 config->ConfigureURLRequestContextBuilder(&context_builder); |
| 205 | 206 |
| 206 // Set up pref file if storage path is specified. | 207 // Set up pref file if storage path is specified. |
| 207 if (!config->storage_path.empty()) { | 208 if (!config->storage_path.empty()) { |
| 208 base::FilePath filepath(config->storage_path); | 209 base::FilePath filepath(config->storage_path); |
| 209 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json")); | 210 filepath = filepath.Append(FILE_PATH_LITERAL("local_prefs.json")); |
| 210 json_pref_store_ = new JsonPrefStore( | 211 json_pref_store_ = new JsonPrefStore( |
| 211 filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>()); | 212 filepath, GetFileThread()->task_runner(), scoped_ptr<PrefFilter>()); |
| 212 context_builder.SetFileTaskRunner(GetFileThread()->task_runner()); | 213 context_builder.SetFileTaskRunner(GetFileThread()->task_runner()); |
| 213 | 214 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 static jint SetMinLogLevel(JNIEnv* env, | 429 static jint SetMinLogLevel(JNIEnv* env, |
| 429 const JavaParamRef<jclass>& jcaller, | 430 const JavaParamRef<jclass>& jcaller, |
| 430 jint jlog_level) { | 431 jint jlog_level) { |
| 431 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); | 432 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); |
| 432 // MinLogLevel is global, shared by all URLRequestContexts. | 433 // MinLogLevel is global, shared by all URLRequestContexts. |
| 433 logging::SetMinLogLevel(static_cast<int>(jlog_level)); | 434 logging::SetMinLogLevel(static_cast<int>(jlog_level)); |
| 434 return old_log_level; | 435 return old_log_level; |
| 435 } | 436 } |
| 436 | 437 |
| 437 } // namespace cronet | 438 } // namespace cronet |
| OLD | NEW |