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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 const int kNumNetLogEventFiles = 10; | 82 const int kNumNetLogEventFiles = 10; |
82 | 83 |
83 // This class wraps a NetLog that also contains network change events. | 84 // This class wraps a NetLog that also contains network change events. |
84 class NetLogWithNetworkChangeEvents { | 85 class NetLogWithNetworkChangeEvents { |
85 public: | 86 public: |
86 NetLogWithNetworkChangeEvents() {} | 87 NetLogWithNetworkChangeEvents() {} |
87 | 88 |
88 net::NetLog* net_log() { return &net_log_; } | 89 net::NetLog* net_log() { return &net_log_; } |
89 // This function registers with the NetworkChangeNotifier and so must be | 90 // This function registers with the NetworkChangeNotifier and so must be |
90 // called *after* the NetworkChangeNotifier is created. Should only be | 91 // called *after* the NetworkChangeNotifier is created. Should only be |
91 // called on the UI thread as it is not thread-safe and the UI thread is | 92 // called on the init thread as it is not thread-safe and the init thread is |
92 // the thread the NetworkChangeNotifier is created on. This function is | 93 // the thread the NetworkChangeNotifier is created on. This function is |
93 // not thread-safe because accesses to |net_change_logger_| are not atomic. | 94 // not thread-safe because accesses to |net_change_logger_| are not atomic. |
94 // There might be multiple CronetEngines each with a network thread so | 95 // There might be multiple CronetEngines each with a network thread so |
95 // so the UI thread is used. |g_net_log_| also outlives the network threads | 96 // so the init thread is used. |g_net_log_| also outlives the network threads |
96 // so it would be unsafe to receive callbacks on the network threads without | 97 // so it would be unsafe to receive callbacks on the network threads without |
97 // a complicated thread-safe reference-counting system to control callback | 98 // a complicated thread-safe reference-counting system to control callback |
98 // registration. | 99 // registration. |
99 void EnsureInitializedOnMainThread() { | 100 void EnsureInitializedOnInitThread() { |
100 DCHECK(base::MessageLoopForUI::IsCurrent()); | 101 DCHECK(cronet::OnInitThread()); |
101 if (net_change_logger_) | 102 if (net_change_logger_) |
102 return; | 103 return; |
103 net_change_logger_.reset(new net::LoggingNetworkChangeObserver(&net_log_)); | 104 net_change_logger_.reset(new net::LoggingNetworkChangeObserver(&net_log_)); |
104 } | 105 } |
105 | 106 |
106 private: | 107 private: |
107 net::NetLog net_log_; | 108 net::NetLog net_log_; |
108 // LoggingNetworkChangeObserver logs network change events to a NetLog. | 109 // LoggingNetworkChangeObserver logs network change events to a NetLog. |
109 // This class bundles one LoggingNetworkChangeObserver with one NetLog, | 110 // This class bundles one LoggingNetworkChangeObserver with one NetLog, |
110 // so network change event are logged just once in the NetLog. | 111 // so network change event are logged just once in the NetLog. |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 network_quality_estimator_->RemoveRTTObserver(this); | 502 network_quality_estimator_->RemoveRTTObserver(this); |
502 network_quality_estimator_->RemoveThroughputObserver(this); | 503 network_quality_estimator_->RemoveThroughputObserver(this); |
503 network_quality_estimator_->RemoveEffectiveConnectionTypeObserver(this); | 504 network_quality_estimator_->RemoveEffectiveConnectionTypeObserver(this); |
504 network_quality_estimator_->RemoveRTTAndThroughputEstimatesObserver(this); | 505 network_quality_estimator_->RemoveRTTAndThroughputEstimatesObserver(this); |
505 } | 506 } |
506 | 507 |
507 // Stop NetLog observer if there is one. | 508 // Stop NetLog observer if there is one. |
508 StopNetLogOnNetworkThread(); | 509 StopNetLogOnNetworkThread(); |
509 } | 510 } |
510 | 511 |
511 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread( | 512 void CronetURLRequestContextAdapter::InitRequestContextOnInitThread( |
512 JNIEnv* env, | 513 JNIEnv* env, |
513 const JavaParamRef<jobject>& jcaller) { | 514 const JavaParamRef<jobject>& jcaller) { |
514 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref; | 515 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref; |
515 jcaller_ref.Reset(env, jcaller); | 516 jcaller_ref.Reset(env, jcaller); |
516 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( | 517 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( |
517 GetNetworkTaskRunner(), nullptr /* Ignored on Android */); | 518 GetNetworkTaskRunner(), nullptr /* Ignored on Android */); |
518 net::ProxyConfigServiceAndroid* android_proxy_config_service = | 519 net::ProxyConfigServiceAndroid* android_proxy_config_service = |
519 static_cast<net::ProxyConfigServiceAndroid*>(proxy_config_service_.get()); | 520 static_cast<net::ProxyConfigServiceAndroid*>(proxy_config_service_.get()); |
520 // If a PAC URL is present, ignore it and use the address and port of | 521 // If a PAC URL is present, ignore it and use the address and port of |
521 // Android system's local HTTP proxy server. See: crbug.com/432539. | 522 // Android system's local HTTP proxy server. See: crbug.com/432539. |
522 // TODO(csharrison) Architect the wrapper better so we don't need to cast for | 523 // TODO(csharrison) Architect the wrapper better so we don't need to cast for |
523 // android ProxyConfigServices. | 524 // android ProxyConfigServices. |
524 android_proxy_config_service->set_exclude_pac_url(true); | 525 android_proxy_config_service->set_exclude_pac_url(true); |
525 g_net_log.Get().EnsureInitializedOnMainThread(); | 526 g_net_log.Get().EnsureInitializedOnInitThread(); |
526 GetNetworkTaskRunner()->PostTask( | 527 GetNetworkTaskRunner()->PostTask( |
527 FROM_HERE, | 528 FROM_HERE, |
528 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, | 529 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, |
529 base::Unretained(this), base::Passed(&context_config_), | 530 base::Unretained(this), base::Passed(&context_config_), |
530 jcaller_ref)); | 531 jcaller_ref)); |
531 } | 532 } |
532 | 533 |
533 void CronetURLRequestContextAdapter:: | 534 void CronetURLRequestContextAdapter:: |
534 ConfigureNetworkQualityEstimatorOnNetworkThreadForTesting( | 535 ConfigureNetworkQualityEstimatorOnNetworkThreadForTesting( |
535 bool use_local_host_requests, | 536 bool use_local_host_requests, |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 JNIEnv* env, | 1209 JNIEnv* env, |
1209 const JavaParamRef<jclass>& jcaller) { | 1210 const JavaParamRef<jclass>& jcaller) { |
1210 base::StatisticsRecorder::Initialize(); | 1211 base::StatisticsRecorder::Initialize(); |
1211 std::vector<uint8_t> data; | 1212 std::vector<uint8_t> data; |
1212 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 1213 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
1213 return ScopedJavaLocalRef<jbyteArray>(); | 1214 return ScopedJavaLocalRef<jbyteArray>(); |
1214 return base::android::ToJavaByteArray(env, &data[0], data.size()); | 1215 return base::android::ToJavaByteArray(env, &data[0], data.size()); |
1215 } | 1216 } |
1216 | 1217 |
1217 } // namespace cronet | 1218 } // namespace cronet |
OLD | NEW |