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

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: Removed mStarted 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..51b52ec94657ce53eb9d763df098c4a46b7a59ef 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,6 +194,26 @@ void URLRequestContextAdapter::InitializeURLRequestContext(
delegate_->OnContextInitialized(this);
}
+// Runs a task that might depend on the context being initialized.
+// This method can be called on any thread.
mmenke 2014/10/02 22:11:52 nit: Function level comments should go with the d
xunjieli 2014/10/03 14:32:55 Done.
+void URLRequestContextAdapter::RunTask(
+ const RunAfterContextInitTask& callback) {
+ GetNetworkTaskRunner()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ &URLRequestContextAdapter::RunTaskOnNetworkThread, this, callback));
+}
+
+// This method should only be run on the network thread.
+void URLRequestContextAdapter::RunTaskOnNetworkThread(
+ 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());

Powered by Google App Engine
This is Rietveld 408576698