| 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.
|
| +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());
|
|
|