| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "components/prefs/pref_service_factory.h" | 48 #include "components/prefs/pref_service_factory.h" |
| 49 #include "jni/CronetUrlRequestContext_jni.h" | 49 #include "jni/CronetUrlRequestContext_jni.h" |
| 50 #include "net/base/load_flags.h" | 50 #include "net/base/load_flags.h" |
| 51 #include "net/base/logging_network_change_observer.h" | 51 #include "net/base/logging_network_change_observer.h" |
| 52 #include "net/base/net_errors.h" | 52 #include "net/base/net_errors.h" |
| 53 #include "net/base/network_delegate_impl.h" | 53 #include "net/base/network_delegate_impl.h" |
| 54 #include "net/base/url_util.h" | 54 #include "net/base/url_util.h" |
| 55 #include "net/cert/caching_cert_verifier.h" | 55 #include "net/cert/caching_cert_verifier.h" |
| 56 #include "net/cert/cert_verifier.h" | 56 #include "net/cert/cert_verifier.h" |
| 57 #include "net/cookies/cookie_monster.h" | 57 #include "net/cookies/cookie_monster.h" |
| 58 #include "net/dns/host_cache.h" |
| 58 #include "net/http/http_auth_handler_factory.h" | 59 #include "net/http/http_auth_handler_factory.h" |
| 59 #include "net/http/http_server_properties_manager.h" | 60 #include "net/http/http_server_properties_manager.h" |
| 60 #include "net/log/file_net_log_observer.h" | 61 #include "net/log/file_net_log_observer.h" |
| 61 #include "net/log/net_log_util.h" | 62 #include "net/log/net_log_util.h" |
| 62 #include "net/nqe/external_estimate_provider.h" | 63 #include "net/nqe/external_estimate_provider.h" |
| 63 #include "net/nqe/network_qualities_prefs_manager.h" | 64 #include "net/nqe/network_qualities_prefs_manager.h" |
| 64 #include "net/proxy/proxy_config_service_android.h" | 65 #include "net/proxy/proxy_config_service_android.h" |
| 65 #include "net/proxy/proxy_service.h" | 66 #include "net/proxy/proxy_service.h" |
| 66 #include "net/sdch/sdch_owner.h" | 67 #include "net/sdch/sdch_owner.h" |
| 67 #include "net/ssl/channel_id_service.h" | 68 #include "net/ssl/channel_id_service.h" |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 void CronetURLRequestContextAdapter::ProvideThroughputObservations( | 593 void CronetURLRequestContextAdapter::ProvideThroughputObservations( |
| 593 JNIEnv* env, | 594 JNIEnv* env, |
| 594 const JavaParamRef<jobject>& jcaller, | 595 const JavaParamRef<jobject>& jcaller, |
| 595 bool should) { | 596 bool should) { |
| 596 PostTaskToNetworkThread( | 597 PostTaskToNetworkThread( |
| 597 FROM_HERE, base::Bind(&CronetURLRequestContextAdapter:: | 598 FROM_HERE, base::Bind(&CronetURLRequestContextAdapter:: |
| 598 ProvideThroughputObservationsOnNetworkThread, | 599 ProvideThroughputObservationsOnNetworkThread, |
| 599 base::Unretained(this), should)); | 600 base::Unretained(this), should)); |
| 600 } | 601 } |
| 601 | 602 |
| 603 void CronetURLRequestContextAdapter::PutHostCacheOnNetworkThread( |
| 604 std::string hostname, |
| 605 net::AddressList address_list, |
| 606 base::TimeDelta ttl) { |
| 607 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| 608 net::HostCache::Key key(hostname, net::ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 609 net::HostCache::Entry entry(net::OK, address_list, ttl); |
| 610 context_->host_resolver()->GetHostCache()->Set(key, entry, |
| 611 base::TimeTicks::Now(), ttl); |
| 612 } |
| 613 |
| 614 void CronetURLRequestContextAdapter::PutHostCache( |
| 615 JNIEnv* env, |
| 616 const base::android::JavaParamRef<jobject>& jcaller, |
| 617 const base::android::JavaParamRef<jstring>& jhostname, |
| 618 const base::android::JavaParamRef<jobjectArray>& jaddresses, |
| 619 jint jseconds_to_live) { |
| 620 size_t address_count = env->GetArrayLength(jaddresses); |
| 621 net::AddressList address_list; |
| 622 for (size_t i = 0; i < address_count; ++i) { |
| 623 ScopedJavaLocalRef<jbyteArray> bytes_array( |
| 624 env, |
| 625 static_cast<jbyteArray>(env->GetObjectArrayElement(jaddresses, i))); |
| 626 size_t address_size = env->GetArrayLength(bytes_array.obj()); |
| 627 if (address_size != net::IPAddress::kIPv4AddressSize && |
| 628 address_size != net::IPAddress::kIPv6AddressSize) { |
| 629 LOG(ERROR) << "Unsupported IP address size: " << address_size; |
| 630 return; |
| 631 } |
| 632 jbyte* bytes = env->GetByteArrayElements(bytes_array.obj(), nullptr); |
| 633 address_list.push_back(net::IPEndPoint( |
| 634 net::IPAddress(reinterpret_cast<uint8_t*>(bytes), address_size), 0)); |
| 635 env->ReleaseByteArrayElements(bytes_array.obj(), bytes, JNI_ABORT); |
| 636 } |
| 637 PostTaskToNetworkThread( |
| 638 FROM_HERE, |
| 639 base::Bind(&CronetURLRequestContextAdapter::PutHostCacheOnNetworkThread, |
| 640 base::Unretained(this), |
| 641 base::android::ConvertJavaStringToUTF8(env, jhostname), |
| 642 address_list, base::TimeDelta::FromSeconds(jseconds_to_live))); |
| 643 } |
| 644 |
| 602 void CronetURLRequestContextAdapter::InitializeOnNetworkThread( | 645 void CronetURLRequestContextAdapter::InitializeOnNetworkThread( |
| 603 std::unique_ptr<URLRequestContextConfig> config, | 646 std::unique_ptr<URLRequestContextConfig> config, |
| 604 const base::android::ScopedJavaGlobalRef<jobject>& | 647 const base::android::ScopedJavaGlobalRef<jobject>& |
| 605 jcronet_url_request_context) { | 648 jcronet_url_request_context) { |
| 606 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); | 649 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| 607 DCHECK(!is_context_initialized_); | 650 DCHECK(!is_context_initialized_); |
| 608 DCHECK(proxy_config_service_); | 651 DCHECK(proxy_config_service_); |
| 609 | 652 |
| 610 // TODO(mmenke): Add method to have the builder enable SPDY. | 653 // TODO(mmenke): Add method to have the builder enable SPDY. |
| 611 net::URLRequestContextBuilder context_builder; | 654 net::URLRequestContextBuilder context_builder; |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 JNIEnv* env, | 1217 JNIEnv* env, |
| 1175 const JavaParamRef<jclass>& jcaller) { | 1218 const JavaParamRef<jclass>& jcaller) { |
| 1176 DCHECK(base::StatisticsRecorder::IsActive()); | 1219 DCHECK(base::StatisticsRecorder::IsActive()); |
| 1177 std::vector<uint8_t> data; | 1220 std::vector<uint8_t> data; |
| 1178 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 1221 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
| 1179 return ScopedJavaLocalRef<jbyteArray>(); | 1222 return ScopedJavaLocalRef<jbyteArray>(); |
| 1180 return base::android::ToJavaByteArray(env, &data[0], data.size()); | 1223 return base::android::ToJavaByteArray(env, &data[0], data.size()); |
| 1181 } | 1224 } |
| 1182 | 1225 |
| 1183 } // namespace cronet | 1226 } // namespace cronet |
| OLD | NEW |