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

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

Issue 2035313008: [Cronet] Make StartNetLog and StopNetLog synchronous in Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review Created 4 years, 6 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
« no previous file with comments | « components/cronet/android/cronet_url_request_context_adapter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 389 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
390 390
391 if (http_server_properties_manager_) 391 if (http_server_properties_manager_)
392 http_server_properties_manager_->ShutdownOnPrefThread(); 392 http_server_properties_manager_->ShutdownOnPrefThread();
393 if (pref_service_) 393 if (pref_service_)
394 pref_service_->CommitPendingWrite(); 394 pref_service_->CommitPendingWrite();
395 if (network_quality_estimator_) { 395 if (network_quality_estimator_) {
396 network_quality_estimator_->RemoveRTTObserver(this); 396 network_quality_estimator_->RemoveRTTObserver(this);
397 network_quality_estimator_->RemoveThroughputObserver(this); 397 network_quality_estimator_->RemoveThroughputObserver(this);
398 } 398 }
399 StopNetLogOnNetworkThread();
400 } 399 }
401 400
402 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread( 401 void CronetURLRequestContextAdapter::InitRequestContextOnMainThread(
403 JNIEnv* env, 402 JNIEnv* env,
404 const JavaParamRef<jobject>& jcaller) { 403 const JavaParamRef<jobject>& jcaller) {
405 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref; 404 base::android::ScopedJavaGlobalRef<jobject> jcaller_ref;
406 jcaller_ref.Reset(env, jcaller); 405 jcaller_ref.Reset(env, jcaller);
407 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( 406 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService(
408 GetNetworkTaskRunner(), nullptr /* Ignored on Android */); 407 GetNetworkTaskRunner(), nullptr /* Ignored on Android */);
409 net::ProxyConfigServiceAndroid* android_proxy_config_service = 408 net::ProxyConfigServiceAndroid* android_proxy_config_service =
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 scoped_refptr<base::SingleThreadTaskRunner> 696 scoped_refptr<base::SingleThreadTaskRunner>
698 CronetURLRequestContextAdapter::GetNetworkTaskRunner() const { 697 CronetURLRequestContextAdapter::GetNetworkTaskRunner() const {
699 return network_thread_->task_runner(); 698 return network_thread_->task_runner();
700 } 699 }
701 700
702 void CronetURLRequestContextAdapter::StartNetLogToFile( 701 void CronetURLRequestContextAdapter::StartNetLogToFile(
703 JNIEnv* env, 702 JNIEnv* env,
704 const JavaParamRef<jobject>& jcaller, 703 const JavaParamRef<jobject>& jcaller,
705 const JavaParamRef<jstring>& jfile_name, 704 const JavaParamRef<jstring>& jfile_name,
706 jboolean jlog_all) { 705 jboolean jlog_all) {
707 PostTaskToNetworkThread( 706 base::AutoLock lock(write_to_file_observer_lock_);
708 FROM_HERE,
709 base::Bind(
710 &CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread,
711 base::Unretained(this),
712 base::android::ConvertJavaStringToUTF8(env, jfile_name), jlog_all));
713 }
714
715 void CronetURLRequestContextAdapter::StopNetLog(
716 JNIEnv* env,
717 const JavaParamRef<jobject>& jcaller) {
718 PostTaskToNetworkThread(
719 FROM_HERE,
720 base::Bind(&CronetURLRequestContextAdapter::StopNetLogOnNetworkThread,
721 base::Unretained(this)));
722 }
723
724 void CronetURLRequestContextAdapter::StartNetLogToFileOnNetworkThread(
725 const std::string& file_name, bool log_all) {
726 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
727 DCHECK(is_context_initialized_);
728 DCHECK(context_);
729 // Do nothing if already logging to a file. 707 // Do nothing if already logging to a file.
730 if (write_to_file_observer_) 708 if (write_to_file_observer_)
731 return; 709 return;
710 std::string file_name =
711 base::android::ConvertJavaStringToUTF8(env, jfile_name);
732 base::FilePath file_path(file_name); 712 base::FilePath file_path(file_name);
733 base::ScopedFILE file(base::OpenFile(file_path, "w")); 713 base::ScopedFILE file(base::OpenFile(file_path, "w"));
734 if (!file) { 714 if (!file) {
735 LOG(ERROR) << "Failed to open NetLog file for writing."; 715 LOG(ERROR) << "Failed to open NetLog file for writing.";
736 return; 716 return;
737 } 717 }
738 718
739 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver()); 719 write_to_file_observer_.reset(new net::WriteToFileNetLogObserver());
740 if (log_all) { 720 if (jlog_all == JNI_TRUE) {
741 write_to_file_observer_->set_capture_mode( 721 write_to_file_observer_->set_capture_mode(
742 net::NetLogCaptureMode::IncludeSocketBytes()); 722 net::NetLogCaptureMode::IncludeSocketBytes());
743 } 723 }
744 write_to_file_observer_->StartObserving(context_->net_log(), std::move(file), 724 write_to_file_observer_->StartObserving(
745 nullptr, context_.get()); 725 g_net_log.Get().net_log(), std::move(file),
726 /*constants=*/nullptr, /*url_request_context=*/nullptr);
746 } 727 }
747 728
748 void CronetURLRequestContextAdapter::StopNetLogOnNetworkThread() { 729 void CronetURLRequestContextAdapter::StopNetLog(
749 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 730 JNIEnv* env,
731 const JavaParamRef<jobject>& jcaller) {
732 base::AutoLock lock(write_to_file_observer_lock_);
750 if (write_to_file_observer_) { 733 if (write_to_file_observer_) {
751 write_to_file_observer_->StopObserving(context_.get()); 734 write_to_file_observer_->StopObserving(/*url_request_context=*/nullptr);
752 write_to_file_observer_.reset(); 735 write_to_file_observer_.reset();
753 } 736 }
754 } 737 }
755 738
756 base::Thread* CronetURLRequestContextAdapter::GetFileThread() { 739 base::Thread* CronetURLRequestContextAdapter::GetFileThread() {
757 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); 740 DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread());
758 if (!file_thread_) { 741 if (!file_thread_) {
759 file_thread_.reset(new base::Thread("Network File Thread")); 742 file_thread_.reset(new base::Thread("Network File Thread"));
760 file_thread_->Start(); 743 file_thread_->Start();
761 } 744 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 JNIEnv* env, 887 JNIEnv* env,
905 const JavaParamRef<jclass>& jcaller) { 888 const JavaParamRef<jclass>& jcaller) {
906 base::StatisticsRecorder::Initialize(); 889 base::StatisticsRecorder::Initialize();
907 std::vector<uint8_t> data; 890 std::vector<uint8_t> data;
908 if (!HistogramManager::GetInstance()->GetDeltas(&data)) 891 if (!HistogramManager::GetInstance()->GetDeltas(&data))
909 return ScopedJavaLocalRef<jbyteArray>(); 892 return ScopedJavaLocalRef<jbyteArray>();
910 return base::android::ToJavaByteArray(env, &data[0], data.size()); 893 return base::android::ToJavaByteArray(env, &data[0], data.size());
911 } 894 }
912 895
913 } // namespace cronet 896 } // namespace cronet
OLDNEW
« no previous file with comments | « components/cronet/android/cronet_url_request_context_adapter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698