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

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

Issue 2098753002: [Cronet] Fix race with NetLogWithNetworkChangeEvents registration with NCN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: _ Created 4 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698