Chromium Code Reviews| Index: components/cronet/android/cronet_url_request_context_adapter.cc |
| diff --git a/components/cronet/android/cronet_url_request_context_adapter.cc b/components/cronet/android/cronet_url_request_context_adapter.cc |
| index 6621e091c59ab8197d61394093a5f4e9dca2cdff..8fff2232abe535fb711f96f069966025f9b21328 100644 |
| --- a/components/cronet/android/cronet_url_request_context_adapter.cc |
| +++ b/components/cronet/android/cronet_url_request_context_adapter.cc |
| @@ -24,6 +24,7 @@ |
| #include "net/base/load_flags.h" |
| #include "net/base/net_errors.h" |
| #include "net/base/network_delegate_impl.h" |
| +#include "net/base/network_quality_estimator.h" |
| #include "net/http/http_auth_handler_factory.h" |
| #include "net/http/http_server_properties_manager.h" |
| #include "net/log/write_to_file_net_log_observer.h" |
| @@ -139,6 +140,8 @@ CronetURLRequestContextAdapter::~CronetURLRequestContextAdapter() { |
| http_server_properties_manager_->ShutdownOnPrefThread(); |
| if (pref_service_) |
| pref_service_->CommitPendingWrite(); |
| + network_quality_estimator_->RemoveRTTObserver(this); |
|
mef
2015/08/26 16:58:59
what if network_quality_estimator_ is null?
bengr
2015/08/27 16:44:34
Uggh. I wrote all of this when that wasn't possibl
|
| + network_quality_estimator_->RemoveThroughputObserver(this); |
| StopNetLogOnNetworkThread(); |
| } |
| @@ -156,6 +159,66 @@ void CronetURLRequestContextAdapter::InitRequestContextOnMainThread( |
| jcaller_ref)); |
| } |
| +void CronetURLRequestContextAdapter:: |
| + EnableNetworkQualityEstimatorOnNetworkThread(bool use_local_host_requests, |
| + bool use_smaller_responses) { |
| + DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| + scoped_ptr<net::ExternalEstimateProvider> external_estimate_provider; |
|
mef
2015/08/26 16:58:59
uninitialized?
mef
2015/08/26 17:28:40
include header for net::ExternalEstimateProvider?
bengr
2015/08/27 16:44:34
Done.
bengr
2015/08/27 16:44:34
Done.
|
| + std::map<std::string, std::string> network_quality_estimator_params; |
|
mef
2015/08/26 16:58:59
#include <map>
bengr
2015/08/27 16:44:34
Done.
|
| + network_quality_estimator_.reset(new net::NetworkQualityEstimator( |
| + external_estimate_provider.Pass(), network_quality_estimator_params)); |
| + context_->set_network_quality_estimator(network_quality_estimator_.get()); |
| + network_quality_estimator_->Configure(use_local_host_requests, |
| + use_smaller_responses); |
| +} |
| + |
| +void CronetURLRequestContextAdapter::EnableNetworkQualityEstimator( |
| + JNIEnv* env, |
| + jobject jcaller, |
| + jboolean use_local_host_requests, |
| + jboolean use_smaller_responses) { |
| + PostTaskToNetworkThread( |
| + FROM_HERE, base::Bind(&CronetURLRequestContextAdapter:: |
| + EnableNetworkQualityEstimatorOnNetworkThread, |
| + base::Unretained(this), use_local_host_requests, |
| + use_smaller_responses)); |
| +} |
| + |
| +void CronetURLRequestContextAdapter::ProvideRTTObservationsOnNetworkThread( |
| + bool should) { |
| + if (should) |
| + network_quality_estimator_->AddRTTObserver(this); |
|
mef
2015/08/26 16:58:59
is there any danger in doing it multiple times?
bengr
2015/08/27 16:44:34
Nope. No issue. The observer will only be added on
|
| + else |
| + network_quality_estimator_->RemoveRTTObserver(this); |
| +} |
| + |
| +void CronetURLRequestContextAdapter::ProvideRTTObservations(JNIEnv* env, |
| + jobject jcaller, |
| + bool should) { |
| + PostTaskToNetworkThread(FROM_HERE, |
| + base::Bind(&CronetURLRequestContextAdapter:: |
| + ProvideRTTObservationsOnNetworkThread, |
| + base::Unretained(this), should)); |
| +} |
| + |
| +void CronetURLRequestContextAdapter:: |
| + ProvideThroughputObservationsOnNetworkThread(bool should) { |
| + if (should) |
| + network_quality_estimator_->AddThroughputObserver(this); |
| + else |
| + network_quality_estimator_->RemoveThroughputObserver(this); |
| +} |
| + |
| +void CronetURLRequestContextAdapter::ProvideThroughputObservations( |
| + JNIEnv* env, |
| + jobject jcaller, |
| + bool should) { |
| + PostTaskToNetworkThread( |
| + FROM_HERE, base::Bind(&CronetURLRequestContextAdapter:: |
| + ProvideThroughputObservationsOnNetworkThread, |
| + base::Unretained(this), should)); |
| +} |
| + |
| void CronetURLRequestContextAdapter::InitializeOnNetworkThread( |
| scoped_ptr<URLRequestContextConfig> config, |
| const base::android::ScopedJavaGlobalRef<jobject>& |
| @@ -281,6 +344,7 @@ void CronetURLRequestContextAdapter::InitializeOnNetworkThread( |
| } |
| JNIEnv* env = base::android::AttachCurrentThread(); |
| + jcronet_url_request_context_.Reset(env, jcronet_url_request_context.obj()); |
| Java_CronetUrlRequestContext_initNetworkThread( |
| env, jcronet_url_request_context.obj()); |
| @@ -399,6 +463,27 @@ base::Thread* CronetURLRequestContextAdapter::GetFileThread() { |
| return file_thread_.get(); |
| } |
| +void CronetURLRequestContextAdapter::OnRTTObservation( |
| + int32_t rtt_ms, |
| + const base::TimeTicks& timestamp, |
| + net::NetworkQualityEstimator::ObservationSource source) { |
| + Java_CronetUrlRequestContext_onRTTObservation( |
| + base::android::AttachCurrentThread(), jcronet_url_request_context_.obj(), |
| + rtt_ms, (timestamp - base::TimeTicks::UnixEpoch()).InMilliseconds(), |
| + static_cast<jint>(source)); |
| +} |
| + |
| +void CronetURLRequestContextAdapter::OnThroughputObservation( |
| + int32_t throughput_kbps, |
| + const base::TimeTicks& timestamp, |
| + net::NetworkQualityEstimator::ObservationSource source) { |
| + Java_CronetUrlRequestContext_onThroughputObservation( |
| + base::android::AttachCurrentThread(), jcronet_url_request_context_.obj(), |
| + throughput_kbps, |
| + (timestamp - base::TimeTicks::UnixEpoch()).InMilliseconds(), |
| + static_cast<jint>(source)); |
| +} |
| + |
| // Creates RequestContextAdater if config is valid URLRequestContextConfig, |
| // returns 0 otherwise. |
| static jlong CreateRequestContextAdapter(JNIEnv* env, |