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

Side by Side 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: extend comment Created 4 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/cronet/android/cronet_url_request_context_adapter.h" 5 #include "components/cronet/android/cronet_url_request_context_adapter.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 #if defined(DATA_REDUCTION_PROXY_SUPPORT) 58 #if defined(DATA_REDUCTION_PROXY_SUPPORT)
59 #include "components/cronet/android/cronet_data_reduction_proxy.h" 59 #include "components/cronet/android/cronet_data_reduction_proxy.h"
60 #endif 60 #endif
61 61
62 namespace { 62 namespace {
63 63
64 // This class wraps a NetLog that also contains network change events. 64 // This class wraps a NetLog that also contains network change events.
65 class NetLogWithNetworkChangeEvents { 65 class NetLogWithNetworkChangeEvents {
66 public: 66 public:
67 NetLogWithNetworkChangeEvents() : net_log_(), net_change_logger_(&net_log_) {} 67 NetLogWithNetworkChangeEvents() {}
68 68
69 net::NetLog* net_log() { return &net_log_; } 69 net::NetLog* net_log() { return &net_log_; }
70 // This function registers with the NetworkChangeNotifier and so must be
71 // called *after* the NetworkChangeNotifier is created. Should only be
72 // called on the UI thread as it is not thread-safe and the UI thread is
73 // the thread the NetworkChangeNotifier is created on. This function is
74 // not thread-safe because accesses to |net_change_logger_| are not atomic.
75 // There might be multiple CronetEngines each with a network thread so
76 // so the UI thread is used. |g_net_log_| also outlives the network threads
77 // so it would be unsafe to receive callbacks on the network threads without
78 // a complicated thread-safe reference-counting system to control callback
79 // registration.
80 void EnsureInitializedOnMainThread() {
81 DCHECK(base::MessageLoopForUI::IsCurrent());
82 if (net_change_logger_)
83 return;
84 net_change_logger_.reset(new net::LoggingNetworkChangeObserver(&net_log_));
85 }
70 86
71 private: 87 private:
72 net::NetLog net_log_; 88 net::NetLog net_log_;
73 // LoggingNetworkChangeObserver logs network change events to a NetLog. 89 // LoggingNetworkChangeObserver logs network change events to a NetLog.
74 // This class bundles one LoggingNetworkChangeObserver with one NetLog, 90 // This class bundles one LoggingNetworkChangeObserver with one NetLog,
75 // so network change event are logged just once in the NetLog. 91 // so network change event are logged just once in the NetLog.
76 net::LoggingNetworkChangeObserver net_change_logger_; 92 std::unique_ptr<net::LoggingNetworkChangeObserver> net_change_logger_;
77 93
78 DISALLOW_COPY_AND_ASSIGN(NetLogWithNetworkChangeEvents); 94 DISALLOW_COPY_AND_ASSIGN(NetLogWithNetworkChangeEvents);
79 }; 95 };
80 96
81 // Use a global NetLog instance. See crbug.com/486120. 97 // Use a global NetLog instance. See crbug.com/486120.
82 static base::LazyInstance<NetLogWithNetworkChangeEvents>::Leaky g_net_log = 98 static base::LazyInstance<NetLogWithNetworkChangeEvents>::Leaky g_net_log =
83 LAZY_INSTANCE_INITIALIZER; 99 LAZY_INSTANCE_INITIALIZER;
84 100
85 const char kHttpServerProperties[] = "net.http_server_properties"; 101 const char kHttpServerProperties[] = "net.http_server_properties";
86 // Current version of disk storage. 102 // Current version of disk storage.
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 jcaller_ref.Reset(env, jcaller); 422 jcaller_ref.Reset(env, jcaller);
407 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( 423 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService(
408 GetNetworkTaskRunner(), nullptr /* Ignored on Android */); 424 GetNetworkTaskRunner(), nullptr /* Ignored on Android */);
409 net::ProxyConfigServiceAndroid* android_proxy_config_service = 425 net::ProxyConfigServiceAndroid* android_proxy_config_service =
410 static_cast<net::ProxyConfigServiceAndroid*>(proxy_config_service_.get()); 426 static_cast<net::ProxyConfigServiceAndroid*>(proxy_config_service_.get());
411 // If a PAC URL is present, ignore it and use the address and port of 427 // If a PAC URL is present, ignore it and use the address and port of
412 // Android system's local HTTP proxy server. See: crbug.com/432539. 428 // Android system's local HTTP proxy server. See: crbug.com/432539.
413 // TODO(csharrison) Architect the wrapper better so we don't need to cast for 429 // TODO(csharrison) Architect the wrapper better so we don't need to cast for
414 // android ProxyConfigServices. 430 // android ProxyConfigServices.
415 android_proxy_config_service->set_exclude_pac_url(true); 431 android_proxy_config_service->set_exclude_pac_url(true);
432 g_net_log.Get().EnsureInitializedOnMainThread();
416 GetNetworkTaskRunner()->PostTask( 433 GetNetworkTaskRunner()->PostTask(
417 FROM_HERE, 434 FROM_HERE,
418 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, 435 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread,
419 base::Unretained(this), base::Passed(&context_config_), 436 base::Unretained(this), base::Passed(&context_config_),
420 jcaller_ref)); 437 jcaller_ref));
421 } 438 }
422 439
423 void CronetURLRequestContextAdapter:: 440 void CronetURLRequestContextAdapter::
424 EnableNetworkQualityEstimatorOnNetworkThread(bool use_local_host_requests, 441 EnableNetworkQualityEstimatorOnNetworkThread(bool use_local_host_requests,
425 bool use_smaller_responses) { 442 bool use_smaller_responses) {
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 JNIEnv* env, 921 JNIEnv* env,
905 const JavaParamRef<jclass>& jcaller) { 922 const JavaParamRef<jclass>& jcaller) {
906 base::StatisticsRecorder::Initialize(); 923 base::StatisticsRecorder::Initialize();
907 std::vector<uint8_t> data; 924 std::vector<uint8_t> data;
908 if (!HistogramManager::GetInstance()->GetDeltas(&data)) 925 if (!HistogramManager::GetInstance()->GetDeltas(&data))
909 return ScopedJavaLocalRef<jbyteArray>(); 926 return ScopedJavaLocalRef<jbyteArray>();
910 return base::android::ToJavaByteArray(env, &data[0], data.size()); 927 return base::android::ToJavaByteArray(env, &data[0], data.size());
911 } 928 }
912 929
913 } // namespace cronet 930 } // namespace cronet
OLDNEW
« 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