Chromium Code Reviews| 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" |
| 11 #include "base/files/scoped_file.h" | 11 #include "base/files/scoped_file.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/prefs/pref_filter.h" | 15 #include "base/prefs/pref_filter.h" |
| 16 #include "base/prefs/pref_registry_simple.h" | 16 #include "base/prefs/pref_registry_simple.h" |
| 17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 18 #include "base/prefs/pref_service_factory.h" | 18 #include "base/prefs/pref_service_factory.h" |
| 19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "components/cronet/url_request_context_config.h" | 22 #include "components/cronet/url_request_context_config.h" |
| 23 #include "jni/CronetUrlRequestContext_jni.h" | 23 #include "jni/CronetUrlRequestContext_jni.h" |
| 24 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
| 25 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 26 #include "net/base/network_delegate_impl.h" | 26 #include "net/base/network_delegate_impl.h" |
| 27 #include "net/base/network_quality_estimator.h" | |
| 27 #include "net/http/http_auth_handler_factory.h" | 28 #include "net/http/http_auth_handler_factory.h" |
| 28 #include "net/http/http_server_properties_manager.h" | 29 #include "net/http/http_server_properties_manager.h" |
| 29 #include "net/log/write_to_file_net_log_observer.h" | 30 #include "net/log/write_to_file_net_log_observer.h" |
| 30 #include "net/proxy/proxy_service.h" | 31 #include "net/proxy/proxy_service.h" |
| 31 #include "net/sdch/sdch_owner.h" | 32 #include "net/sdch/sdch_owner.h" |
| 32 #include "net/url_request/url_request_context.h" | 33 #include "net/url_request/url_request_context.h" |
| 33 #include "net/url_request/url_request_context_builder.h" | 34 #include "net/url_request/url_request_context_builder.h" |
| 34 #include "net/url_request/url_request_interceptor.h" | 35 #include "net/url_request/url_request_interceptor.h" |
| 35 | 36 |
| 36 #if defined(DATA_REDUCTION_PROXY_SUPPORT) | 37 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 jcaller_ref.Reset(env, jcaller); | 153 jcaller_ref.Reset(env, jcaller); |
| 153 proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( | 154 proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( |
| 154 GetNetworkTaskRunner(), nullptr)); | 155 GetNetworkTaskRunner(), nullptr)); |
| 155 GetNetworkTaskRunner()->PostTask( | 156 GetNetworkTaskRunner()->PostTask( |
| 156 FROM_HERE, | 157 FROM_HERE, |
| 157 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, | 158 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, |
| 158 base::Unretained(this), Passed(&context_config_), | 159 base::Unretained(this), Passed(&context_config_), |
| 159 jcaller_ref)); | 160 jcaller_ref)); |
| 160 } | 161 } |
| 161 | 162 |
| 163 void CronetURLRequestContextAdapter::ConfigureNetworkQualityEstimator( | |
| 164 JNIEnv* env, jobject jcaller, jboolean use_local_host_requests, | |
| 165 jboolean use_smaller_responses) { | |
| 166 network_quality_estimator_->Configure(use_local_host_requests, | |
| 167 use_smaller_responses); | |
| 168 } | |
| 169 | |
| 170 void CronetURLRequestContextAdapter::ProvideRTTObservations( | |
| 171 JNIEnv* env, jobject jcaller, bool should) { | |
| 172 if (should) | |
| 173 network_quality_estimator_->AddRTTObserver(this); | |
| 174 else | |
| 175 network_quality_estimator_->RemoveRTTObserver(this); | |
| 176 } | |
| 177 | |
| 178 void CronetURLRequestContextAdapter::ProvideBandwidthObservations( | |
| 179 JNIEnv* env, jobject jcaller, bool should) { | |
| 180 if (should) | |
| 181 network_quality_estimator_->AddBandwidthObserver(this); | |
| 182 else | |
| 183 network_quality_estimator_->RemoveBandwidthObserver(this); | |
| 184 } | |
| 185 | |
| 162 void CronetURLRequestContextAdapter::InitializeOnNetworkThread( | 186 void CronetURLRequestContextAdapter::InitializeOnNetworkThread( |
| 163 scoped_ptr<URLRequestContextConfig> config, | 187 scoped_ptr<URLRequestContextConfig> config, |
| 164 const base::android::ScopedJavaGlobalRef<jobject>& | 188 const base::android::ScopedJavaGlobalRef<jobject>& |
| 165 jcronet_url_request_context) { | 189 jcronet_url_request_context) { |
| 166 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 190 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| 167 DCHECK(!is_context_initialized_); | 191 DCHECK(!is_context_initialized_); |
| 168 DCHECK(proxy_config_service_); | 192 DCHECK(proxy_config_service_); |
| 169 // TODO(mmenke): Add method to have the builder enable SPDY. | 193 // TODO(mmenke): Add method to have the builder enable SPDY. |
| 170 net::URLRequestContextBuilder context_builder; | 194 net::URLRequestContextBuilder context_builder; |
| 171 | 195 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 new net::HttpServerPropertiesManager(pref_service_.get(), | 241 new net::HttpServerPropertiesManager(pref_service_.get(), |
| 218 kHttpServerProperties, | 242 kHttpServerProperties, |
| 219 GetNetworkTaskRunner())); | 243 GetNetworkTaskRunner())); |
| 220 http_server_properties_manager->InitializeOnNetworkThread(); | 244 http_server_properties_manager->InitializeOnNetworkThread(); |
| 221 http_server_properties_manager_ = http_server_properties_manager.get(); | 245 http_server_properties_manager_ = http_server_properties_manager.get(); |
| 222 context_builder.SetHttpServerProperties( | 246 context_builder.SetHttpServerProperties( |
| 223 http_server_properties_manager.Pass()); | 247 http_server_properties_manager.Pass()); |
| 224 } | 248 } |
| 225 | 249 |
| 226 context_.reset(context_builder.Build()); | 250 context_.reset(context_builder.Build()); |
| 251 std::map<std::string, std::string> network_quality_estimator_params; | |
|
mef
2015/08/11 17:16:26
Should this happen only if ConfigureNetworkQuality
bengr
2015/08/25 23:43:34
Done.
| |
| 252 network_quality_estimator_.reset(new net::NetworkQualityEstimator( | |
| 253 network_quality_estimator_params)); | |
| 254 context_->set_network_quality_estimator(network_quality_estimator_.get()); | |
| 227 | 255 |
| 228 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | | 256 default_load_flags_ = net::LOAD_DO_NOT_SAVE_COOKIES | |
| 229 net::LOAD_DO_NOT_SEND_COOKIES; | 257 net::LOAD_DO_NOT_SEND_COOKIES; |
| 230 if (config->load_disable_cache) | 258 if (config->load_disable_cache) |
| 231 default_load_flags_ |= net::LOAD_DISABLE_CACHE; | 259 default_load_flags_ |= net::LOAD_DISABLE_CACHE; |
| 232 | 260 |
| 233 if (config->enable_sdch) { | 261 if (config->enable_sdch) { |
| 234 DCHECK(context_->sdch_manager()); | 262 DCHECK(context_->sdch_manager()); |
| 235 sdch_owner_.reset( | 263 sdch_owner_.reset( |
| 236 new net::SdchOwner(context_->sdch_manager(), context_.get())); | 264 new net::SdchOwner(context_->sdch_manager(), context_.get())); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 net::AlternativeService alternative_service( | 305 net::AlternativeService alternative_service( |
| 278 net::AlternateProtocol::QUIC, "", | 306 net::AlternateProtocol::QUIC, "", |
| 279 static_cast<uint16>(quic_hint.alternate_port)); | 307 static_cast<uint16>(quic_hint.alternate_port)); |
| 280 context_->http_server_properties()->SetAlternativeService( | 308 context_->http_server_properties()->SetAlternativeService( |
| 281 quic_hint_host_port_pair, alternative_service, 1.0f, | 309 quic_hint_host_port_pair, alternative_service, 1.0f, |
| 282 base::Time::Max()); | 310 base::Time::Max()); |
| 283 } | 311 } |
| 284 } | 312 } |
| 285 | 313 |
| 286 JNIEnv* env = base::android::AttachCurrentThread(); | 314 JNIEnv* env = base::android::AttachCurrentThread(); |
| 315 jcronet_url_request_context_.Reset(env, jcronet_url_request_context.obj()); | |
|
mef
2015/08/11 17:16:26
Does this add a reference to jcronet_url_request_c
bengr
2015/08/25 23:43:34
We didn't store the reference before. Is there a b
mef
2015/08/26 16:58:59
It seems that we do the same in CronetUrlRequestAd
| |
| 287 Java_CronetUrlRequestContext_initNetworkThread( | 316 Java_CronetUrlRequestContext_initNetworkThread( |
| 288 env, jcronet_url_request_context.obj()); | 317 env, jcronet_url_request_context.obj()); |
| 289 | 318 |
| 290 #if defined(DATA_REDUCTION_PROXY_SUPPORT) | 319 #if defined(DATA_REDUCTION_PROXY_SUPPORT) |
| 291 if (data_reduction_proxy_) | 320 if (data_reduction_proxy_) |
| 292 data_reduction_proxy_->Init(true, GetURLRequestContext()); | 321 data_reduction_proxy_->Init(true, GetURLRequestContext()); |
| 293 #endif | 322 #endif |
| 294 is_context_initialized_ = true; | 323 is_context_initialized_ = true; |
| 295 while (!tasks_waiting_for_context_.empty()) { | 324 while (!tasks_waiting_for_context_.empty()) { |
| 296 tasks_waiting_for_context_.front().Run(); | 325 tasks_waiting_for_context_.front().Run(); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 | 424 |
| 396 base::Thread* CronetURLRequestContextAdapter::GetFileThread() { | 425 base::Thread* CronetURLRequestContextAdapter::GetFileThread() { |
| 397 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 426 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| 398 if (!file_thread_) { | 427 if (!file_thread_) { |
| 399 file_thread_.reset(new base::Thread("Network File Thread")); | 428 file_thread_.reset(new base::Thread("Network File Thread")); |
| 400 file_thread_->Start(); | 429 file_thread_->Start(); |
| 401 } | 430 } |
| 402 return file_thread_.get(); | 431 return file_thread_.get(); |
| 403 } | 432 } |
| 404 | 433 |
| 434 void CronetURLRequestContextAdapter::OnRTTObservation( | |
| 435 int32_t value, const base::TimeTicks& timestamp, | |
| 436 net::NetworkQualityEstimator::ObservationSource source) { | |
| 437 | |
| 438 Java_CronetUrlRequestContext_onRTTObservation( | |
| 439 base::android::AttachCurrentThread(), jcronet_url_request_context_.obj(), | |
| 440 value, | |
| 441 (timestamp - base::TimeTicks::UnixEpoch()).InMilliseconds(), | |
| 442 static_cast<jint>(source)); | |
| 443 } | |
| 444 | |
| 445 void CronetURLRequestContextAdapter::OnBandwidthObservation( | |
| 446 int32_t value, const base::TimeTicks& timestamp, | |
| 447 net::NetworkQualityEstimator::ObservationSource source) { | |
| 448 Java_CronetUrlRequestContext_onBandwidthObservation( | |
| 449 base::android::AttachCurrentThread(), jcronet_url_request_context_.obj(), | |
| 450 value, | |
| 451 (timestamp - base::TimeTicks::UnixEpoch()).InMilliseconds(), | |
| 452 static_cast<jint>(source)); | |
| 453 } | |
| 454 | |
| 405 // Creates RequestContextAdater if config is valid URLRequestContextConfig, | 455 // Creates RequestContextAdater if config is valid URLRequestContextConfig, |
| 406 // returns 0 otherwise. | 456 // returns 0 otherwise. |
| 407 static jlong CreateRequestContextAdapter(JNIEnv* env, | 457 static jlong CreateRequestContextAdapter(JNIEnv* env, |
| 408 jclass jcaller, | 458 jclass jcaller, |
| 409 jstring jconfig) { | 459 jstring jconfig) { |
| 410 std::string config_string = | 460 std::string config_string = |
| 411 base::android::ConvertJavaStringToUTF8(env, jconfig); | 461 base::android::ConvertJavaStringToUTF8(env, jconfig); |
| 412 scoped_ptr<URLRequestContextConfig> context_config( | 462 scoped_ptr<URLRequestContextConfig> context_config( |
| 413 new URLRequestContextConfig()); | 463 new URLRequestContextConfig()); |
| 414 if (!context_config->LoadFromJSON(config_string)) | 464 if (!context_config->LoadFromJSON(config_string)) |
| 415 return 0; | 465 return 0; |
| 416 | 466 |
| 417 CronetURLRequestContextAdapter* context_adapter = | 467 CronetURLRequestContextAdapter* context_adapter = |
| 418 new CronetURLRequestContextAdapter(context_config.Pass()); | 468 new CronetURLRequestContextAdapter(context_config.Pass()); |
| 419 return reinterpret_cast<jlong>(context_adapter); | 469 return reinterpret_cast<jlong>(context_adapter); |
| 420 } | 470 } |
| 421 | 471 |
| 422 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { | 472 static jint SetMinLogLevel(JNIEnv* env, jclass jcaller, jint jlog_level) { |
| 423 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); | 473 jint old_log_level = static_cast<jint>(logging::GetMinLogLevel()); |
| 424 // MinLogLevel is global, shared by all URLRequestContexts. | 474 // MinLogLevel is global, shared by all URLRequestContexts. |
| 425 logging::SetMinLogLevel(static_cast<int>(jlog_level)); | 475 logging::SetMinLogLevel(static_cast<int>(jlog_level)); |
| 426 return old_log_level; | 476 return old_log_level; |
| 427 } | 477 } |
| 428 | 478 |
| 429 } // namespace cronet | 479 } // namespace cronet |
| OLD | NEW |