Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
|
xunjieli
2016/06/24 19:13:03
I think I understand it slightly better now. Thank
pauljensen
2016/06/27 11:49:43
Done.
| |
| 73 // the thread the NetworkChangeNotifier is created on. | |
| 74 void EnsureInitializedOnMainThread() { | |
| 75 DCHECK(base::MessageLoopForUI::IsCurrent()); | |
| 76 if (net_change_logger_) | |
| 77 return; | |
| 78 net_change_logger_.reset(new net::LoggingNetworkChangeObserver(&net_log_)); | |
| 79 } | |
| 70 | 80 |
| 71 private: | 81 private: |
| 72 net::NetLog net_log_; | 82 net::NetLog net_log_; |
| 73 // LoggingNetworkChangeObserver logs network change events to a NetLog. | 83 // LoggingNetworkChangeObserver logs network change events to a NetLog. |
| 74 // This class bundles one LoggingNetworkChangeObserver with one NetLog, | 84 // This class bundles one LoggingNetworkChangeObserver with one NetLog, |
| 75 // so network change event are logged just once in the NetLog. | 85 // so network change event are logged just once in the NetLog. |
| 76 net::LoggingNetworkChangeObserver net_change_logger_; | 86 std::unique_ptr<net::LoggingNetworkChangeObserver> net_change_logger_; |
| 77 | 87 |
| 78 DISALLOW_COPY_AND_ASSIGN(NetLogWithNetworkChangeEvents); | 88 DISALLOW_COPY_AND_ASSIGN(NetLogWithNetworkChangeEvents); |
| 79 }; | 89 }; |
| 80 | 90 |
| 81 // Use a global NetLog instance. See crbug.com/486120. | 91 // Use a global NetLog instance. See crbug.com/486120. |
| 82 static base::LazyInstance<NetLogWithNetworkChangeEvents>::Leaky g_net_log = | 92 static base::LazyInstance<NetLogWithNetworkChangeEvents>::Leaky g_net_log = |
| 83 LAZY_INSTANCE_INITIALIZER; | 93 LAZY_INSTANCE_INITIALIZER; |
| 84 | 94 |
| 85 const char kHttpServerProperties[] = "net.http_server_properties"; | 95 const char kHttpServerProperties[] = "net.http_server_properties"; |
| 86 // Current version of disk storage. | 96 // Current version of disk storage. |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 jcaller_ref.Reset(env, jcaller); | 416 jcaller_ref.Reset(env, jcaller); |
| 407 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( | 417 proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( |
| 408 GetNetworkTaskRunner(), nullptr /* Ignored on Android */); | 418 GetNetworkTaskRunner(), nullptr /* Ignored on Android */); |
| 409 net::ProxyConfigServiceAndroid* android_proxy_config_service = | 419 net::ProxyConfigServiceAndroid* android_proxy_config_service = |
| 410 static_cast<net::ProxyConfigServiceAndroid*>(proxy_config_service_.get()); | 420 static_cast<net::ProxyConfigServiceAndroid*>(proxy_config_service_.get()); |
| 411 // If a PAC URL is present, ignore it and use the address and port of | 421 // 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. | 422 // 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 | 423 // TODO(csharrison) Architect the wrapper better so we don't need to cast for |
| 414 // android ProxyConfigServices. | 424 // android ProxyConfigServices. |
| 415 android_proxy_config_service->set_exclude_pac_url(true); | 425 android_proxy_config_service->set_exclude_pac_url(true); |
| 426 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()
| |
| 416 GetNetworkTaskRunner()->PostTask( | 427 GetNetworkTaskRunner()->PostTask( |
| 417 FROM_HERE, | 428 FROM_HERE, |
| 418 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, | 429 base::Bind(&CronetURLRequestContextAdapter::InitializeOnNetworkThread, |
| 419 base::Unretained(this), base::Passed(&context_config_), | 430 base::Unretained(this), base::Passed(&context_config_), |
| 420 jcaller_ref)); | 431 jcaller_ref)); |
| 421 } | 432 } |
| 422 | 433 |
| 423 void CronetURLRequestContextAdapter:: | 434 void CronetURLRequestContextAdapter:: |
| 424 EnableNetworkQualityEstimatorOnNetworkThread(bool use_local_host_requests, | 435 EnableNetworkQualityEstimatorOnNetworkThread(bool use_local_host_requests, |
| 425 bool use_smaller_responses) { | 436 bool use_smaller_responses) { |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 904 JNIEnv* env, | 915 JNIEnv* env, |
| 905 const JavaParamRef<jclass>& jcaller) { | 916 const JavaParamRef<jclass>& jcaller) { |
| 906 base::StatisticsRecorder::Initialize(); | 917 base::StatisticsRecorder::Initialize(); |
| 907 std::vector<uint8_t> data; | 918 std::vector<uint8_t> data; |
| 908 if (!HistogramManager::GetInstance()->GetDeltas(&data)) | 919 if (!HistogramManager::GetInstance()->GetDeltas(&data)) |
| 909 return ScopedJavaLocalRef<jbyteArray>(); | 920 return ScopedJavaLocalRef<jbyteArray>(); |
| 910 return base::android::ToJavaByteArray(env, &data[0], data.size()); | 921 return base::android::ToJavaByteArray(env, &data[0], data.size()); |
| 911 } | 922 } |
| 912 | 923 |
| 913 } // namespace cronet | 924 } // namespace cronet |
| OLD | NEW |