Chromium Code Reviews| Index: components/cronet/android/cronet_url_request_context_adapter.cc |
| diff --git a/components/cronet/android/cronet_url_request_context_adapter.cc b/components/cronet/android/cronet_url_request_context_adapter.cc |
| index 1141e8b2cc0a90b18a593ecb41f478b52168e1a0..d9cb905ed9a181c1c1268479e68e616f8fe45cae 100644 |
| --- a/components/cronet/android/cronet_url_request_context_adapter.cc |
| +++ b/components/cronet/android/cronet_url_request_context_adapter.cc |
| @@ -64,16 +64,26 @@ namespace { |
| // This class wraps a NetLog that also contains network change events. |
| class NetLogWithNetworkChangeEvents { |
| public: |
| - NetLogWithNetworkChangeEvents() : net_log_(), net_change_logger_(&net_log_) {} |
| + NetLogWithNetworkChangeEvents() {} |
| net::NetLog* net_log() { return &net_log_; } |
| + // This function registers with the NetworkChangeNotifier and so must be |
| + // called *after* the NetworkChangeNotifier is created. Should only be |
| + // called on the UI thread as it is not thread-safe and the UI thread is |
|
xunjieli
2016/06/24 19:13:03
I think I understand it slightly better now. Thank
pauljensen
2016/06/27 11:49:43
Done.
|
| + // the thread the NetworkChangeNotifier is created on. |
| + void EnsureInitializedOnMainThread() { |
| + DCHECK(base::MessageLoopForUI::IsCurrent()); |
| + if (net_change_logger_) |
| + return; |
| + net_change_logger_.reset(new net::LoggingNetworkChangeObserver(&net_log_)); |
| + } |
| private: |
| net::NetLog net_log_; |
| // LoggingNetworkChangeObserver logs network change events to a NetLog. |
| // This class bundles one LoggingNetworkChangeObserver with one NetLog, |
| // so network change event are logged just once in the NetLog. |
| - net::LoggingNetworkChangeObserver net_change_logger_; |
| + std::unique_ptr<net::LoggingNetworkChangeObserver> net_change_logger_; |
| DISALLOW_COPY_AND_ASSIGN(NetLogWithNetworkChangeEvents); |
| }; |
| @@ -413,6 +423,7 @@ void CronetURLRequestContextAdapter::InitRequestContextOnMainThread( |
| // TODO(csharrison) Architect the wrapper better so we don't need to cast for |
| // android ProxyConfigServices. |
| android_proxy_config_service->set_exclude_pac_url(true); |
| + g_net_log.Get().EnsureInitializedOnMainThread(); |
|
xunjieli
2016/06/24 13:49:53
Why do we initialize the observer on the main thre
pauljensen
2016/06/24 14:09:43
A few reasons:
1. so as to initialize it ASAP so w
xunjieli
2016/06/24 16:20:11
AddObserver is already thread safe. There isn't ad
pauljensen
2016/06/24 19:03:36
No, take a look at EnsureInitializedOnMainThread()
|
| GetNetworkTaskRunner()->PostTask( |
| FROM_HERE, |
| base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, |