Chromium Code Reviews| 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 026e39d0b1524e30d1fb4f8fc5cd31232514cd14..230efcdc6382b3fdae9724aa1e21bec048bb8457 100644 |
| --- a/components/cronet/android/url_request_context_adapter.cc |
| +++ b/components/cronet/android/url_request_context_adapter.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/bind.h" |
| #include "base/files/file_util.h" |
| +#include "base/message_loop/message_loop.h" |
| #include "base/single_thread_task_runner.h" |
| #include "components/cronet/url_request_context_config.h" |
| #include "net/base/net_errors.h" |
| @@ -14,7 +15,7 @@ |
| #include "net/http/http_auth_handler_factory.h" |
| #include "net/http/http_network_layer.h" |
| #include "net/http/http_server_properties.h" |
| -#include "net/proxy/proxy_config_service_fixed.h" |
| +#include "net/proxy/proxy_config_service.h" |
| #include "net/proxy/proxy_service.h" |
| #include "net/ssl/ssl_config_service_defaults.h" |
| #include "net/url_request/static_http_user_agent_settings.h" |
| @@ -108,6 +109,9 @@ class BasicNetworkDelegate : public net::NetworkDelegate { |
| DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); |
| }; |
| +// Android specific UI MessageLoop. |
|
mmenke
2014/10/15 17:44:17
Maybe "UI MessageLoop" -> "MessageLoop on main thr
xunjieli
2014/10/15 19:48:08
Done.
|
| +base::MessageLoop* g_main_message_loop = nullptr; |
|
mmenke
2014/10/15 17:44:17
optional: Suggest putting this at the top of the
xunjieli
2014/10/15 19:48:08
Done.
|
| + |
| } // namespace |
| namespace cronet { |
| @@ -125,22 +129,34 @@ void URLRequestContextAdapter::Initialize( |
| base::Thread::Options options; |
| options.message_loop_type = base::MessageLoop::TYPE_IO; |
| network_thread_->StartWithOptions(options); |
| + config_ = config.Pass(); |
| +} |
| + |
| +void URLRequestContextAdapter::InitRequestContextOnUIThread() { |
|
mmenke
2014/10/15 17:44:18
DCHECK(config_)?
xunjieli
2014/10/15 19:48:09
Done.
|
| + if (!base::MessageLoop::current()) { |
|
mmenke
2014/10/15 17:44:17
We have no tests where this check is false, I beli
xunjieli
2014/10/15 19:48:08
Done.
|
| + DCHECK(!g_main_message_loop); |
| + g_main_message_loop = new base::MessageLoopForUI; |
|
mmenke
2014/10/15 17:44:17
optional nit: Seems more common to use "()" with
xunjieli
2014/10/15 19:48:08
Done.
|
| + base::MessageLoopForUI::current()->Start(); |
| + } |
|
mmenke
2014/10/15 17:44:17
DCHECK_EQ(g_main_message_loop, base::MessageLoop::
xunjieli
2014/10/15 19:48:08
Done.
|
| + net::ProxyConfigService* service = |
|
mmenke
2014/10/15 17:44:17
Should generally avoid using raw pointers, except
xunjieli
2014/10/15 19:48:09
Done.
|
| + net::ProxyService::CreateSystemProxyConfigService(GetNetworkTaskRunner(), |
| + NULL); |
| + proxy_config_service_.reset(service); |
| GetNetworkTaskRunner()->PostTask( |
| FROM_HERE, |
| - base::Bind(&URLRequestContextAdapter::InitializeURLRequestContext, |
| + base::Bind(&URLRequestContextAdapter::InitRequestContextOnNetworkThread, |
| this, |
| - Passed(&config))); |
| + Passed(&config_))); |
|
mmenke
2014/10/15 17:44:17
I don't think we get anything from passing the con
xunjieli
2014/10/15 19:48:09
Done. Sounds good. I adopted the second approach.
|
| } |
| -void URLRequestContextAdapter::InitializeURLRequestContext( |
| +void URLRequestContextAdapter::InitRequestContextOnNetworkThread( |
| scoped_ptr<URLRequestContextConfig> config) { |
| DCHECK(GetNetworkTaskRunner()->BelongsToCurrentThread()); |
| // TODO(mmenke): Add method to have the builder enable SPDY. |
| net::URLRequestContextBuilder context_builder; |
| context_builder.set_network_delegate(new BasicNetworkDelegate()); |
| - context_builder.set_proxy_config_service( |
| - new net::ProxyConfigServiceFixed(net::ProxyConfig())); |
| + context_builder.set_proxy_config_service(proxy_config_service_.get()); |
| config->ConfigureURLRequestContextBuilder(&context_builder); |
| context_.reset(context_builder.Build()); |
| @@ -179,11 +195,6 @@ 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)) { |
| @@ -192,6 +203,12 @@ void URLRequestContextAdapter::InitializeURLRequestContext( |
| net::NetLog::LOG_ALL_BUT_BYTES); |
| } |
| + is_context_initialized_ = true; |
| + while (!tasks_waiting_for_context_.empty()) { |
| + tasks_waiting_for_context_.front().Run(); |
| + tasks_waiting_for_context_.pop(); |
| + } |
| + |
| delegate_->OnContextInitialized(this); |
| } |