Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: components/cronet/android/cronet_url_request_context_adapter.cc

Issue 2223773003: Expose effective connection type to Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased, addressed comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "net/base/net_errors.h" 44 #include "net/base/net_errors.h"
45 #include "net/base/network_delegate_impl.h" 45 #include "net/base/network_delegate_impl.h"
46 #include "net/base/url_util.h" 46 #include "net/base/url_util.h"
47 #include "net/cert/caching_cert_verifier.h" 47 #include "net/cert/caching_cert_verifier.h"
48 #include "net/cert/cert_verifier.h" 48 #include "net/cert/cert_verifier.h"
49 #include "net/cookies/cookie_monster.h" 49 #include "net/cookies/cookie_monster.h"
50 #include "net/http/http_auth_handler_factory.h" 50 #include "net/http/http_auth_handler_factory.h"
51 #include "net/http/http_server_properties_manager.h" 51 #include "net/http/http_server_properties_manager.h"
52 #include "net/log/write_to_file_net_log_observer.h" 52 #include "net/log/write_to_file_net_log_observer.h"
53 #include "net/nqe/external_estimate_provider.h" 53 #include "net/nqe/external_estimate_provider.h"
54 #include "net/nqe/network_quality_estimator.h"
55 #include "net/proxy/proxy_config_service_android.h" 54 #include "net/proxy/proxy_config_service_android.h"
56 #include "net/proxy/proxy_service.h" 55 #include "net/proxy/proxy_service.h"
57 #include "net/sdch/sdch_owner.h" 56 #include "net/sdch/sdch_owner.h"
58 #include "net/ssl/channel_id_service.h" 57 #include "net/ssl/channel_id_service.h"
59 #include "net/url_request/url_request_context.h" 58 #include "net/url_request/url_request_context.h"
60 #include "net/url_request/url_request_context_builder.h" 59 #include "net/url_request/url_request_context_builder.h"
61 #include "net/url_request/url_request_interceptor.h" 60 #include "net/url_request/url_request_interceptor.h"
62 61
63 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 62 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
64 #include "components/cronet/android/cronet_data_reduction_proxy.h" 63 #include "components/cronet/android/cronet_data_reduction_proxy.h"
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() { 411 CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() {
413 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 412 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
414 413
415 if (http_server_properties_manager_) 414 if (http_server_properties_manager_)
416 http_server_properties_manager_->ShutdownOnPrefThread(); 415 http_server_properties_manager_->ShutdownOnPrefThread();
417 if (pref_service_) 416 if (pref_service_)
418 pref_service_->CommitPendingWrite(); 417 pref_service_->CommitPendingWrite();
419 if (network_quality_estimator_) { 418 if (network_quality_estimator_) {
420 network_quality_estimator_->RemoveRTTObserver(this); 419 network_quality_estimator_->RemoveRTTObserver(this);
421 network_quality_estimator_->RemoveThroughputObserver(this); 420 network_quality_estimator_->RemoveThroughputObserver(this);
421 network_quality_estimator_->RemoveEffectiveConnectionTypeObserver(this);
422 } 422 }
423 // Stop |write_to_file_observer_| if there is one. 423 // Stop |write_to_file_observer_| if there is one.
424 StopNetLogHelper(); 424 StopNetLogHelper();
425 } 425 }
426 426
427 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread( 427 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread(
428 JNIEnv* env, 428 JNIEnv* env,
429 const JavaParamRef<jobject>& jcaller) { 429 const JavaParamRef<jobject>& jcaller) {
430 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref; 430 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref;
431 jcaller_ref.Reset(env, jcaller); 431 jcaller_ref.Reset(env, jcaller);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 // Explicitly disable the persister for Cronet to avoid persistence of dynamic 593 // Explicitly disable the persister for Cronet to avoid persistence of dynamic
594 // HPKP. This is a safety measure ensuring that nobody enables the persistence 594 // HPKP. This is a safety measure ensuring that nobody enables the persistence
595 // of HPKP by specifying transport_security_persister_path in the future. 595 // of HPKP by specifying transport_security_persister_path in the future.
596 context_builder.set_transport_security_persister_path(base::FilePath()); 596 context_builder.set_transport_security_persister_path(base::FilePath());
597 597
598 // Disable net::CookieStore and net::ChannelIDService. 598 // Disable net::CookieStore and net::ChannelIDService.
599 context_builder.SetCookieAndChannelIdStores(nullptr, nullptr); 599 context_builder.SetCookieAndChannelIdStores(nullptr, nullptr);
600 600
601 if (config->enable_network_quality_estimator) { 601 if (config->enable_network_quality_estimator) {
602 DCHECK(!network_quality_estimator_); 602 DCHECK(!network_quality_estimator_);
603 std::map<std::string, std::string> variation_params;
604 // Configure network quality estimator: Specify the algorithm that should
605 // be used for computing the effective connection type. The algorithm
606 // is specified using the key-value pairs defined in
607 // //net/nqe/network_quality_estimator.cc.
608 // TODO(tbansal): Investigate a more robust way of configuring the network
609 // quality estimator.
610 variation_params["effective_connection_type_algorithm"] =
611 "TransportRTTOrDownstreamThroughput";
603 network_quality_estimator_.reset(new net::NetworkQualityEstimator( 612 network_quality_estimator_.reset(new net::NetworkQualityEstimator(
604 std::unique_ptr<net::ExternalEstimateProvider>(), 613 std::unique_ptr<net::ExternalEstimateProvider>(), variation_params,
605 std::map<std::string, std::string>(), false, false)); 614 false, false));
606 // Set the socket performance watcher factory so that network quality 615 // Set the socket performance watcher factory so that network quality
607 // estimator is notified of socket performance metrics from TCP and QUIC. 616 // estimator is notified of socket performance metrics from TCP and QUIC.
608 context_builder.set_socket_performance_watcher_factory( 617 context_builder.set_socket_performance_watcher_factory(
609 network_quality_estimator_->GetSocketPerformanceWatcherFactory()); 618 network_quality_estimator_->GetSocketPerformanceWatcherFactory());
619 network_quality_estimator_->AddEffectiveConnectionTypeObserver(this);
610 } 620 }
611 621
612 context_ = context_builder.Build(); 622 context_ = context_builder.Build();
613 if (network_quality_estimator_) 623 if (network_quality_estimator_)
614 context_->set_network_quality_estimator(network_quality_estimator_.get()); 624 context_->set_network_quality_estimator(network_quality_estimator_.get());
615 625
616 if (config->load_disable_cache) 626 if (config->load_disable_cache)
617 default_load_flags_ |= net::LOAD_DISABLE_CACHE; 627 default_load_flags_ |= net::LOAD_DISABLE_CACHE;
618 628
619 if (config->enable_sdch) { 629 if (config->enable_sdch) {
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 828
819 base::Thread* CronetURLRequestContextAdapter::GetFileThread() { 829 base::Thread* CronetURLRequestContextAdapter::GetFileThread() {
820 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 830 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
821 if (!file_thread_) { 831 if (!file_thread_) {
822 file_thread_.reset(new base::Thread("Network File Thread")); 832 file_thread_.reset(new base::Thread("Network File Thread"));
823 file_thread_->Start(); 833 file_thread_->Start();
824 } 834 }
825 return file_thread_.get(); 835 return file_thread_.get();
826 } 836 }
827 837
838 void CronetURLRequestContextAdapter::OnEffectiveConnectionTypeChanged(
839 net::EffectiveConnectionType effective_connection_type) {
840 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
841 Java_CronetUrlRequestContext_onEffectiveConnectionTypeChanged(
842 base::android::AttachCurrentThread(), jcronet_url_request_context_.obj(),
843 effective_connection_type);
844 }
845
828 void CronetURLRequestContextAdapter::OnRTTObservation( 846 void CronetURLRequestContextAdapter::OnRTTObservation(
829 int32_t rtt_ms, 847 int32_t rtt_ms,
830 const base::TimeTicks& timestamp, 848 const base::TimeTicks& timestamp,
831 net::NetworkQualityObservationSource source) { 849 net::NetworkQualityObservationSource source) {
832 Java_CronetUrlRequestContext_onRttObservation( 850 Java_CronetUrlRequestContext_onRttObservation(
833 base::android::AttachCurrentThread(), jcronet_url_request_context_.obj(), 851 base::android::AttachCurrentThread(), jcronet_url_request_context_.obj(),
834 rtt_ms, (timestamp - base::TimeTicks::UnixEpoch()).InMilliseconds(), 852 rtt_ms, (timestamp - base::TimeTicks::UnixEpoch()).InMilliseconds(),
835 source); 853 source);
836 } 854 }
837 855
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 JNIEnv* env, 999 JNIEnv* env,
982 const JavaParamRef<jclass>& jcaller) { 1000 const JavaParamRef<jclass>& jcaller) {
983 base::StatisticsRecorder::Initialize(); 1001 base::StatisticsRecorder::Initialize();
984 std::vector<uint8_t> data; 1002 std::vector<uint8_t> data;
985 if (!HistogramManager::GetInstance()->GetDeltas(&data)) 1003 if (!HistogramManager::GetInstance()->GetDeltas(&data))
986 return ScopedJavaLocalRef<jbyteArray>(); 1004 return ScopedJavaLocalRef<jbyteArray>();
987 return base::android::ToJavaByteArray(env, &data[0], data.size()); 1005 return base::android::ToJavaByteArray(env, &data[0], data.size());
988 } 1006 }
989 1007
990 } // namespace cronet 1008 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698