| 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 <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "base/memory/scoped_vector.h" | 30 #include "base/memory/scoped_vector.h" |
| 31 #include "base/message_loop/message_loop.h" | 31 #include "base/message_loop/message_loop.h" |
| 32 #include "base/metrics/histogram_macros.h" | 32 #include "base/metrics/histogram_macros.h" |
| 33 #include "base/metrics/statistics_recorder.h" | 33 #include "base/metrics/statistics_recorder.h" |
| 34 #include "base/single_thread_task_runner.h" | 34 #include "base/single_thread_task_runner.h" |
| 35 #include "base/threading/thread_task_runner_handle.h" | 35 #include "base/threading/thread_task_runner_handle.h" |
| 36 #include "base/time/time.h" | 36 #include "base/time/time.h" |
| 37 #include "base/values.h" | 37 #include "base/values.h" |
| 38 #include "components/cronet/android/cert/cert_verifier_cache_serializer.h" | 38 #include "components/cronet/android/cert/cert_verifier_cache_serializer.h" |
| 39 #include "components/cronet/android/cert/proto/cert_verification.pb.h" | 39 #include "components/cronet/android/cert/proto/cert_verification.pb.h" |
| 40 #include "components/cronet/android/cronet_library_loader.h" |
| 40 #include "components/cronet/histogram_manager.h" | 41 #include "components/cronet/histogram_manager.h" |
| 41 #include "components/cronet/url_request_context_config.h" | 42 #include "components/cronet/url_request_context_config.h" |
| 42 #include "components/prefs/pref_change_registrar.h" | 43 #include "components/prefs/pref_change_registrar.h" |
| 43 #include "components/prefs/pref_filter.h" | 44 #include "components/prefs/pref_filter.h" |
| 44 #include "components/prefs/pref_registry.h" | 45 #include "components/prefs/pref_registry.h" |
| 45 #include "components/prefs/pref_registry_simple.h" | 46 #include "components/prefs/pref_registry_simple.h" |
| 46 #include "components/prefs/pref_service.h" | 47 #include "components/prefs/pref_service.h" |
| 47 #include "components/prefs/pref_service_factory.h" | 48 #include "components/prefs/pref_service_factory.h" |
| 48 #include "jni/CronetUrlRequestContext_jni.h" | 49 #include "jni/CronetUrlRequestContext_jni.h" |
| 49 #include "net/base/load_flags.h" | 50 #include "net/base/load_flags.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 77 const int kNumNetLogEventFiles = 10; | 78 const int kNumNetLogEventFiles = 10; |
| 78 | 79 |
| 79 // This class wraps a NetLog that also contains network change events. | 80 // This class wraps a NetLog that also contains network change events. |
| 80 class NetLogWithNetworkChangeEvents { | 81 class NetLogWithNetworkChangeEvents { |
| 81 public: | 82 public: |
| 82 NetLogWithNetworkChangeEvents() {} | 83 NetLogWithNetworkChangeEvents() {} |
| 83 | 84 |
| 84 net::NetLog* net_log() { return &net_log_; } | 85 net::NetLog* net_log() { return &net_log_; } |
| 85 // This function registers with the NetworkChangeNotifier and so must be | 86 // This function registers with the NetworkChangeNotifier and so must be |
| 86 // called *after* the NetworkChangeNotifier is created. Should only be | 87 // called *after* the NetworkChangeNotifier is created. Should only be |
| 87 // called on the UI thread as it is not thread-safe and the UI thread is | 88 // called on the init thread as it is not thread-safe and the init thread is |
| 88 // the thread the NetworkChangeNotifier is created on. This function is | 89 // the thread the NetworkChangeNotifier is created on. This function is |
| 89 // not thread-safe because accesses to |net_change_logger_| are not atomic. | 90 // not thread-safe because accesses to |net_change_logger_| are not atomic. |
| 90 // There might be multiple CronetEngines each with a network thread so | 91 // There might be multiple CronetEngines each with a network thread so |
| 91 // so the UI thread is used. |g_net_log_| also outlives the network threads | 92 // so the init thread is used. |g_net_log_| also outlives the network threads |
| 92 // so it would be unsafe to receive callbacks on the network threads without | 93 // so it would be unsafe to receive callbacks on the network threads without |
| 93 // a complicated thread-safe reference-counting system to control callback | 94 // a complicated thread-safe reference-counting system to control callback |
| 94 // registration. | 95 // registration. |
| 95 void EnsureInitializedOnMainThread() { | 96 void EnsureInitializedOnInitThread() { |
| 96 DCHECK(base::MessageLoopForUI::IsCurrent()); | 97 DCHECK(cronet::OnInitThread()); |
| 97 if (net_change_logger_) | 98 if (net_change_logger_) |
| 98 return; | 99 return; |
| 99 net_change_logger_.reset(new net::LoggingNetworkChangeObserver(&net_log_)); | 100 net_change_logger_.reset(new net::LoggingNetworkChangeObserver(&net_log_)); |
| 100 } | 101 } |
| 101 | 102 |
| 102 private: | 103 private: |
| 103 net::NetLog net_log_; | 104 net::NetLog net_log_; |
| 104 // LoggingNetworkChangeObserver logs network change events to a NetLog. | 105 // LoggingNetworkChangeObserver logs network change events to a NetLog. |
| 105 // This class bundles one LoggingNetworkChangeObserver with one NetLog, | 106 // This class bundles one LoggingNetworkChangeObserver with one NetLog, |
| 106 // so network change event are logged just once in the NetLog. | 107 // so network change event are logged just once in the NetLog. |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 network_quality_estimator_->RemoveRTTObserver(this); | 498 network_quality_estimator_->RemoveRTTObserver(this); |
| 498 network_quality_estimator_->RemoveThroughputObserver(this); | 499 network_quality_estimator_->RemoveThroughputObserver(this); |
| 499 network_quality_estimator_->RemoveEffectiveConnectionTypeObserver(this); | 500 network_quality_estimator_->RemoveEffectiveConnectionTypeObserver(this); |
| 500 network_quality_estimator_->RemoveRTTAndThroughputEstimatesObserver(this); | 501 network_quality_estimator_->RemoveRTTAndThroughputEstimatesObserver(this); |
| 501 } | 502 } |
| 502 | 503 |
| 503 // Stop NetLog observer if there is one. | 504 // Stop NetLog observer if there is one. |
| 504 StopNetLogOnNetworkThread(); | 505 StopNetLogOnNetworkThread(); |
| 505 } | 506 } |
| 506 | 507 |
| 507 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread( | 508 void CronetURLRequestContextAdapter::InitRequestContextOnInitThread( |
| 508 JNIEnv* env, | 509 JNIEnv* env, |
| 509 const JavaParamRef<jobject>& jcaller) { | 510 const JavaParamRef<jobject>& jcaller) { |
| 510 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref; | 511 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref; |
| 511 jcaller_ref.Reset(env, jcaller); | 512 jcaller_ref.Reset(env, jcaller); |
| 512 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( | 513 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( |
| 513 GetNetworkTaskRunner(), nullptr /* Ignored on Android */); | 514 GetNetworkTaskRunner(), nullptr /* Ignored on Android */); |
| 514 net::ProxyConfigServiceAndroid* android_proxy_config_service = | 515 net::ProxyConfigServiceAndroid* android_proxy_config_service = |
| 515 static_cast<net::ProxyConfigServiceAndroid*>(proxy_config_service_.get()); | 516 static_cast<net::ProxyConfigServiceAndroid*>(proxy_config_service_.get()); |
| 516 // If a PAC URL is present, ignore it and use the address and port of | 517 // If a PAC URL is present, ignore it and use the address and port of |
| 517 // Android system's local HTTP proxy server. See: crbug.com/432539. | 518 // Android system's local HTTP proxy server. See: crbug.com/432539. |
| 518 // TODO(csharrison) Architect the wrapper better so we don't need to cast for | 519 // TODO(csharrison) Architect the wrapper better so we don't need to cast for |
| 519 // android ProxyConfigServices. | 520 // android ProxyConfigServices. |
| 520 android_proxy_config_service->set_exclude_pac_url(true); | 521 android_proxy_config_service->set_exclude_pac_url(true); |
| 521 g_net_log.Get().EnsureInitializedOnMainThread(); | 522 g_net_log.Get().EnsureInitializedOnInitThread(); |
| 522 GetNetworkTaskRunner()->PostTask( | 523 GetNetworkTaskRunner()->PostTask( |
| 523 FROM_HERE, | 524 FROM_HERE, |
| 524 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, | 525 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, |
| 525 base::Unretained(this), base::Passed(&context_config_), | 526 base::Unretained(this), base::Passed(&context_config_), |
| 526 jcaller_ref)); | 527 jcaller_ref)); |
| 527 } | 528 } |
| 528 | 529 |
| 529 void CronetURLRequestContextAdapter:: | 530 void CronetURLRequestContextAdapter:: |
| 530 ConfigureNetworkQualityEstimatorOnNetworkThreadForTesting( | 531 ConfigureNetworkQualityEstimatorOnNetworkThreadForTesting( |
| 531 bool use_local_host_requests, | 532 bool use_local_host_requests, |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 JNIEnv* env, | 1174 JNIEnv* env, |
| 1174 const JavaParamRef<jclass>& jcaller) { | 1175 const JavaParamRef<jclass>& jcaller) { |
| 1175 DCHECK(base::StatisticsRecorder::IsActive()); | 1176 DCHECK(base::StatisticsRecorder::IsActive()); |
| 1176 std::vector<uint8_t> data; | 1177 std::vector<uint8_t> data; |
| 1177 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 1178 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
| 1178 return ScopedJavaLocalRef<jbyteArray>(); | 1179 return ScopedJavaLocalRef<jbyteArray>(); |
| 1179 return base::android::ToJavaByteArray(env, &data[0], data.size()); | 1180 return base::android::ToJavaByteArray(env, &data[0], data.size()); |
| 1180 } | 1181 } |
| 1181 | 1182 |
| 1182 } // namespace cronet | 1183 } // namespace cronet |
| OLD | NEW |