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