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

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

Issue 2751113004: Revert of [Cronet] Write effective experimental options to NetLog (Closed)
Patch Set: Created 3 years, 9 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "net/base/net_errors.h" 51 #include "net/base/net_errors.h"
52 #include "net/base/network_delegate_impl.h" 52 #include "net/base/network_delegate_impl.h"
53 #include "net/base/url_util.h" 53 #include "net/base/url_util.h"
54 #include "net/cert/caching_cert_verifier.h" 54 #include "net/cert/caching_cert_verifier.h"
55 #include "net/cert/cert_verifier.h" 55 #include "net/cert/cert_verifier.h"
56 #include "net/cookies/cookie_monster.h" 56 #include "net/cookies/cookie_monster.h"
57 #include "net/http/http_auth_handler_factory.h" 57 #include "net/http/http_auth_handler_factory.h"
58 #include "net/http/http_server_properties_manager.h" 58 #include "net/http/http_server_properties_manager.h"
59 #include "net/log/file_net_log_observer.h" 59 #include "net/log/file_net_log_observer.h"
60 #include "net/log/net_log_util.h" 60 #include "net/log/net_log_util.h"
61 #include "net/log/write_to_file_net_log_observer.h"
61 #include "net/nqe/external_estimate_provider.h" 62 #include "net/nqe/external_estimate_provider.h"
62 #include "net/nqe/network_qualities_prefs_manager.h" 63 #include "net/nqe/network_qualities_prefs_manager.h"
63 #include "net/proxy/proxy_config_service_android.h" 64 #include "net/proxy/proxy_config_service_android.h"
64 #include "net/proxy/proxy_service.h" 65 #include "net/proxy/proxy_service.h"
65 #include "net/sdch/sdch_owner.h" 66 #include "net/sdch/sdch_owner.h"
66 #include "net/ssl/channel_id_service.h" 67 #include "net/ssl/channel_id_service.h"
67 #include "net/url_request/url_request_context.h" 68 #include "net/url_request/url_request_context.h"
68 #include "net/url_request/url_request_context_builder.h" 69 #include "net/url_request/url_request_context_builder.h"
69 #include "net/url_request/url_request_interceptor.h" 70 #include "net/url_request/url_request_interceptor.h"
70 71
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 if (pref_service_) 499 if (pref_service_)
499 pref_service_->CommitPendingWrite(); 500 pref_service_->CommitPendingWrite();
500 if (network_quality_estimator_) { 501 if (network_quality_estimator_) {
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 StopNetLogHelper();
509 } 510 }
510 511
511 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread( 512 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread(
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 =
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 base::Unretained(this), should)); 603 base::Unretained(this), should));
603 } 604 }
604 605
605 void CronetURLRequestContextAdapter::InitializeOnNetworkThread( 606 void CronetURLRequestContextAdapter::InitializeOnNetworkThread(
606 std::unique_ptr<URLRequestContextConfig> config, 607 std::unique_ptr<URLRequestContextConfig> config,
607 const base::android::ScopedJavaGlobalRef<jobject>& 608 const base::android::ScopedJavaGlobalRef<jobject>&
608 jcronet_url_request_context) { 609 jcronet_url_request_context) {
609 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 610 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
610 DCHECK(!is_context_initialized_); 611 DCHECK(!is_context_initialized_);
611 DCHECK(proxy_config_service_); 612 DCHECK(proxy_config_service_);
612
613 // TODO(mmenke): Add method to have the builder enable SPDY. 613 // TODO(mmenke): Add method to have the builder enable SPDY.
614 net::URLRequestContextBuilder context_builder; 614 net::URLRequestContextBuilder context_builder;
615 615
616 std::unique_ptr<net::NetworkDelegate> network_delegate( 616 std::unique_ptr<net::NetworkDelegate> network_delegate(
617 new BasicNetworkDelegate()); 617 new BasicNetworkDelegate());
618 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 618 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
619 DCHECK(!data_reduction_proxy_); 619 DCHECK(!data_reduction_proxy_);
620 // For now, the choice to enable the data reduction proxy happens once, 620 // For now, the choice to enable the data reduction proxy happens once,
621 // at initialization. It cannot be disabled thereafter. 621 // at initialization. It cannot be disabled thereafter.
622 if (!config->data_reduction_proxy_key.empty()) { 622 if (!config->data_reduction_proxy_key.empty()) {
(...skipping 18 matching lines...) Expand all
641 // URL is present. Create a proxy service without a resolver and rely on this 641 // URL is present. Create a proxy service without a resolver and rely on this
642 // local HTTP proxy. See: crbug.com/432539. 642 // local HTTP proxy. See: crbug.com/432539.
643 context_builder.set_proxy_service( 643 context_builder.set_proxy_service(
644 net::ProxyService::CreateWithoutProxyResolver( 644 net::ProxyService::CreateWithoutProxyResolver(
645 std::move(proxy_config_service_), g_net_log.Get().net_log())); 645 std::move(proxy_config_service_), g_net_log.Get().net_log()));
646 646
647 config->ConfigureURLRequestContextBuilder(&context_builder, 647 config->ConfigureURLRequestContextBuilder(&context_builder,
648 g_net_log.Get().net_log(), 648 g_net_log.Get().net_log(),
649 GetFileThread()->task_runner()); 649 GetFileThread()->task_runner());
650 650
651 effective_experimental_options_ =
652 std::move(config->effective_experimental_options);
653
654 // Set up pref file if storage path is specified. 651 // Set up pref file if storage path is specified.
655 if (!config->storage_path.empty()) { 652 if (!config->storage_path.empty()) {
656 base::FilePath storage_path(config->storage_path); 653 base::FilePath storage_path(config->storage_path);
657 // Make sure storage directory has correct version. 654 // Make sure storage directory has correct version.
658 InitializeStorageDirectory(storage_path); 655 InitializeStorageDirectory(storage_path);
659 base::FilePath filepath = 656 base::FilePath filepath =
660 storage_path.Append(FILE_PATH_LITERAL(kPrefsDirectoryName)) 657 storage_path.Append(FILE_PATH_LITERAL(kPrefsDirectoryName))
661 .Append(FILE_PATH_LITERAL(kPrefsFileName)); 658 .Append(FILE_PATH_LITERAL(kPrefsFileName));
662 json_pref_store_ = 659 json_pref_store_ =
663 new JsonPrefStore(filepath, GetFileThread()->task_runner(), 660 new JsonPrefStore(filepath, GetFileThread()->task_runner(),
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 scoped_refptr<base::SingleThreadTaskRunner> 872 scoped_refptr<base::SingleThreadTaskRunner>
876 CronetURLRequestContextAdapter::GetNetworkTaskRunner() const { 873 CronetURLRequestContextAdapter::GetNetworkTaskRunner() const {
877 return network_thread_->task_runner(); 874 return network_thread_->task_runner();
878 } 875 }
879 876
880 bool CronetURLRequestContextAdapter::StartNetLogToFile( 877 bool CronetURLRequestContextAdapter::StartNetLogToFile(
881 JNIEnv* env, 878 JNIEnv* env,
882 const JavaParamRef<jobject>& jcaller, 879 const JavaParamRef<jobject>& jcaller,
883 const JavaParamRef<jstring>& jfile_name, 880 const JavaParamRef<jstring>& jfile_name,
884 jboolean jlog_all) { 881 jboolean jlog_all) {
885 base::FilePath file_path( 882 base::AutoLock lock(write_to_file_observer_lock_);
886 base::android::ConvertJavaStringToUTF8(env, jfile_name)); 883 // Do nothing if already logging to a file.
884 if (write_to_file_observer_)
885 return true;
886 std::string file_name =
887 base::android::ConvertJavaStringToUTF8(env, jfile_name);
888 base::FilePath file_path(file_name);
887 base::ScopedFILE file(base::OpenFile(file_path, "w")); 889 base::ScopedFILE file(base::OpenFile(file_path, "w"));
888 if (!file) { 890 if (!file) {
889 LOG(ERROR) << "Failed to open NetLog file for writing."; 891 LOG(ERROR) << "Failed to open NetLog file for writing.";
890 return false; 892 return false;
891 } 893 }
892 PostTaskToNetworkThread( 894
893 FROM_HERE, 895 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver());
894 base::Bind(&CronetURLRequestContextAdapter::StartNetLogOnNetworkThread, 896 if (jlog_all == JNI_TRUE) {
895 base::Unretained(this), file_path, jlog_all == JNI_TRUE)); 897 write_to_file_observer_->set_capture_mode(
898 net::NetLogCaptureMode::IncludeSocketBytes());
899 }
900 write_to_file_observer_->StartObserving(
901 g_net_log.Get().net_log(), std::move(file),
902 /*constants=*/nullptr, /*url_request_context=*/nullptr);
903
896 return true; 904 return true;
897 } 905 }
898 906
899 void CronetURLRequestContextAdapter::StartNetLogToDisk( 907 void CronetURLRequestContextAdapter::StartNetLogToDisk(
900 JNIEnv* env, 908 JNIEnv* env,
901 const JavaParamRef<jobject>& jcaller, 909 const JavaParamRef<jobject>& jcaller,
902 const JavaParamRef<jstring>& jdir_name, 910 const JavaParamRef<jstring>& jdir_name,
903 jboolean jlog_all, 911 jboolean jlog_all,
904 jint jmax_size) { 912 jint jmax_size) {
905 PostTaskToNetworkThread( 913 PostTaskToNetworkThread(
906 FROM_HERE, 914 FROM_HERE,
907 base::Bind(&CronetURLRequestContextAdapter:: 915 base::Bind(&CronetURLRequestContextAdapter::
908 StartNetLogToBoundedFileOnNetworkThread, 916 StartNetLogToBoundedFileOnNetworkThread,
909 base::Unretained(this), 917 base::Unretained(this),
910 base::android::ConvertJavaStringToUTF8(env, jdir_name), 918 base::android::ConvertJavaStringToUTF8(env, jdir_name),
911 jlog_all, jmax_size)); 919 jlog_all, jmax_size));
912 } 920 }
913 921
914 void CronetURLRequestContextAdapter::StopNetLog( 922 void CronetURLRequestContextAdapter::StopNetLog(
915 JNIEnv* env, 923 JNIEnv* env,
916 const JavaParamRef<jobject>& jcaller) { 924 const JavaParamRef<jobject>& jcaller) {
917 DCHECK(!GetNetworkTaskRunner()->BelongsToCurrentThread()); 925 StopNetLogHelper();
918 PostTaskToNetworkThread(
919 FROM_HERE,
920 base::Bind(&CronetURLRequestContextAdapter::StopNetLogOnNetworkThread,
921 base::Unretained(this)));
922 } 926 }
923 927
924 void CronetURLRequestContextAdapter::GetCertVerifierData( 928 void CronetURLRequestContextAdapter::GetCertVerifierData(
925 JNIEnv* env, 929 JNIEnv* env,
926 const JavaParamRef<jobject>& jcaller) { 930 const JavaParamRef<jobject>& jcaller) {
927 PostTaskToNetworkThread( 931 PostTaskToNetworkThread(
928 FROM_HERE, 932 FROM_HERE,
929 base::Bind( 933 base::Bind(
930 &CronetURLRequestContextAdapter::GetCertVerifierDataOnNetworkThread, 934 &CronetURLRequestContextAdapter::GetCertVerifierDataOnNetworkThread,
931 base::Unretained(this))); 935 base::Unretained(this)));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 void CronetURLRequestContextAdapter::OnThroughputObservation( 1002 void CronetURLRequestContextAdapter::OnThroughputObservation(
999 int32_t throughput_kbps, 1003 int32_t throughput_kbps,
1000 const base::TimeTicks& timestamp, 1004 const base::TimeTicks& timestamp,
1001 net::NetworkQualityObservationSource source) { 1005 net::NetworkQualityObservationSource source) {
1002 Java_CronetUrlRequestContext_onThroughputObservation( 1006 Java_CronetUrlRequestContext_onThroughputObservation(
1003 base::android::AttachCurrentThread(), jcronet_url_request_context_, 1007 base::android::AttachCurrentThread(), jcronet_url_request_context_,
1004 throughput_kbps, 1008 throughput_kbps,
1005 (timestamp - base::TimeTicks::UnixEpoch()).InMilliseconds(), source); 1009 (timestamp - base::TimeTicks::UnixEpoch()).InMilliseconds(), source);
1006 } 1010 }
1007 1011
1008 void CronetURLRequestContextAdapter::StartNetLogOnNetworkThread(
1009 const base::FilePath& file_path,
1010 bool include_socket_bytes) {
1011 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
1012
1013 // Do nothing if already logging to a file.
1014 if (net_log_file_observer_)
1015 return;
1016 net_log_file_observer_ = net::FileNetLogObserver::CreateUnbounded(
1017 GetFileThread()->task_runner(), file_path, /*constants=*/nullptr);
1018 CreateNetLogEntriesForActiveObjects({context_.get()},
1019 net_log_file_observer_.get());
1020 net::NetLogCaptureMode capture_mode =
1021 include_socket_bytes ? net::NetLogCaptureMode::IncludeSocketBytes()
1022 : net::NetLogCaptureMode::Default();
1023 net_log_file_observer_->StartObserving(g_net_log.Get().net_log(),
1024 capture_mode);
1025 }
1026
1027 void CronetURLRequestContextAdapter::StartNetLogToBoundedFileOnNetworkThread( 1012 void CronetURLRequestContextAdapter::StartNetLogToBoundedFileOnNetworkThread(
1028 const std::string& dir_path, 1013 const std::string& dir_path,
1029 bool include_socket_bytes, 1014 bool include_socket_bytes,
1030 int size) { 1015 int size) {
1031 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 1016 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
1032 1017
1033 // Do nothing if already logging to a directory. 1018 // Do nothing if already logging to a directory.
1034 if (net_log_file_observer_) 1019 if (bounded_file_observer_)
1035 return; 1020 return;
1036 1021
1037 // Filepath for NetLog files must exist and be writable. 1022 // Filepath for NetLog files must exist and be writable.
1038 base::FilePath file_path(dir_path); 1023 base::FilePath file_path(dir_path);
1039 DCHECK(base::PathIsWritable(file_path)); 1024 DCHECK(base::PathIsWritable(file_path));
1040 1025
1041 net_log_file_observer_ = net::FileNetLogObserver::CreateBounded( 1026 bounded_file_observer_ = net::FileNetLogObserver::CreateBounded(
1042 GetFileThread()->task_runner(), file_path, size, kNumNetLogEventFiles, 1027 GetFileThread()->task_runner(), file_path, size, kNumNetLogEventFiles,
1043 /*constants=*/nullptr); 1028 /*constants=*/nullptr);
1044 1029
1045 CreateNetLogEntriesForActiveObjects({context_.get()}, 1030 CreateNetLogEntriesForActiveObjects({context_.get()},
1046 net_log_file_observer_.get()); 1031 bounded_file_observer_.get());
1047 1032
1048 net::NetLogCaptureMode capture_mode = 1033 net::NetLogCaptureMode capture_mode =
1049 include_socket_bytes ? net::NetLogCaptureMode::IncludeSocketBytes() 1034 include_socket_bytes ? net::NetLogCaptureMode::IncludeSocketBytes()
1050 : net::NetLogCaptureMode::Default(); 1035 : net::NetLogCaptureMode::Default();
1051 net_log_file_observer_->StartObserving(g_net_log.Get().net_log(), 1036 bounded_file_observer_->StartObserving(g_net_log.Get().net_log(),
1052 capture_mode); 1037 capture_mode);
1053 } 1038 }
1054 1039
1055 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() { 1040 void CronetURLRequestContextAdapter::StopBoundedFileNetLogOnNetworkThread() {
1056 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 1041 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
1057 1042 bounded_file_observer_->StopObserving(
1058 if (!net_log_file_observer_) 1043 net::GetNetInfo(context_.get(), net::NET_INFO_ALL_SOURCES),
1059 return;
1060 net_log_file_observer_->StopObserving(
1061 GetNetLogInfo(),
1062 base::Bind(&CronetURLRequestContextAdapter::StopNetLogCompleted, 1044 base::Bind(&CronetURLRequestContextAdapter::StopNetLogCompleted,
1063 base::Unretained(this))); 1045 base::Unretained(this)));
1064 net_log_file_observer_.reset(); 1046 bounded_file_observer_.reset();
1065 } 1047 }
1066 1048
1067 void CronetURLRequestContextAdapter::StopNetLogCompleted() { 1049 void CronetURLRequestContextAdapter::StopNetLogCompleted() {
1068 Java_CronetUrlRequestContext_stopNetLogCompleted( 1050 Java_CronetUrlRequestContext_stopNetLogCompleted(
1069 base::android::AttachCurrentThread(), jcronet_url_request_context_.obj()); 1051 base::android::AttachCurrentThread(), jcronet_url_request_context_.obj());
1070 } 1052 }
1071 1053
1072 std::unique_ptr<base::DictionaryValue> 1054 void CronetURLRequestContextAdapter::StopNetLogHelper() {
1073 CronetURLRequestContextAdapter::GetNetLogInfo() const { 1055 base::AutoLock lock(write_to_file_observer_lock_);
1074 std::unique_ptr<base::DictionaryValue> net_info = 1056 DCHECK(!(write_to_file_observer_ && bounded_file_observer_));
1075 net::GetNetInfo(context_.get(), net::NET_INFO_ALL_SOURCES); 1057 if (write_to_file_observer_) {
1076 if (effective_experimental_options_) { 1058 write_to_file_observer_->StopObserving(/*url_request_context=*/nullptr);
1077 net_info->Set("cronetExperimentalParams", 1059 write_to_file_observer_.reset();
1078 effective_experimental_options_->CreateDeepCopy()); 1060 } else if (bounded_file_observer_) {
1061 PostTaskToNetworkThread(FROM_HERE,
1062 base::Bind(&CronetURLRequestContextAdapter::
1063 StopBoundedFileNetLogOnNetworkThread,
1064 base::Unretained(this)));
1079 } 1065 }
1080 return net_info;
1081 } 1066 }
1082 1067
1083 // Create a URLRequestContextConfig from the given parameters. 1068 // Create a URLRequestContextConfig from the given parameters.
1084 static jlong CreateRequestContextConfig( 1069 static jlong CreateRequestContextConfig(
1085 JNIEnv* env, 1070 JNIEnv* env,
1086 const JavaParamRef<jclass>& jcaller, 1071 const JavaParamRef<jclass>& jcaller,
1087 const JavaParamRef<jstring>& juser_agent, 1072 const JavaParamRef<jstring>& juser_agent,
1088 const JavaParamRef<jstring>& jstorage_path, 1073 const JavaParamRef<jstring>& jstorage_path,
1089 jboolean jquic_enabled, 1074 jboolean jquic_enabled,
1090 const JavaParamRef<jstring>& jquic_default_user_agent_id, 1075 const JavaParamRef<jstring>& jquic_default_user_agent_id,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 JNIEnv* env, 1193 JNIEnv* env,
1209 const JavaParamRef<jclass>& jcaller) { 1194 const JavaParamRef<jclass>& jcaller) {
1210 base::StatisticsRecorder::Initialize(); 1195 base::StatisticsRecorder::Initialize();
1211 std::vector<uint8_t> data; 1196 std::vector<uint8_t> data;
1212 if (!HistogramManager::GetInstance()->GetDeltas(&data)) 1197 if (!HistogramManager::GetInstance()->GetDeltas(&data))
1213 return ScopedJavaLocalRef<jbyteArray>(); 1198 return ScopedJavaLocalRef<jbyteArray>();
1214 return base::android::ToJavaByteArray(env, &data[0], data.size()); 1199 return base::android::ToJavaByteArray(env, &data[0], data.size());
1215 } 1200 }
1216 1201
1217 } // namespace cronet 1202 } // namespace cronet
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698