[email protected] | d24fc3a0 | 2012-02-11 02:08:34 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/io_thread.h" |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 6 | |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 7 | #include <utility> |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 10 | #include "base/base64.h" |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 11 | #include "base/bind.h" |
| 12 | #include "base/bind_helpers.h" |
[email protected] | aa84a7e | 2012-03-15 21:29:06 | [diff] [blame] | 13 | #include "base/command_line.h" |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 14 | #include "base/compiler_specific.h" |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 15 | #include "base/debug/leak_tracker.h" |
zhongyi | 81f85c6d9 | 2015-10-16 19:34:14 | [diff] [blame] | 16 | #include "base/environment.h" |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 17 | #include "base/files/file_path.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 18 | #include "base/logging.h" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 19 | #include "base/macros.h" |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 20 | #include "base/memory/ptr_util.h" |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 21 | #include "base/metrics/field_trial.h" |
davidben | 45eb1995 | 2016-05-05 16:30:44 | [diff] [blame] | 22 | #include "base/metrics/histogram_macros.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 23 | #include "base/stl_util.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 24 | #include "base/strings/string_number_conversions.h" |
bnc | e3553d9 | 2014-10-30 22:29:45 | [diff] [blame] | 25 | #include "base/strings/string_piece.h" |
[email protected] | 1988e1c | 2013-02-28 20:27:42 | [diff] [blame] | 26 | #include "base/strings/string_split.h" |
[email protected] | 9c7ddc9 | 2013-06-11 01:40:57 | [diff] [blame] | 27 | #include "base/strings/string_util.h" |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 28 | #include "base/strings/utf_string_conversions.h" |
fdoray | dd7eb40 | 2017-04-26 21:44:25 | [diff] [blame] | 29 | #include "base/task_scheduler/post_task.h" |
[email protected] | 3fc40c14 | 2011-12-01 13:09:04 | [diff] [blame] | 30 | #include "base/threading/thread.h" |
[email protected] | d827e11 | 2014-03-31 17:45:05 | [diff] [blame] | 31 | #include "base/time/time.h" |
primiano | 6221e57 | 2015-01-28 12:14:34 | [diff] [blame] | 32 | #include "base/trace_event/trace_event.h" |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 33 | #include "build/build_config.h" |
[email protected] | df2840d | 2011-02-20 16:32:32 | [diff] [blame] | 34 | #include "chrome/browser/browser_process.h" |
sclittle | a133de0 | 2015-11-10 23:54:21 | [diff] [blame] | 35 | #include "chrome/browser/data_usage/tab_id_annotator.h" |
kundaji | f617523b | 2016-09-09 22:41:24 | [diff] [blame] | 36 | #include "chrome/browser/data_use_measurement/chrome_data_use_ascriber.h" |
[email protected] | 026876f3 | 2012-08-22 23:53:40 | [diff] [blame] | 37 | #include "chrome/browser/net/async_dns_field_trial.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 38 | #include "chrome/browser/net/chrome_network_delegate.h" |
[email protected] | 4588b3d | 2012-11-14 00:37:38 | [diff] [blame] | 39 | #include "chrome/browser/net/dns_probe_service.h" |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 40 | #include "chrome/browser/net/proxy_service_factory.h" |
eranm | 3c2d643 | 2016-06-01 10:17:27 | [diff] [blame] | 41 | #include "chrome/browser/net/sth_distributor_provider.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 42 | #include "chrome/common/channel_info.h" |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 43 | #include "chrome/common/chrome_content_client.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 44 | #include "chrome/common/chrome_switches.h" |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 45 | #include "chrome/common/pref_names.h" |
eranm | 3c2d643 | 2016-06-01 10:17:27 | [diff] [blame] | 46 | #include "components/certificate_transparency/tree_state_tracker.h" |
megjablon | 3476e04 | 2014-10-14 19:21:59 | [diff] [blame] | 47 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h" |
sclittle | 3f98c6c | 2015-11-19 22:59:29 | [diff] [blame] | 48 | #include "components/data_usage/core/data_use_aggregator.h" |
sclittle | c441f78 | 2015-11-12 01:12:09 | [diff] [blame] | 49 | #include "components/data_usage/core/data_use_amortizer.h" |
sclittle | 3f98c6c | 2015-11-19 22:59:29 | [diff] [blame] | 50 | #include "components/data_usage/core/data_use_annotator.h" |
kundaji | c613596 | 2016-09-26 17:54:28 | [diff] [blame] | 51 | #include "components/data_use_measurement/core/data_use_ascriber.h" |
gayane | 0b46091c | 2016-04-07 21:01:05 | [diff] [blame] | 52 | #include "components/metrics/metrics_service.h" |
droger | c690e880 | 2015-09-21 14:29:16 | [diff] [blame] | 53 | #include "components/net_log/chrome_net_log.h" |
bnc | 210d6f3 | 2016-05-24 07:40:47 | [diff] [blame] | 54 | #include "components/network_session_configurator/network_session_configurator.h" |
[email protected] | 76b4b15 | 2013-12-08 21:10:04 | [diff] [blame] | 55 | #include "components/policy/core/common/policy_service.h" |
brettw | 39d6ba4 | 2016-08-24 16:56:38 | [diff] [blame] | 56 | #include "components/policy/policy_constants.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 57 | #include "components/prefs/pref_registry_simple.h" |
| 58 | #include "components/prefs/pref_service.h" |
abhishek.a21 | 71c61285 | 2015-08-31 10:48:19 | [diff] [blame] | 59 | #include "components/proxy_config/pref_proxy_config_tracker.h" |
[email protected] | 488a0e25 | 2014-06-25 04:37:44 | [diff] [blame] | 60 | #include "components/variations/variations_associated_data.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 61 | #include "components/version_info/version_info.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 62 | #include "content/public/browser/browser_thread.h" |
[email protected] | 7c4b66b | 2014-01-04 12:28:13 | [diff] [blame] | 63 | #include "content/public/browser/cookie_store_factory.h" |
eustas | fbec913 | 2015-12-30 14:56:51 | [diff] [blame] | 64 | #include "content/public/common/content_features.h" |
brettw | 90e9260 | 2015-10-10 00:12:40 | [diff] [blame] | 65 | #include "content/public/common/content_switches.h" |
rtenneti | 4d126a7 | 2015-06-23 17:32:09 | [diff] [blame] | 66 | #include "content/public/common/user_agent.h" |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 67 | #include "extensions/features/features.h" |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 68 | #include "net/base/host_mapping_rules.h" |
pauljensen | 7b34e52 | 2016-05-12 18:20:59 | [diff] [blame] | 69 | #include "net/base/logging_network_change_observer.h" |
rdsmith | 60e6e6fb | 2015-03-05 16:49:20 | [diff] [blame] | 70 | #include "net/base/sdch_manager.h" |
rsleevi | 6df5418 | 2016-06-13 14:34:23 | [diff] [blame] | 71 | #include "net/cert/caching_cert_verifier.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 72 | #include "net/cert/cert_verifier.h" |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 73 | #include "net/cert/cert_verify_proc.h" |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 74 | #include "net/cert/ct_known_logs.h" |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 75 | #include "net/cert/ct_log_verifier.h" |
estark | 6f9b3d8 | 2016-01-12 21:37:05 | [diff] [blame] | 76 | #include "net/cert/ct_policy_enforcer.h" |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 77 | #include "net/cert/ct_verifier.h" |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 78 | #include "net/cert/multi_log_ct_verifier.h" |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 79 | #include "net/cert/multi_threaded_cert_verifier.h" |
eranm | 3c2d643 | 2016-06-01 10:17:27 | [diff] [blame] | 80 | #include "net/cert/sth_distributor.h" |
| 81 | #include "net/cert/sth_observer.h" |
[email protected] | 9a6c2aa | 2014-01-11 22:39:39 | [diff] [blame] | 82 | #include "net/cookies/cookie_store.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 83 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 84 | #include "net/dns/host_resolver.h" |
| 85 | #include "net/dns/mapped_host_resolver.h" |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 86 | #include "net/http/http_auth_filter.h" |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 87 | #include "net/http/http_auth_handler_factory.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 88 | #include "net/http/http_auth_preferences.h" |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 89 | #include "net/http/http_network_layer.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 90 | #include "net/http/http_server_properties_impl.h" |
brettw | a1228ebb | 2016-10-28 03:51:34 | [diff] [blame] | 91 | #include "net/net_features.h" |
tbansal | ca83c00 | 2016-04-28 20:56:28 | [diff] [blame] | 92 | #include "net/nqe/external_estimate_provider.h" |
| 93 | #include "net/nqe/network_quality_estimator.h" |
tbansal | d3e08ca6 | 2017-05-04 19:51:09 | [diff] [blame] | 94 | #include "net/nqe/network_quality_estimator_params.h" |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 95 | #include "net/proxy/proxy_config_service.h" |
[email protected] | 8693361 | 2010-10-16 23:10:33 | [diff] [blame] | 96 | #include "net/proxy/proxy_script_fetcher_impl.h" |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 97 | #include "net/proxy/proxy_service.h" |
rch | 4c967ea | 2016-12-22 01:41:07 | [diff] [blame] | 98 | #include "net/quic/chromium/quic_utils_chromium.h" |
zhongyi | 81f85c6d9 | 2015-10-16 19:34:14 | [diff] [blame] | 99 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 717e4e2 | 2013-04-10 20:52:23 | [diff] [blame] | 100 | #include "net/socket/tcp_client_socket.h" |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 101 | #include "net/ssl/channel_id_service.h" |
| 102 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 103 | #include "net/url_request/data_protocol_handler.h" |
| 104 | #include "net/url_request/file_protocol_handler.h" |
| 105 | #include "net/url_request/ftp_protocol_handler.h" |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 106 | #include "net/url_request/static_http_user_agent_settings.h" |
[email protected] | 3dc1bc4 | 2012-06-19 08:20:53 | [diff] [blame] | 107 | #include "net/url_request/url_fetcher.h" |
[email protected] | f9c8c7c | 2014-07-31 16:42:31 | [diff] [blame] | 108 | #include "net/url_request/url_request_context.h" |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 109 | #include "net/url_request/url_request_context_builder.h" |
[email protected] | f9c8c7c | 2014-07-31 16:42:31 | [diff] [blame] | 110 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | b3ae2db | 2013-05-30 05:00:05 | [diff] [blame] | 111 | #include "net/url_request/url_request_job_factory_impl.h" |
brettw | 03e6196 | 2016-03-15 06:27:04 | [diff] [blame] | 112 | #include "url/url_constants.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 113 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 114 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 115 | #include "chrome/browser/extensions/event_router_forwarder.h" |
| 116 | #endif |
| 117 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 118 | #if defined(USE_NSS_CERTS) |
eroman | ed744f3 | 2015-04-09 06:35:49 | [diff] [blame] | 119 | #include "net/cert_net/nss_ocsp.h" |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 120 | #endif |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 121 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 122 | #if defined(OS_ANDROID) |
jeremyim | b6c97ae | 2015-01-05 22:57:14 | [diff] [blame] | 123 | #include "base/android/build_info.h" |
megjablon | 174bc34 | 2015-11-05 00:30:06 | [diff] [blame] | 124 | #include "chrome/browser/android/data_usage/external_data_use_observer.h" |
tbansal | dafbb3e | 2015-08-19 19:55:33 | [diff] [blame] | 125 | #include "chrome/browser/android/net/external_estimate_provider_android.h" |
sclittle | c441f78 | 2015-11-12 01:12:09 | [diff] [blame] | 126 | #include "components/data_usage/android/traffic_stats_amortizer.h" |
estark | 9a26378 | 2017-01-20 02:13:04 | [diff] [blame] | 127 | #include "net/cert/cert_net_fetcher.h" |
| 128 | #include "net/cert/cert_verify_proc_android.h" |
| 129 | #include "net/cert_net/cert_net_fetcher_impl.h" |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 130 | #endif // defined(OS_ANDROID) |
jeremyim | b6c97ae | 2015-01-05 22:57:14 | [diff] [blame] | 131 | |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 132 | #if defined(OS_CHROMEOS) |
| 133 | #include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h" |
zentaro | e032635 | 2017-05-09 13:11:51 | [diff] [blame^] | 134 | #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
[email protected] | 106ccd2c | 2014-06-17 09:21:00 | [diff] [blame] | 135 | #include "chromeos/network/host_resolver_impl_chromeos.h" |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 136 | #endif |
| 137 | |
davidben | 45eb1995 | 2016-05-05 16:30:44 | [diff] [blame] | 138 | #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) |
davidben | 45eb1995 | 2016-05-05 16:30:44 | [diff] [blame] | 139 | #include "crypto/openssl_util.h" |
tfarina | 29a3a174 | 2016-10-28 18:47:33 | [diff] [blame] | 140 | #include "third_party/boringssl/src/include/openssl/cpu.h" |
davidben | 45eb1995 | 2016-05-05 16:30:44 | [diff] [blame] | 141 | #endif |
| 142 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 143 | using content::BrowserThread; |
| 144 | |
[email protected] | 075c032 | 2012-02-14 00:56:44 | [diff] [blame] | 145 | class SafeBrowsingURLRequestContext; |
| 146 | |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 147 | // The IOThread object must outlive any tasks posted to the IO thread before the |
| 148 | // Quit task, so base::Bind() calls are not refcounted. |
| 149 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 150 | namespace { |
| 151 | |
tbansal | b177b539 | 2015-06-25 11:13:02 | [diff] [blame] | 152 | // Field trial for network quality estimator. Seeds RTT and downstream |
| 153 | // throughput observations with values that correspond to the connection type |
| 154 | // determined by the operating system. |
| 155 | const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator"; |
| 156 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 157 | #if defined(OS_MACOSX) |
[email protected] | 11f5e3a | 2012-09-27 00:30:13 | [diff] [blame] | 158 | void ObserveKeychainEvents() { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 159 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 11f5e3a | 2012-09-27 00:30:13 | [diff] [blame] | 160 | net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents(); |
| 161 | } |
| 162 | #endif |
| 163 | |
zhongyi | 81f85c6d9 | 2015-10-16 19:34:14 | [diff] [blame] | 164 | // Gets file path into ssl_keylog_file from command line argument or |
| 165 | // environment variable. Command line argument has priority when |
| 166 | // both specified. |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 167 | base::FilePath GetSSLKeyLogFile(const base::CommandLine& command_line) { |
zhongyi | 81f85c6d9 | 2015-10-16 19:34:14 | [diff] [blame] | 168 | if (command_line.HasSwitch(switches::kSSLKeyLogFile)) { |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 169 | base::FilePath path = |
| 170 | command_line.GetSwitchValuePath(switches::kSSLKeyLogFile); |
| 171 | if (!path.empty()) |
| 172 | return path; |
zhongyi | 81f85c6d9 | 2015-10-16 19:34:14 | [diff] [blame] | 173 | LOG(WARNING) << "ssl-key-log-file argument missing"; |
| 174 | } |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 175 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 176 | std::unique_ptr<base::Environment> env(base::Environment::Create()); |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 177 | std::string path_str; |
| 178 | env->GetVar("SSLKEYLOGFILE", &path_str); |
| 179 | #if defined(OS_WIN) |
| 180 | // base::Environment returns environment variables in UTF-8 on Windows. |
| 181 | return base::FilePath(base::UTF8ToUTF16(path_str)); |
| 182 | #else |
| 183 | return base::FilePath(path_str); |
| 184 | #endif |
zhongyi | 81f85c6d9 | 2015-10-16 19:34:14 | [diff] [blame] | 185 | } |
| 186 | |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 187 | // Used for the "system" URLRequestContext. |
| 188 | class SystemURLRequestContext : public net::URLRequestContext { |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 189 | public: |
| 190 | SystemURLRequestContext() { |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 191 | #if defined(USE_NSS_CERTS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 192 | net::SetURLRequestContextForNSSHttpIO(this); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 193 | #endif |
estark | 9a26378 | 2017-01-20 02:13:04 | [diff] [blame] | 194 | #if defined(OS_ANDROID) |
| 195 | net::CertVerifyProcAndroid::SetCertNetFetcher( |
| 196 | net::CreateCertNetFetcher(this)); |
| 197 | #endif |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | private: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 201 | ~SystemURLRequestContext() override { |
[email protected] | 42455949 | 2014-07-22 00:27:40 | [diff] [blame] | 202 | AssertNoURLRequests(); |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 203 | #if defined(USE_NSS_CERTS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 204 | net::SetURLRequestContextForNSSHttpIO(NULL); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 205 | #endif |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 206 | } |
| 207 | }; |
| 208 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 209 | std::unique_ptr<net::HostResolver> CreateGlobalHostResolver( |
| 210 | net::NetLog* net_log) { |
[email protected] | d22f06e | 2013-06-11 16:01:17 | [diff] [blame] | 211 | TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver"); |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 212 | const base::CommandLine& command_line = |
| 213 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 214 | |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 215 | net::HostResolver::Options options; |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 216 | |
[email protected] | 06ef6d9 | 2011-05-19 04:24:58 | [diff] [blame] | 217 | // Use the retry attempts override from the command-line, if any. |
| 218 | if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) { |
| 219 | std::string s = |
| 220 | command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts); |
| 221 | // Parse the switch (it should be a non-negative integer). |
| 222 | int n; |
| 223 | if (base::StringToInt(s, &n) && n >= 0) { |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 224 | options.max_retry_attempts = static_cast<size_t>(n); |
[email protected] | 06ef6d9 | 2011-05-19 04:24:58 | [diff] [blame] | 225 | } else { |
| 226 | LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s; |
| 227 | } |
| 228 | } |
| 229 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 230 | std::unique_ptr<net::HostResolver> global_host_resolver; |
[email protected] | 106ccd2c | 2014-06-17 09:21:00 | [diff] [blame] | 231 | #if defined OS_CHROMEOS |
| 232 | global_host_resolver = |
| 233 | chromeos::HostResolverImplChromeOS::CreateSystemResolver(options, |
| 234 | net_log); |
| 235 | #else |
| 236 | global_host_resolver = |
| 237 | net::HostResolver::CreateSystemResolver(options, net_log); |
| 238 | #endif |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 239 | |
[email protected] | 3dc5d7ef | 2014-03-28 19:18:21 | [diff] [blame] | 240 | // If hostname remappings were specified on the command-line, layer these |
| 241 | // rules on top of the real host resolver. This allows forwarding all requests |
| 242 | // through a designated test server. |
| 243 | if (!command_line.HasSwitch(switches::kHostResolverRules)) |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 244 | return global_host_resolver; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 245 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 246 | std::unique_ptr<net::MappedHostResolver> remapped_resolver( |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 247 | new net::MappedHostResolver(std::move(global_host_resolver))); |
[email protected] | 3dc5d7ef | 2014-03-28 19:18:21 | [diff] [blame] | 248 | remapped_resolver->SetRulesFromString( |
| 249 | command_line.GetSwitchValueASCII(switches::kHostResolverRules)); |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 250 | return std::move(remapped_resolver); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 251 | } |
| 252 | |
jam | 1671ed3 | 2016-07-27 16:31:24 | [diff] [blame] | 253 | int GetSwitchValueAsInt(const base::CommandLine& command_line, |
| 254 | const std::string& switch_name) { |
| 255 | int value; |
| 256 | if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name), |
| 257 | &value)) { |
| 258 | return 0; |
| 259 | } |
| 260 | return value; |
| 261 | } |
| 262 | |
robliao | 7253fd2 | 2016-12-01 18:41:38 | [diff] [blame] | 263 | // This function is for forwarding metrics usage pref changes to the metrics |
| 264 | // service on the appropriate thread. |
| 265 | // TODO(gayane): Reduce the frequency of posting tasks from IO to UI thread. |
| 266 | void UpdateMetricsUsagePrefsOnUIThread(const std::string& service_name, |
| 267 | int message_size, |
| 268 | bool is_cellular) { |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 269 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 270 | base::BindOnce( |
| 271 | [](const std::string& service_name, |
| 272 | int message_size, bool is_cellular) { |
| 273 | // Some unit tests use IOThread but do not |
| 274 | // initialize MetricsService. In that case it's |
| 275 | // fine to skip the update. |
| 276 | auto* metrics_service = |
| 277 | g_browser_process->metrics_service(); |
| 278 | if (metrics_service) { |
| 279 | metrics_service->UpdateMetricsUsagePrefs( |
| 280 | service_name, message_size, is_cellular); |
| 281 | } |
| 282 | }, |
| 283 | service_name, message_size, is_cellular)); |
robliao | 7253fd2 | 2016-12-01 18:41:38 | [diff] [blame] | 284 | } |
| 285 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 286 | } // namespace |
| 287 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 288 | class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 289 | public: |
| 290 | explicit SystemURLRequestContextGetter(IOThread* io_thread); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 291 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 292 | // Implementation for net::UrlRequestContextGetter. |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 293 | net::URLRequestContext* GetURLRequestContext() override; |
| 294 | scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() |
| 295 | const override; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 296 | |
[email protected] | 13ed17f8 | 2012-04-06 02:27:18 | [diff] [blame] | 297 | protected: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 298 | ~SystemURLRequestContextGetter() override; |
[email protected] | 13ed17f8 | 2012-04-06 02:27:18 | [diff] [blame] | 299 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 300 | private: |
| 301 | IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess. |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 302 | scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 303 | |
| 304 | base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; |
| 305 | }; |
| 306 | |
| 307 | SystemURLRequestContextGetter::SystemURLRequestContextGetter( |
| 308 | IOThread* io_thread) |
| 309 | : io_thread_(io_thread), |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 310 | network_task_runner_( |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 311 | BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)) {} |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 312 | |
| 313 | SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} |
| 314 | |
| 315 | net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 316 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 317 | DCHECK(io_thread_->globals()->system_request_context.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 318 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 319 | return io_thread_->globals()->system_request_context.get(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 320 | } |
| 321 | |
[email protected] | 4969b012 | 2012-06-16 01:58:28 | [diff] [blame] | 322 | scoped_refptr<base::SingleThreadTaskRunner> |
| 323 | SystemURLRequestContextGetter::GetNetworkTaskRunner() const { |
| 324 | return network_task_runner_; |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 325 | } |
| 326 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 327 | IOThread::Globals:: |
| 328 | SystemRequestContextLeakChecker::SystemRequestContextLeakChecker( |
| 329 | Globals* globals) |
| 330 | : globals_(globals) { |
| 331 | DCHECK(globals_); |
[email protected] | 7613faae | 2012-04-18 01:01:19 | [diff] [blame] | 332 | } |
[email protected] | 1889dc1b | 2010-10-14 22:03:13 | [diff] [blame] | 333 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 334 | IOThread::Globals:: |
| 335 | SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() { |
| 336 | if (globals_->system_request_context.get()) |
| 337 | globals_->system_request_context->AssertNoURLRequests(); |
| 338 | } |
| 339 | |
maksim.sisov | 3d40c81 | 2016-05-02 13:27:16 | [diff] [blame] | 340 | IOThread::Globals::Globals() : system_request_context_leak_checker(this), |
| 341 | enable_brotli(false) {} |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 342 | |
[email protected] | c93123fa | 2012-04-19 02:49:48 | [diff] [blame] | 343 | IOThread::Globals::~Globals() {} |
| 344 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 345 | // |local_state| is passed in explicitly in order to (1) reduce implicit |
| 346 | // dependencies and (2) make IOThread more flexible for testing. |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 347 | IOThread::IOThread( |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 348 | PrefService* local_state, |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 349 | policy::PolicyService* policy_service, |
droger | c690e880 | 2015-09-21 14:29:16 | [diff] [blame] | 350 | net_log::ChromeNetLog* net_log, |
[email protected] | 5a38dfd | 2012-07-23 23:22:10 | [diff] [blame] | 351 | extensions::EventRouterForwarder* extension_event_router_forwarder) |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 352 | : net_log_(net_log), |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 353 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 354 | extension_event_router_forwarder_(extension_event_router_forwarder), |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 355 | #endif |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 356 | globals_(nullptr), |
peletskyi | 5df83d4 | 2015-04-30 16:37:46 | [diff] [blame] | 357 | is_quic_allowed_by_policy_(true), |
mmenke | 82d19a58 | 2017-01-27 23:26:32 | [diff] [blame] | 358 | http_09_on_non_default_ports_enabled_(false), |
mohan.reddy | 14cb4ad4 | 2014-09-17 18:15:14 | [diff] [blame] | 359 | creation_time_(base::TimeTicks::Now()), |
| 360 | weak_factory_(this) { |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 361 | scoped_refptr<base::SingleThreadTaskRunner> io_thread_proxy = |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 362 | BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 363 | auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 364 | negotiate_disable_cname_lookup_.Init( |
| 365 | prefs::kDisableAuthNegotiateCnameLookup, local_state, |
| 366 | base::Bind(&IOThread::UpdateNegotiateDisableCnameLookup, |
| 367 | base::Unretained(this))); |
| 368 | negotiate_disable_cname_lookup_.MoveToThread(io_thread_proxy); |
| 369 | negotiate_enable_port_.Init( |
| 370 | prefs::kEnableAuthNegotiatePort, local_state, |
| 371 | base::Bind(&IOThread::UpdateNegotiateEnablePort, base::Unretained(this))); |
| 372 | negotiate_enable_port_.MoveToThread(io_thread_proxy); |
| 373 | auth_server_whitelist_.Init( |
| 374 | prefs::kAuthServerWhitelist, local_state, |
| 375 | base::Bind(&IOThread::UpdateServerWhitelist, base::Unretained(this))); |
| 376 | auth_server_whitelist_.MoveToThread(io_thread_proxy); |
| 377 | auth_delegate_whitelist_.Init( |
| 378 | prefs::kAuthNegotiateDelegateWhitelist, local_state, |
| 379 | base::Bind(&IOThread::UpdateDelegateWhitelist, base::Unretained(this))); |
| 380 | auth_delegate_whitelist_.MoveToThread(io_thread_proxy); |
| 381 | #if defined(OS_ANDROID) |
| 382 | auth_android_negotiate_account_type_.Init( |
| 383 | prefs::kAuthAndroidNegotiateAccountType, local_state, |
| 384 | base::Bind(&IOThread::UpdateAndroidAuthNegotiateAccountType, |
| 385 | base::Unretained(this))); |
| 386 | auth_android_negotiate_account_type_.MoveToThread(io_thread_proxy); |
| 387 | #endif |
| 388 | #if defined(OS_POSIX) && !defined(OS_ANDROID) |
[email protected] | ac7f3fdb | 2010-11-12 12:47:05 | [diff] [blame] | 389 | gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 390 | #endif |
zentaro | e032635 | 2017-05-09 13:11:51 | [diff] [blame^] | 391 | #if defined(OS_CHROMEOS) |
| 392 | policy::BrowserPolicyConnectorChromeOS* connector = |
| 393 | g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 394 | allow_gssapi_library_load_ = connector->IsActiveDirectoryManaged(); |
| 395 | #endif |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 396 | pref_proxy_config_tracker_.reset( |
[email protected] | e2930d090 | 2013-07-17 05:25:42 | [diff] [blame] | 397 | ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState( |
| 398 | local_state)); |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 399 | ChromeNetworkDelegate::InitializePrefsOnUIThread( |
| 400 | &system_enable_referrers_, |
igorcov | 193d8ad3 | 2016-05-27 11:03:21 | [diff] [blame] | 401 | nullptr, |
| 402 | nullptr, |
| 403 | nullptr, |
| 404 | nullptr, |
[email protected] | 9d8cfb68 | 2012-09-13 16:48:04 | [diff] [blame] | 405 | local_state); |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 406 | ssl_config_service_manager_.reset( |
abhishek.a21 | 2849cee | 2015-10-20 11:27:29 | [diff] [blame] | 407 | ssl_config::SSLConfigServiceManager::CreateDefaultManager( |
| 408 | local_state, |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 409 | BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 410 | |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 411 | base::Value* dns_client_enabled_default = |
| 412 | new base::Value(chrome_browser_net::ConfigureAsyncDnsFieldTrial()); |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 413 | local_state->SetDefaultPrefValue(prefs::kBuiltInDnsClientEnabled, |
| 414 | dns_client_enabled_default); |
ttuttle | 53018496 | 2015-01-13 00:24:07 | [diff] [blame] | 415 | chrome_browser_net::LogAsyncDnsPrefSource( |
| 416 | local_state->FindPreference(prefs::kBuiltInDnsClientEnabled)); |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 417 | |
[email protected] | fa4b6c3 | 2012-11-26 23:02:39 | [diff] [blame] | 418 | dns_client_enabled_.Init(prefs::kBuiltInDnsClientEnabled, |
| 419 | local_state, |
| 420 | base::Bind(&IOThread::UpdateDnsClientEnabled, |
| 421 | base::Unretained(this))); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 422 | dns_client_enabled_.MoveToThread(io_thread_proxy); |
[email protected] | fa4b6c3 | 2012-11-26 23:02:39 | [diff] [blame] | 423 | |
[email protected] | 6737814 | 2013-12-17 21:57:17 | [diff] [blame] | 424 | quick_check_enabled_.Init(prefs::kQuickCheckEnabled, |
| 425 | local_state); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 426 | quick_check_enabled_.MoveToThread(io_thread_proxy); |
[email protected] | 6737814 | 2013-12-17 21:57:17 | [diff] [blame] | 427 | |
eroman | 9f7ea64 | 2016-06-03 21:28:29 | [diff] [blame] | 428 | pac_https_url_stripping_enabled_.Init(prefs::kPacHttpsUrlStrippingEnabled, |
| 429 | local_state); |
| 430 | pac_https_url_stripping_enabled_.MoveToThread(io_thread_proxy); |
| 431 | |
peletskyi | 5df83d4 | 2015-04-30 16:37:46 | [diff] [blame] | 432 | const base::Value* value = policy_service->GetPolicies( |
| 433 | policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, |
| 434 | std::string())).GetValue(policy::key::kQuicAllowed); |
| 435 | if (value) |
| 436 | value->GetAsBoolean(&is_quic_allowed_by_policy_); |
[email protected] | 7730542 | 2012-11-29 16:51:39 | [diff] [blame] | 437 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 438 | value = policy_service |
| 439 | ->GetPolicies(policy::PolicyNamespace( |
| 440 | policy::POLICY_DOMAIN_CHROME, std::string())) |
| 441 | .GetValue(policy::key::kHttp09OnNonDefaultPortsEnabled); |
| 442 | if (value) |
| 443 | value->GetAsBoolean(&http_09_on_non_default_ports_enabled_); |
| 444 | |
eranm | 3c2d643 | 2016-06-01 10:17:27 | [diff] [blame] | 445 | chrome_browser_net::SetGlobalSTHDistributor( |
| 446 | std::unique_ptr<net::ct::STHDistributor>(new net::ct::STHDistributor())); |
| 447 | |
gab | 90becc9 | 2016-12-08 17:19:34 | [diff] [blame] | 448 | BrowserThread::SetIOThreadDelegate(this); |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 449 | } |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 450 | |
| 451 | IOThread::~IOThread() { |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 452 | // This isn't needed for production code, but in tests, IOThread may |
| 453 | // be multiply constructed. |
gab | 90becc9 | 2016-12-08 17:19:34 | [diff] [blame] | 454 | BrowserThread::SetIOThreadDelegate(nullptr); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 455 | |
[email protected] | d461ed2 | 2013-01-18 03:18:56 | [diff] [blame] | 456 | pref_proxy_config_tracker_->DetachFromPrefService(); |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 457 | DCHECK(!globals_); |
eranm | 3c2d643 | 2016-06-01 10:17:27 | [diff] [blame] | 458 | |
| 459 | // Destroy the old distributor to check that the observers list it holds is |
| 460 | // empty. |
| 461 | chrome_browser_net::SetGlobalSTHDistributor(nullptr); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 462 | } |
| 463 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 464 | IOThread::Globals* IOThread::globals() { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 465 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 466 | return globals_; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 467 | } |
| 468 | |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 469 | void IOThread::SetGlobalsForTesting(Globals* globals) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 470 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 37ac95b | 2013-07-23 23:39:35 | [diff] [blame] | 471 | DCHECK(!globals || !globals_); |
| 472 | globals_ = globals; |
| 473 | } |
| 474 | |
droger | c690e880 | 2015-09-21 14:29:16 | [diff] [blame] | 475 | net_log::ChromeNetLog* IOThread::net_log() { |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 476 | return net_log_; |
| 477 | } |
| 478 | |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 479 | void IOThread::ChangedToOnTheRecord() { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 480 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 481 | BrowserThread::PostTask( |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 482 | BrowserThread::IO, FROM_HERE, |
| 483 | base::BindOnce(&IOThread::ChangedToOnTheRecordOnIOThread, |
| 484 | base::Unretained(this))); |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 485 | } |
| 486 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 487 | net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 488 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 489 | if (!system_url_request_context_getter_.get()) { |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 490 | InitSystemRequestContext(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 491 | } |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 492 | return system_url_request_context_getter_.get(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 493 | } |
| 494 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 495 | void IOThread::Init() { |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 496 | TRACE_EVENT0("startup", "IOThread::InitAsync"); |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 497 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 70b9234 | 2010-10-12 05:54:06 | [diff] [blame] | 498 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 499 | #if defined(USE_NSS_CERTS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 500 | net::SetMessageLoopForNSSHttpIO(); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 501 | #endif |
[email protected] | 70b9234 | 2010-10-12 05:54:06 | [diff] [blame] | 502 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 503 | const base::CommandLine& command_line = |
| 504 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 505 | |
zhongyi | 81f85c6d9 | 2015-10-16 19:34:14 | [diff] [blame] | 506 | // Export ssl keys if log file specified. |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 507 | base::FilePath ssl_keylog_file = GetSSLKeyLogFile(command_line); |
zhongyi | 81f85c6d9 | 2015-10-16 19:34:14 | [diff] [blame] | 508 | if (!ssl_keylog_file.empty()) { |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 509 | net::SSLClientSocket::SetSSLKeyLogFile( |
| 510 | ssl_keylog_file, |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 511 | BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE)); |
zhongyi | 81f85c6d9 | 2015-10-16 19:34:14 | [diff] [blame] | 512 | } |
| 513 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 514 | DCHECK(!globals_); |
| 515 | globals_ = new Globals; |
| 516 | |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 517 | // Add an observer that will emit network change events to the ChromeNetLog. |
| 518 | // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be |
| 519 | // logging the network change before other IO thread consumers respond to it. |
| 520 | network_change_observer_.reset( |
pauljensen | 7b34e52 | 2016-05-12 18:20:59 | [diff] [blame] | 521 | new net::LoggingNetworkChangeObserver(net_log_)); |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 522 | |
[email protected] | cde8b3c | 2012-08-13 19:20:52 | [diff] [blame] | 523 | // Setup the HistogramWatcher to run on the IO thread. |
| 524 | net::NetworkChangeNotifier::InitHistogramWatcher(); |
| 525 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 526 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 527 | globals_->extension_event_router_forwarder = |
| 528 | extension_event_router_forwarder_; |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 529 | #endif |
| 530 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 531 | std::unique_ptr<data_usage::DataUseAmortizer> data_use_amortizer; |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 532 | #if defined(OS_ANDROID) |
sclittle | c441f78 | 2015-11-12 01:12:09 | [diff] [blame] | 533 | data_use_amortizer.reset(new data_usage::android::TrafficStatsAmortizer()); |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 534 | #endif // defined(OS_ANDROID) |
sclittle | c441f78 | 2015-11-12 01:12:09 | [diff] [blame] | 535 | |
kundaji | f617523b | 2016-09-09 22:41:24 | [diff] [blame] | 536 | globals_->data_use_ascriber = |
| 537 | base::MakeUnique<data_use_measurement::ChromeDataUseAscriber>(); |
| 538 | |
sclittle | 3f98c6c | 2015-11-19 22:59:29 | [diff] [blame] | 539 | globals_->data_use_aggregator.reset(new data_usage::DataUseAggregator( |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 540 | std::unique_ptr<data_usage::DataUseAnnotator>( |
sclittle | c441f78 | 2015-11-12 01:12:09 | [diff] [blame] | 541 | new chrome_browser_data_usage::TabIdAnnotator()), |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 542 | std::move(data_use_amortizer))); |
sclittle | ae932be | 2015-10-08 20:53:50 | [diff] [blame] | 543 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 544 | std::unique_ptr<ChromeNetworkDelegate> chrome_network_delegate( |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 545 | new ChromeNetworkDelegate(extension_event_router_forwarder(), |
rajendrant | 14a5a85 | 2016-11-17 17:58:48 | [diff] [blame] | 546 | &system_enable_referrers_)); |
sclittle | ae932be | 2015-10-08 20:53:50 | [diff] [blame] | 547 | // By default, data usage is considered off the record. |
| 548 | chrome_network_delegate->set_data_use_aggregator( |
sclittle | 3f98c6c | 2015-11-19 22:59:29 | [diff] [blame] | 549 | globals_->data_use_aggregator.get(), |
| 550 | true /* is_data_usage_off_the_record */); |
tbansal | 796988c | 2015-10-14 02:41:22 | [diff] [blame] | 551 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 552 | #if defined(OS_ANDROID) |
sclittle | 3f98c6c | 2015-11-19 22:59:29 | [diff] [blame] | 553 | globals_->external_data_use_observer.reset( |
tbansal | 7c98c0a | 2015-11-03 21:39:51 | [diff] [blame] | 554 | new chrome::android::ExternalDataUseObserver( |
sclittle | 3f98c6c | 2015-11-19 22:59:29 | [diff] [blame] | 555 | globals_->data_use_aggregator.get(), |
thestig | 529ad8a | 2016-07-08 20:30:12 | [diff] [blame] | 556 | BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), |
| 557 | BrowserThread::GetTaskRunnerForThread(BrowserThread::UI))); |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 558 | #endif // defined(OS_ANDROID) |
[email protected] | 84b7a55 | 2014-07-19 04:52:06 | [diff] [blame] | 559 | |
kundaji | c613596 | 2016-09-26 17:54:28 | [diff] [blame] | 560 | globals_->system_network_delegate = |
| 561 | globals_->data_use_ascriber->CreateNetworkDelegate( |
robliao | 7253fd2 | 2016-12-01 18:41:38 | [diff] [blame] | 562 | std::move(chrome_network_delegate), GetMetricsDataUseForwarder()); |
kundaji | c613596 | 2016-09-26 17:54:28 | [diff] [blame] | 563 | |
[email protected] | c54a891 | 2012-10-22 22:09:43 | [diff] [blame] | 564 | globals_->host_resolver = CreateGlobalHostResolver(net_log_); |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 565 | |
tbansal | b177b539 | 2015-06-25 11:13:02 | [diff] [blame] | 566 | std::map<std::string, std::string> network_quality_estimator_params; |
| 567 | variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName, |
| 568 | &network_quality_estimator_params); |
tbansal | 1c92d5b | 2015-08-14 20:14:43 | [diff] [blame] | 569 | |
tbansal | d3e08ca6 | 2017-05-04 19:51:09 | [diff] [blame] | 570 | if (command_line.HasSwitch(switches::kForceEffectiveConnectionType)) { |
| 571 | const std::string force_ect_value = |
| 572 | base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 573 | switches::kForceEffectiveConnectionType); |
| 574 | |
| 575 | if (!force_ect_value.empty()) { |
| 576 | // If the effective connection type is forced using command line switch, |
| 577 | // it overrides the one set by field trial. |
| 578 | network_quality_estimator_params[net::kForceEffectiveConnectionType] = |
| 579 | force_ect_value; |
| 580 | } |
| 581 | } |
| 582 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 583 | std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider; |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 584 | #if defined(OS_ANDROID) |
tbansal | 1c92d5b | 2015-08-14 20:14:43 | [diff] [blame] | 585 | external_estimate_provider.reset( |
tbansal | dafbb3e | 2015-08-19 19:55:33 | [diff] [blame] | 586 | new chrome::android::ExternalEstimateProviderAndroid()); |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 587 | #endif // defined(OS_ANDROID) |
tbansal | 1c92d5b | 2015-08-14 20:14:43 | [diff] [blame] | 588 | // Pass ownership. |
| 589 | globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator( |
tbansal | 97e38a2 | 2017-01-20 20:43:02 | [diff] [blame] | 590 | std::move(external_estimate_provider), network_quality_estimator_params, |
| 591 | net_log_)); |
tbansal | ea2fb8c | 2015-05-22 22:23:00 | [diff] [blame] | 592 | |
[email protected] | fa4b6c3 | 2012-11-26 23:02:39 | [diff] [blame] | 593 | UpdateDnsClientEnabled(); |
[email protected] | f46f6d5 | 2014-02-08 04:00:39 | [diff] [blame] | 594 | #if defined(OS_CHROMEOS) |
[email protected] | f9357a44 | 2014-05-15 18:44:07 | [diff] [blame] | 595 | // Creates a CertVerifyProc that doesn't allow any profile-provided certs. |
rsleevi | 6df5418 | 2016-06-13 14:34:23 | [diff] [blame] | 596 | globals_->cert_verifier = base::MakeUnique<net::CachingCertVerifier>( |
| 597 | base::MakeUnique<net::MultiThreadedCertVerifier>( |
| 598 | new chromeos::CertVerifyProcChromeOS())); |
[email protected] | f9357a44 | 2014-05-15 18:44:07 | [diff] [blame] | 599 | #else |
rsleevi | 6df5418 | 2016-06-13 14:34:23 | [diff] [blame] | 600 | globals_->cert_verifier = net::CertVerifier::CreateDefault(); |
[email protected] | f9357a44 | 2014-05-15 18:44:07 | [diff] [blame] | 601 | #endif |
| 602 | |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 603 | globals_->transport_security_state.reset(new net::TransportSecurityState()); |
| 604 | |
eranm | 1a79db2 | 2015-11-24 10:56:49 | [diff] [blame] | 605 | std::vector<scoped_refptr<const net::CTLogVerifier>> ct_logs( |
eranm | 03d454c | 2015-07-02 09:12:03 | [diff] [blame] | 606 | net::ct::CreateLogVerifiersForKnownLogs()); |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 607 | |
eranm | 1a79db2 | 2015-11-24 10:56:49 | [diff] [blame] | 608 | globals_->ct_logs.assign(ct_logs.begin(), ct_logs.end()); |
| 609 | |
eranm | 03d454c | 2015-07-02 09:12:03 | [diff] [blame] | 610 | net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier(); |
| 611 | globals_->cert_transparency_verifier.reset(ct_verifier); |
| 612 | // Add built-in logs |
eranm | 1a79db2 | 2015-11-24 10:56:49 | [diff] [blame] | 613 | ct_verifier->AddLogs(globals_->ct_logs); |
eranm | 03d454c | 2015-07-02 09:12:03 | [diff] [blame] | 614 | |
eranm | bbf5af70 | 2017-02-02 16:06:18 | [diff] [blame] | 615 | ct_tree_tracker_.reset(new certificate_transparency::TreeStateTracker( |
| 616 | globals_->ct_logs, net_log_)); |
eranm | 3c2d643 | 2016-06-01 10:17:27 | [diff] [blame] | 617 | // Register the ct_tree_tracker_ as observer for new STHs. |
| 618 | RegisterSTHObserver(ct_tree_tracker_.get()); |
| 619 | // Register the ct_tree_tracker_ as observer for verified SCTs. |
| 620 | globals_->cert_transparency_verifier->SetObserver(ct_tree_tracker_.get()); |
| 621 | |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 622 | globals_->ct_policy_enforcer.reset(new net::CTPolicyEnforcer()); |
| 623 | params_.ct_policy_enforcer = globals_->ct_policy_enforcer.get(); |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 624 | |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 625 | globals_->ssl_config_service = GetSSLConfigService(); |
[email protected] | f4bfa767 | 2014-08-08 09:50:46 | [diff] [blame] | 626 | |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 627 | CreateDefaultAuthHandlerFactory(); |
[email protected] | 30d4c02 | 2013-07-18 22:58:16 | [diff] [blame] | 628 | globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl()); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 629 | // For the ProxyScriptFetcher, we use a direct ProxyService. |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 630 | globals_->proxy_script_fetcher_proxy_service = |
| 631 | net::ProxyService::CreateDirectWithNetLog(net_log_); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 632 | // In-memory cookie store. |
[email protected] | 9a6c2aa | 2014-01-11 22:39:39 | [diff] [blame] | 633 | globals_->system_cookie_store = |
mmenke | 606c59c | 2016-03-07 18:20:55 | [diff] [blame] | 634 | content::CreateCookieStore(content::CookieStoreConfig()); |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 635 | // In-memory channel ID store. |
| 636 | globals_->system_channel_id_service.reset( |
fdoray | a89e673c | 2017-01-31 21:44:21 | [diff] [blame] | 637 | new net::ChannelIDService(new net::DefaultChannelIDStore(NULL))); |
nharper | 3876dd56 | 2016-03-29 22:52:32 | [diff] [blame] | 638 | globals_->system_cookie_store->SetChannelIDServiceID( |
| 639 | globals_->system_channel_id_service->GetUniqueID()); |
[email protected] | 4588b3d | 2012-11-14 00:37:38 | [diff] [blame] | 640 | globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService()); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 641 | globals_->host_mapping_rules.reset(new net::HostMappingRules()); |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 642 | params_.host_mapping_rules = globals_->host_mapping_rules.get(); |
[email protected] | ee4c30d | 2012-11-07 15:08:43 | [diff] [blame] | 643 | globals_->http_user_agent_settings.reset( |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 644 | new net::StaticHttpUserAgentSettings(std::string(), GetUserAgent())); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 645 | if (command_line.HasSwitch(switches::kHostRules)) { |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 646 | TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:SetRulesFromString"); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 647 | globals_->host_mapping_rules->SetRulesFromString( |
| 648 | command_line.GetSwitchValueASCII(switches::kHostRules)); |
[email protected] | a5e73b8 | 2013-07-17 08:58:39 | [diff] [blame] | 649 | TRACE_EVENT_END0("startup", "IOThread::InitAsync:SetRulesFromString"); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 650 | } |
maksim.sisov | 3d40c81 | 2016-05-02 13:27:16 | [diff] [blame] | 651 | globals_->enable_brotli = |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 652 | base::FeatureList::IsEnabled(features::kBrotliEncoding); |
| 653 | params_.enable_token_binding = |
nharper | ef261864 | 2016-02-03 22:23:44 | [diff] [blame] | 654 | base::FeatureList::IsEnabled(features::kTokenBinding); |
bnc | e87c7c71 | 2016-08-01 23:59:48 | [diff] [blame] | 655 | |
| 656 | // Check for OS support of TCP FastOpen, and turn it on for all connections if |
| 657 | // indicated by user. |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 658 | // TODO(rch): Make the client socket factory a per-network session instance, |
| 659 | // constructed from a NetworkSession::Params, to allow us to move this option |
| 660 | // to IOThread::Globals & HttpNetworkSession::Params. |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 661 | bool always_enable_tfo_if_supported = |
| 662 | command_line.HasSwitch(switches::kEnableTcpFastOpen); |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 663 | net::CheckSupportAndMaybeEnableTCPFastOpen(always_enable_tfo_if_supported); |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 664 | |
bnc | e87c7c71 | 2016-08-01 23:59:48 | [diff] [blame] | 665 | ConfigureParamsFromFieldTrialsAndCommandLine( |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 666 | command_line, is_quic_allowed_by_policy_, |
| 667 | http_09_on_non_default_ports_enabled_, ¶ms_); |
bnc | e87c7c71 | 2016-08-01 23:59:48 | [diff] [blame] | 668 | |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 669 | TRACE_EVENT_BEGIN0("startup", |
| 670 | "IOThread::Init:ProxyScriptFetcherRequestContext"); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 671 | globals_->proxy_script_fetcher_context.reset( |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 672 | ConstructProxyScriptFetcherContext(globals_, params_, net_log_)); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 673 | TRACE_EVENT_END0("startup", |
| 674 | "IOThread::Init:ProxyScriptFetcherRequestContext"); |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 675 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 676 | #if defined(OS_MACOSX) |
[email protected] | 11f5e3a | 2012-09-27 00:30:13 | [diff] [blame] | 677 | // Start observing Keychain events. This needs to be done on the UI thread, |
| 678 | // as Keychain services requires a CFRunLoop. |
| 679 | BrowserThread::PostTask(BrowserThread::UI, |
| 680 | FROM_HERE, |
| 681 | base::Bind(&ObserveKeychainEvents)); |
| 682 | #endif |
| 683 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 684 | // InitSystemRequestContext turns right around and posts a task back |
| 685 | // to the IO thread, so we can't let it run until we know the IO |
| 686 | // thread has started. |
| 687 | // |
| 688 | // Note that since we are at BrowserThread::Init time, the UI thread |
| 689 | // is blocked waiting for the thread to start. Therefore, posting |
| 690 | // this task to the main thread's message loop here is guaranteed to |
| 691 | // get it onto the message loop while the IOThread object still |
| 692 | // exists. However, the message might not be processed on the UI |
| 693 | // thread until after IOThread is gone, so use a weak pointer. |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 694 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 695 | base::BindOnce(&IOThread::InitSystemRequestContext, |
| 696 | weak_factory_.GetWeakPtr())); |
davidben | 45eb1995 | 2016-05-05 16:30:44 | [diff] [blame] | 697 | |
| 698 | #if defined(OS_ANDROID) && defined(ARCH_CPU_ARMEL) |
| 699 | // Record how common CPUs with broken NEON units are. See |
| 700 | // https://crbug.com/341598. |
| 701 | crypto::EnsureOpenSSLInit(); |
| 702 | UMA_HISTOGRAM_BOOLEAN("Net.HasBrokenNEON", CRYPTO_has_broken_NEON()); |
| 703 | #endif |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 704 | } |
| 705 | |
[email protected] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 706 | void IOThread::CleanUp() { |
[email protected] | 075c032 | 2012-02-14 00:56:44 | [diff] [blame] | 707 | base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks(); |
| 708 | |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 709 | #if defined(USE_NSS_CERTS) |
[email protected] | 8c434cbc | 2012-03-14 14:25:09 | [diff] [blame] | 710 | net::ShutdownNSSHttpIO(); |
[email protected] | a592c043 | 2012-12-01 18:10:29 | [diff] [blame] | 711 | #endif |
[email protected] | 59a3b36 | 2010-10-21 21:52:41 | [diff] [blame] | 712 | |
estark | 9a26378 | 2017-01-20 02:13:04 | [diff] [blame] | 713 | #if defined(OS_ANDROID) |
| 714 | net::CertVerifyProcAndroid::ShutdownCertNetFetcher(); |
| 715 | #endif |
| 716 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 717 | system_url_request_context_getter_ = NULL; |
| 718 | |
eranm | 3c2d643 | 2016-06-01 10:17:27 | [diff] [blame] | 719 | // Unlink the ct_tree_tracker_ from the global cert_transparency_verifier |
| 720 | // and unregister it from new STH notifications so it will take no actions |
| 721 | // on anything observed during CleanUp process. |
| 722 | globals()->cert_transparency_verifier->SetObserver(nullptr); |
| 723 | UnregisterSTHObserver(ct_tree_tracker_.get()); |
| 724 | |
| 725 | ct_tree_tracker_.reset(); |
| 726 | |
[email protected] | af66993 | 2012-01-17 19:26:58 | [diff] [blame] | 727 | // Release objects that the net::URLRequestContext could have been pointing |
| 728 | // to. |
[email protected] | 0ee7a3b | 2010-11-09 06:13:40 | [diff] [blame] | 729 | |
[email protected] | 7592b41f | 2014-04-01 01:44:43 | [diff] [blame] | 730 | // Shutdown the HistogramWatcher on the IO thread. |
| 731 | net::NetworkChangeNotifier::ShutdownHistogramWatcher(); |
| 732 | |
[email protected] | 0ee7a3b | 2010-11-09 06:13:40 | [diff] [blame] | 733 | // This must be reset before the ChromeNetLog is destroyed. |
| 734 | network_change_observer_.reset(); |
| 735 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 736 | system_proxy_config_service_.reset(); |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 737 | delete globals_; |
| 738 | globals_ = NULL; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 739 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 740 | base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 741 | } |
| 742 | |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 743 | // static |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 744 | void IOThread::RegisterPrefs(PrefRegistrySimple* registry) { |
| 745 | registry->RegisterStringPref(prefs::kAuthSchemes, |
bengr | 70266e2 | 2015-06-12 19:38:17 | [diff] [blame] | 746 | "basic,digest,ntlm,negotiate"); |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 747 | registry->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, false); |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 748 | registry->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 749 | registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string()); |
| 750 | registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist, |
| 751 | std::string()); |
| 752 | registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string()); |
aberent | ec894a5 | 2015-07-09 14:45:53 | [diff] [blame] | 753 | registry->RegisterStringPref(prefs::kAuthAndroidNegotiateAccountType, |
| 754 | std::string()); |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 755 | registry->RegisterBooleanPref(prefs::kEnableReferrers, true); |
[email protected] | 1575e3d | 2014-05-03 22:21:44 | [diff] [blame] | 756 | data_reduction_proxy::RegisterPrefs(registry); |
[email protected] | 68a9b0d8 | 2013-03-08 07:05:07 | [diff] [blame] | 757 | registry->RegisterBooleanPref(prefs::kBuiltInDnsClientEnabled, true); |
[email protected] | 6737814 | 2013-12-17 21:57:17 | [diff] [blame] | 758 | registry->RegisterBooleanPref(prefs::kQuickCheckEnabled, true); |
eroman | 9f7ea64 | 2016-06-03 21:28:29 | [diff] [blame] | 759 | registry->RegisterBooleanPref(prefs::kPacHttpsUrlStrippingEnabled, true); |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 760 | } |
| 761 | |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 762 | void IOThread::UpdateServerWhitelist() { |
| 763 | globals_->http_auth_preferences->set_server_whitelist( |
| 764 | auth_server_whitelist_.GetValue()); |
| 765 | } |
[email protected] | b730416 | 2010-08-23 17:42:29 | [diff] [blame] | 766 | |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 767 | void IOThread::UpdateDelegateWhitelist() { |
| 768 | globals_->http_auth_preferences->set_delegate_whitelist( |
| 769 | auth_delegate_whitelist_.GetValue()); |
| 770 | } |
| 771 | |
| 772 | #if defined(OS_ANDROID) |
| 773 | void IOThread::UpdateAndroidAuthNegotiateAccountType() { |
| 774 | globals_->http_auth_preferences->set_auth_android_negotiate_account_type( |
| 775 | auth_android_negotiate_account_type_.GetValue()); |
| 776 | } |
| 777 | #endif |
| 778 | |
| 779 | void IOThread::UpdateNegotiateDisableCnameLookup() { |
| 780 | globals_->http_auth_preferences->set_negotiate_disable_cname_lookup( |
| 781 | negotiate_disable_cname_lookup_.GetValue()); |
| 782 | } |
| 783 | |
| 784 | void IOThread::UpdateNegotiateEnablePort() { |
| 785 | globals_->http_auth_preferences->set_negotiate_enable_port( |
| 786 | negotiate_enable_port_.GetValue()); |
| 787 | } |
| 788 | |
| 789 | void IOThread::CreateDefaultAuthHandlerFactory() { |
| 790 | std::vector<std::string> supported_schemes = base::SplitString( |
| 791 | auth_schemes_, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 792 | globals_->http_auth_preferences.reset(new net::HttpAuthPreferences( |
| 793 | supported_schemes |
| 794 | #if defined(OS_POSIX) && !defined(OS_ANDROID) |
| 795 | , |
| 796 | gssapi_library_name_ |
| 797 | #endif |
zentaro | e032635 | 2017-05-09 13:11:51 | [diff] [blame^] | 798 | #if defined(OS_CHROMEOS) |
| 799 | , |
| 800 | allow_gssapi_library_load_ |
| 801 | #endif |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 802 | )); |
| 803 | UpdateServerWhitelist(); |
| 804 | UpdateDelegateWhitelist(); |
| 805 | UpdateNegotiateDisableCnameLookup(); |
| 806 | UpdateNegotiateEnablePort(); |
| 807 | #if defined(OS_ANDROID) |
| 808 | UpdateAndroidAuthNegotiateAccountType(); |
| 809 | #endif |
| 810 | globals_->http_auth_handler_factory = |
[email protected] | ec44ee0 | 2012-09-28 21:31:51 | [diff] [blame] | 811 | net::HttpAuthHandlerRegistryFactory::Create( |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 812 | globals_->http_auth_preferences.get(), globals_->host_resolver.get()); |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 813 | } |
| 814 | |
msramek | 94f5656c | 2016-08-31 17:08:29 | [diff] [blame] | 815 | void IOThread::ClearHostCache( |
| 816 | const base::Callback<bool(const std::string&)>& host_filter) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 817 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | d6f37fc | 2011-02-13 23:58:41 | [diff] [blame] | 818 | |
[email protected] | 489d1a8 | 2011-10-12 03:09:11 | [diff] [blame] | 819 | net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); |
| 820 | if (host_cache) |
msramek | 94f5656c | 2016-08-31 17:08:29 | [diff] [blame] | 821 | host_cache->ClearForHosts(host_filter); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 822 | } |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 823 | |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 824 | const net::HttpNetworkSession::Params& IOThread::NetworkSessionParams() const { |
| 825 | return params_; |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 826 | } |
| 827 | |
pmarko | 6ab8be24 | 2017-01-11 11:02:55 | [diff] [blame] | 828 | void IOThread::DisableQuic() { |
| 829 | params_.enable_quic = false; |
| 830 | |
| 831 | if (globals_->system_http_network_session) |
| 832 | globals_->system_http_network_session->DisableQuic(); |
| 833 | |
| 834 | if (globals_->proxy_script_fetcher_http_network_session) |
| 835 | globals_->proxy_script_fetcher_http_network_session->DisableQuic(); |
| 836 | } |
| 837 | |
[email protected] | d827e11 | 2014-03-31 17:45:05 | [diff] [blame] | 838 | base::TimeTicks IOThread::creation_time() const { |
| 839 | return creation_time_; |
| 840 | } |
| 841 | |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 842 | net::SSLConfigService* IOThread::GetSSLConfigService() { |
| 843 | return ssl_config_service_manager_->Get(); |
| 844 | } |
| 845 | |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 846 | void IOThread::ChangedToOnTheRecordOnIOThread() { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 847 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 848 | |
| 849 | // Clear the host cache to avoid showing entries from the OTR session |
| 850 | // in about:net-internals. |
msramek | 94f5656c | 2016-08-31 17:08:29 | [diff] [blame] | 851 | ClearHostCache(base::Callback<bool(const std::string&)>()); |
[email protected] | b09f76d6 | 2011-12-07 01:51:06 | [diff] [blame] | 852 | } |
| 853 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 854 | void IOThread::InitSystemRequestContext() { |
[email protected] | 5173de8b | 2013-06-02 21:16:02 | [diff] [blame] | 855 | if (system_url_request_context_getter_.get()) |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 856 | return; |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 857 | // If we're in unit_tests, IOThread may not be run. |
[email protected] | dd48370 | 2011-12-02 14:47:42 | [diff] [blame] | 858 | if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO)) |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 859 | return; |
csharrison | b7e3a08 | 2015-09-22 19:13:04 | [diff] [blame] | 860 | system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService( |
| 861 | pref_proxy_config_tracker_.get()); |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 862 | system_url_request_context_getter_ = |
| 863 | new SystemURLRequestContextGetter(this); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 864 | // Safe to post an unretained this pointer, since IOThread is |
| 865 | // guaranteed to outlive the IO BrowserThread. |
[email protected] | dd48370 | 2011-12-02 14:47:42 | [diff] [blame] | 866 | BrowserThread::PostTask( |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 867 | BrowserThread::IO, FROM_HERE, |
| 868 | base::BindOnce(&IOThread::InitSystemRequestContextOnIOThread, |
| 869 | base::Unretained(this))); |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | void IOThread::InitSystemRequestContextOnIOThread() { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 873 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 874 | DCHECK(!globals_->system_proxy_service.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 875 | DCHECK(system_proxy_config_service_.get()); |
| 876 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 877 | const base::CommandLine& command_line = |
| 878 | *base::CommandLine::ForCurrentProcess(); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 879 | globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService( |
| 880 | net_log_, globals_->proxy_script_fetcher_context.get(), |
| 881 | globals_->system_network_delegate.get(), |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 882 | std::move(system_proxy_config_service_), command_line, |
eroman | 9f7ea64 | 2016-06-03 21:28:29 | [diff] [blame] | 883 | WpadQuickCheckEnabled(), PacHttpsUrlStrippingEnabled()); |
[email protected] | c2dad29 | 2012-09-07 21:27:35 | [diff] [blame] | 884 | |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 885 | globals_->system_request_context.reset( |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 886 | ConstructSystemRequestContext(globals_, params_, net_log_)); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 887 | } |
[email protected] | fa4b6c3 | 2012-11-26 23:02:39 | [diff] [blame] | 888 | |
| 889 | void IOThread::UpdateDnsClientEnabled() { |
| 890 | globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_); |
| 891 | } |
[email protected] | 903e6338 | 2013-06-01 00:40:58 | [diff] [blame] | 892 | |
eranm | 3c2d643 | 2016-06-01 10:17:27 | [diff] [blame] | 893 | void IOThread::RegisterSTHObserver(net::ct::STHObserver* observer) { |
| 894 | chrome_browser_net::GetGlobalSTHDistributor()->RegisterObserver(observer); |
| 895 | } |
| 896 | |
| 897 | void IOThread::UnregisterSTHObserver(net::ct::STHObserver* observer) { |
| 898 | chrome_browser_net::GetGlobalSTHDistributor()->UnregisterObserver(observer); |
| 899 | } |
| 900 | |
eroman | 9f7ea64 | 2016-06-03 21:28:29 | [diff] [blame] | 901 | bool IOThread::WpadQuickCheckEnabled() const { |
| 902 | return quick_check_enabled_.GetValue(); |
| 903 | } |
| 904 | |
| 905 | bool IOThread::PacHttpsUrlStrippingEnabled() const { |
| 906 | return pac_https_url_stripping_enabled_.GetValue(); |
| 907 | } |
| 908 | |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 909 | // static |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 910 | net::URLRequestContext* IOThread::ConstructSystemRequestContext( |
| 911 | IOThread::Globals* globals, |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 912 | const net::HttpNetworkSession::Params& params, |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 913 | net::NetLog* net_log) { |
| 914 | net::URLRequestContext* context = new SystemURLRequestContext; |
mmenke | 518c27b | 2017-05-04 23:15:21 | [diff] [blame] | 915 | |
| 916 | context->set_network_quality_estimator( |
| 917 | globals->network_quality_estimator.get()); |
| 918 | context->set_enable_brotli(globals->enable_brotli); |
| 919 | context->set_name("system"); |
| 920 | |
| 921 | context->set_http_user_agent_settings( |
| 922 | globals->http_user_agent_settings.get()); |
| 923 | context->set_network_delegate(globals->system_network_delegate.get()); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 924 | context->set_net_log(net_log); |
| 925 | context->set_host_resolver(globals->host_resolver.get()); |
mmenke | 518c27b | 2017-05-04 23:15:21 | [diff] [blame] | 926 | context->set_proxy_service(globals->system_proxy_service.get()); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 927 | context->set_ssl_config_service(globals->ssl_config_service.get()); |
| 928 | context->set_http_auth_handler_factory( |
| 929 | globals->http_auth_handler_factory.get()); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 930 | |
| 931 | context->set_cookie_store(globals->system_cookie_store.get()); |
| 932 | context->set_channel_id_service( |
| 933 | globals->system_channel_id_service.get()); |
mmenke | 518c27b | 2017-05-04 23:15:21 | [diff] [blame] | 934 | context->set_transport_security_state( |
| 935 | globals->transport_security_state.get()); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 936 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 937 | context->set_http_server_properties(globals->http_server_properties.get()); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 938 | |
mmenke | 518c27b | 2017-05-04 23:15:21 | [diff] [blame] | 939 | context->set_cert_verifier(globals->cert_verifier.get()); |
| 940 | context->set_cert_transparency_verifier( |
| 941 | globals->cert_transparency_verifier.get()); |
| 942 | context->set_ct_policy_enforcer(globals->ct_policy_enforcer.get()); |
maksim.sisov | 3d40c81 | 2016-05-02 13:27:16 | [diff] [blame] | 943 | |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 944 | net::HttpNetworkSession::Params system_params(params); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 945 | net::URLRequestContextBuilder::SetHttpNetworkSessionComponents( |
| 946 | context, &system_params); |
| 947 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 948 | globals->system_http_network_session.reset( |
| 949 | new net::HttpNetworkSession(system_params)); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 950 | globals->system_http_transaction_factory.reset( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 951 | new net::HttpNetworkLayer(globals->system_http_network_session.get())); |
mmenke | 518c27b | 2017-05-04 23:15:21 | [diff] [blame] | 952 | |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 953 | context->set_http_transaction_factory( |
| 954 | globals->system_http_transaction_factory.get()); |
| 955 | |
mmenke | 518c27b | 2017-05-04 23:15:21 | [diff] [blame] | 956 | globals->system_url_request_job_factory.reset( |
| 957 | new net::URLRequestJobFactoryImpl()); |
| 958 | context->set_job_factory(globals->system_url_request_job_factory.get()); |
| 959 | |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 960 | return context; |
| 961 | } |
| 962 | |
bnc | 0f6bff6 | 2016-04-05 16:51:09 | [diff] [blame] | 963 | // static |
bnc | e87c7c71 | 2016-08-01 23:59:48 | [diff] [blame] | 964 | void IOThread::ConfigureParamsFromFieldTrialsAndCommandLine( |
| 965 | const base::CommandLine& command_line, |
| 966 | bool is_quic_allowed_by_policy, |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 967 | bool http_09_on_non_default_ports_enabled, |
bnc | e87c7c71 | 2016-08-01 23:59:48 | [diff] [blame] | 968 | net::HttpNetworkSession::Params* params) { |
| 969 | std::string quic_user_agent_id = chrome::GetChannelString(); |
| 970 | if (!quic_user_agent_id.empty()) |
| 971 | quic_user_agent_id.push_back(' '); |
| 972 | quic_user_agent_id.append( |
| 973 | version_info::GetProductNameAndVersionForUserAgent()); |
| 974 | quic_user_agent_id.push_back(' '); |
| 975 | quic_user_agent_id.append(content::BuildOSCpuInfo()); |
| 976 | |
| 977 | bool is_quic_force_disabled = !is_quic_allowed_by_policy || |
| 978 | command_line.HasSwitch(switches::kDisableQuic); |
| 979 | bool is_quic_force_enabled = command_line.HasSwitch(switches::kEnableQuic); |
| 980 | |
| 981 | network_session_configurator::ParseFieldTrials(is_quic_force_disabled, |
| 982 | is_quic_force_enabled, |
| 983 | quic_user_agent_id, params); |
| 984 | |
| 985 | // Command line flags override field trials. |
| 986 | if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests)) |
| 987 | net::URLFetcher::SetIgnoreCertificateRequests(true); |
| 988 | |
| 989 | if (command_line.HasSwitch(switches::kDisableHttp2)) |
| 990 | params->enable_http2 = false; |
| 991 | |
bnc | e87c7c71 | 2016-08-01 23:59:48 | [diff] [blame] | 992 | if (params->enable_quic) { |
| 993 | if (command_line.HasSwitch(switches::kQuicConnectionOptions)) { |
| 994 | params->quic_connection_options = |
rch | 4c967ea | 2016-12-22 01:41:07 | [diff] [blame] | 995 | net::ParseQuicConnectionOptions( |
bnc | e87c7c71 | 2016-08-01 23:59:48 | [diff] [blame] | 996 | command_line.GetSwitchValueASCII( |
| 997 | switches::kQuicConnectionOptions)); |
| 998 | } |
| 999 | |
bnc | e87c7c71 | 2016-08-01 23:59:48 | [diff] [blame] | 1000 | if (command_line.HasSwitch(switches::kQuicMaxPacketLength)) { |
| 1001 | unsigned value; |
| 1002 | if (base::StringToUint( |
| 1003 | command_line.GetSwitchValueASCII(switches::kQuicMaxPacketLength), |
| 1004 | &value)) { |
| 1005 | params->quic_max_packet_length = value; |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | if (command_line.HasSwitch(switches::kQuicVersion)) { |
| 1010 | net::QuicVersion version = network_session_configurator::ParseQuicVersion( |
| 1011 | command_line.GetSwitchValueASCII(switches::kQuicVersion)); |
| 1012 | if (version != net::QUIC_VERSION_UNSUPPORTED) { |
| 1013 | net::QuicVersionVector supported_versions; |
| 1014 | supported_versions.push_back(version); |
| 1015 | params->quic_supported_versions = supported_versions; |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) { |
| 1020 | std::string origins = |
| 1021 | command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn); |
| 1022 | for (const std::string& host_port : base::SplitString( |
| 1023 | origins, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 1024 | if (host_port == "*") |
| 1025 | params->origins_to_force_quic_on.insert(net::HostPortPair()); |
| 1026 | net::HostPortPair quic_origin = |
| 1027 | net::HostPortPair::FromString(host_port); |
| 1028 | if (!quic_origin.IsEmpty()) |
| 1029 | params->origins_to_force_quic_on.insert(quic_origin); |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | // Parameters only controlled by command line. |
| 1035 | if (command_line.HasSwitch(switches::kEnableUserAlternateProtocolPorts)) { |
| 1036 | params->enable_user_alternate_protocol_ports = true; |
| 1037 | } |
martinkr | fc8514d | 2017-01-20 01:37:11 | [diff] [blame] | 1038 | if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) { |
bnc | e87c7c71 | 2016-08-01 23:59:48 | [diff] [blame] | 1039 | params->ignore_certificate_errors = true; |
martinkr | fc8514d | 2017-01-20 01:37:11 | [diff] [blame] | 1040 | } |
| 1041 | UMA_HISTOGRAM_BOOLEAN( |
| 1042 | "Net.Certificate.IgnoreErrors", |
| 1043 | command_line.HasSwitch(switches::kIgnoreCertificateErrors)); |
bnc | e87c7c71 | 2016-08-01 23:59:48 | [diff] [blame] | 1044 | if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { |
| 1045 | params->testing_fixed_http_port = |
| 1046 | GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort); |
| 1047 | } |
| 1048 | if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { |
| 1049 | params->testing_fixed_https_port = |
| 1050 | GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort); |
| 1051 | } |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 1052 | |
| 1053 | params->http_09_on_non_default_ports_enabled = |
| 1054 | http_09_on_non_default_ports_enabled; |
bnc | e87c7c71 | 2016-08-01 23:59:48 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | // static |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 1058 | net::URLRequestContext* IOThread::ConstructProxyScriptFetcherContext( |
| 1059 | IOThread::Globals* globals, |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 1060 | const net::HttpNetworkSession::Params& params, |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 1061 | net::NetLog* net_log) { |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 1062 | net::URLRequestContext* context = new net::URLRequestContext; |
| 1063 | context->set_net_log(net_log); |
| 1064 | context->set_host_resolver(globals->host_resolver.get()); |
| 1065 | context->set_cert_verifier(globals->cert_verifier.get()); |
| 1066 | context->set_transport_security_state( |
| 1067 | globals->transport_security_state.get()); |
| 1068 | context->set_cert_transparency_verifier( |
| 1069 | globals->cert_transparency_verifier.get()); |
rsleevi | d6de830 | 2016-06-21 01:33:20 | [diff] [blame] | 1070 | context->set_ct_policy_enforcer(globals->ct_policy_enforcer.get()); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 1071 | context->set_ssl_config_service(globals->ssl_config_service.get()); |
| 1072 | context->set_http_auth_handler_factory( |
| 1073 | globals->http_auth_handler_factory.get()); |
| 1074 | context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); |
| 1075 | |
| 1076 | context->set_job_factory( |
| 1077 | globals->proxy_script_fetcher_url_request_job_factory.get()); |
| 1078 | |
| 1079 | context->set_cookie_store(globals->system_cookie_store.get()); |
| 1080 | context->set_channel_id_service( |
| 1081 | globals->system_channel_id_service.get()); |
| 1082 | context->set_network_delegate(globals->system_network_delegate.get()); |
| 1083 | context->set_http_user_agent_settings( |
| 1084 | globals->http_user_agent_settings.get()); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 1085 | context->set_http_server_properties(globals->http_server_properties.get()); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 1086 | |
maksim.sisov | 3d40c81 | 2016-05-02 13:27:16 | [diff] [blame] | 1087 | context->set_enable_brotli(globals->enable_brotli); |
| 1088 | |
bnc | 18fb77f | 2016-04-04 20:54:04 | [diff] [blame] | 1089 | net::HttpNetworkSession::Params session_params(params); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 1090 | net::URLRequestContextBuilder::SetHttpNetworkSessionComponents( |
| 1091 | context, &session_params); |
| 1092 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1093 | globals->proxy_script_fetcher_http_network_session.reset( |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 1094 | new net::HttpNetworkSession(session_params)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1095 | globals->proxy_script_fetcher_http_transaction_factory.reset( |
| 1096 | new net::HttpNetworkLayer( |
| 1097 | globals->proxy_script_fetcher_http_network_session.get())); |
xunjieli | 96ab36a7 | 2016-12-05 21:36:05 | [diff] [blame] | 1098 | context->set_name("proxy"); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 1099 | context->set_http_transaction_factory( |
| 1100 | globals->proxy_script_fetcher_http_transaction_factory.get()); |
| 1101 | |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 1102 | std::unique_ptr<net::URLRequestJobFactoryImpl> job_factory( |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 1103 | new net::URLRequestJobFactoryImpl()); |
| 1104 | |
ricea | 86fa1dd | 2016-09-13 05:59:45 | [diff] [blame] | 1105 | job_factory->SetProtocolHandler(url::kDataScheme, |
| 1106 | base::MakeUnique<net::DataProtocolHandler>()); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 1107 | job_factory->SetProtocolHandler( |
| 1108 | url::kFileScheme, |
ricea | 86fa1dd | 2016-09-13 05:59:45 | [diff] [blame] | 1109 | base::MakeUnique<net::FileProtocolHandler>( |
fdoray | dd7eb40 | 2017-04-26 21:44:25 | [diff] [blame] | 1110 | base::CreateTaskRunnerWithTraits( |
fdoray | 4ad1493 | 2017-05-03 21:21:11 | [diff] [blame] | 1111 | {base::MayBlock(), base::TaskPriority::USER_VISIBLE, |
| 1112 | base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}))); |
brettw | a1228ebb | 2016-10-28 03:51:34 | [diff] [blame] | 1113 | #if !BUILDFLAG(DISABLE_FTP_SUPPORT) |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 1114 | job_factory->SetProtocolHandler( |
| 1115 | url::kFtpScheme, |
mmenke | cd4c753 | 2016-10-19 18:36:05 | [diff] [blame] | 1116 | net::FtpProtocolHandler::Create(globals->host_resolver.get())); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 1117 | #endif |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 1118 | globals->proxy_script_fetcher_url_request_job_factory = |
| 1119 | std::move(job_factory); |
wjmaclean | ea309f7 | 2015-08-25 20:56:59 | [diff] [blame] | 1120 | |
| 1121 | context->set_job_factory( |
| 1122 | globals->proxy_script_fetcher_url_request_job_factory.get()); |
| 1123 | |
| 1124 | // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
| 1125 | // system URLRequestContext too. There's no reason this should be tied to a |
| 1126 | // profile. |
| 1127 | return context; |
| 1128 | } |
gayane | 0b46091c | 2016-04-07 21:01:05 | [diff] [blame] | 1129 | |
robliao | 7253fd2 | 2016-12-01 18:41:38 | [diff] [blame] | 1130 | metrics::UpdateUsagePrefCallbackType IOThread::GetMetricsDataUseForwarder() { |
| 1131 | return base::Bind(&UpdateMetricsUsagePrefsOnUIThread); |
gayane | 0b46091c | 2016-04-07 21:01:05 | [diff] [blame] | 1132 | } |