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

Unified Diff: components/cronet/android/url_request_context_adapter.cc

Issue 617393005: Make URLRequestContextAdapter initialization asynchronous (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/url_request_context_adapter.cc
diff --git a/components/cronet/android/url_request_context_adapter.cc b/components/cronet/android/url_request_context_adapter.cc
index 00e463e7f83d0f3cefbb14abfe0891ed28366c08..a192f567dd56c26fad7056ccbbb58a461628ce08 100644
--- a/components/cronet/android/url_request_context_adapter.cc
+++ b/components/cronet/android/url_request_context_adapter.cc
@@ -178,6 +178,11 @@ void URLRequestContextAdapter::InitializeURLRequestContext(
net::AlternateProtocol::QUIC,
1.0f);
}
+ is_context_initialized_ = true;
+ while (!tasks_waiting_for_context_.empty()) {
+ tasks_waiting_for_context_.front().Run();
+ tasks_waiting_for_context_.pop();
+ }
}
if (VLOG_IS_ON(2)) {
@@ -189,12 +194,32 @@ void URLRequestContextAdapter::InitializeURLRequestContext(
delegate_->OnContextInitialized(this);
}
+void URLRequestContextAdapter::RunTaskAfterContextInit(
+ const RunAfterContextInitTask& callback) {
+ GetNetworkTaskRunner()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &URLRequestContextAdapter::RunTaskAfterContextInitOnNetworkThread,
+ this,
+ callback));
+}
+
+// Called on network thread.
+void URLRequestContextAdapter::RunTaskAfterContextInitOnNetworkThread(
+ const RunAfterContextInitTask& callback) {
+ if (is_context_initialized_) {
+ callback.Run();
+ return;
+ }
+ tasks_waiting_for_context_.push(callback);
+}
+
URLRequestContextAdapter::~URLRequestContextAdapter() {
if (net_log_observer_) {
context_->net_log()->RemoveThreadSafeObserver(net_log_observer_.get());
net_log_observer_.reset();
}
- StopNetLog();
+ StopNetLogHelper();
// TODO(mef): Ensure that |network_thread_| is destroyed properly.
}
@@ -216,6 +241,17 @@ URLRequestContextAdapter::GetNetworkTaskRunner() const {
}
void URLRequestContextAdapter::StartNetLogToFile(const std::string& file_name) {
+ RunTaskAfterContextInit(base::Bind(
+ &URLRequestContextAdapter::StartNetLogToFileHelper, this, file_name));
+}
+
+void URLRequestContextAdapter::StopNetLog() {
+ RunTaskAfterContextInit(
+ base::Bind(&URLRequestContextAdapter::StopNetLogHelper, this));
+}
+
+void URLRequestContextAdapter::StartNetLogToFileHelper(
+ const std::string& file_name) {
// Do nothing if already logging to a file.
if (net_log_logger_)
return;
@@ -230,7 +266,7 @@ void URLRequestContextAdapter::StartNetLogToFile(const std::string& file_name) {
net_log_logger_->StartObserving(context_->net_log());
}
-void URLRequestContextAdapter::StopNetLog() {
+void URLRequestContextAdapter::StopNetLogHelper() {
if (net_log_logger_) {
net_log_logger_->StopObserving();
net_log_logger_.reset();

Powered by Google App Engine
This is Rietveld 408576698