[email protected] | aeb53f0 | 2011-01-15 00:21:34 | [diff] [blame] | 1 | // Copyright (c) 2011 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 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 9 | #include "base/command_line.h" |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 10 | #include "base/bind.h" |
| 11 | #include "base/bind_helpers.h" |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 12 | #include "base/debug/leak_tracker.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 13 | #include "base/logging.h" |
[email protected] | ecd95ae | 2010-10-20 23:58:17 | [diff] [blame] | 14 | #include "base/metrics/field_trial.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 15 | #include "base/stl_util.h" |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 16 | #include "base/string_number_conversions.h" |
[email protected] | 4e5ae20f | 2010-09-24 04:52:11 | [diff] [blame] | 17 | #include "base/string_split.h" |
[email protected] | f1d8192 | 2010-07-31 17:47:09 | [diff] [blame] | 18 | #include "base/string_util.h" |
[email protected] | 3fc40c14 | 2011-12-01 13:09:04 | [diff] [blame] | 19 | #include "base/threading/thread.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 20 | #include "base/threading/thread_restrictions.h" |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 21 | #include "build/build_config.h" |
[email protected] | df2840d | 2011-02-20 16:32:32 | [diff] [blame] | 22 | #include "chrome/browser/browser_process.h" |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 23 | #include "chrome/browser/extensions/extension_event_router_forwarder.h" |
[email protected] | cc87500b | 2011-06-24 20:59:19 | [diff] [blame] | 24 | #include "chrome/browser/media/media_internals.h" |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 25 | #include "chrome/browser/net/chrome_net_log.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 26 | #include "chrome/browser/net/chrome_network_delegate.h" |
[email protected] | 0ee7a3b | 2010-11-09 06:13:40 | [diff] [blame] | 27 | #include "chrome/browser/net/chrome_url_request_context.h" |
[email protected] | 1889dc1b | 2010-10-14 22:03:13 | [diff] [blame] | 28 | #include "chrome/browser/net/connect_interceptor.h" |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 29 | #include "chrome/browser/net/passive_log_collector.h" |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 30 | #include "chrome/browser/net/pref_proxy_config_tracker.h" |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 31 | #include "chrome/browser/net/proxy_service_factory.h" |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 32 | #include "chrome/browser/net/sdch_dictionary_fetcher.h" |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 33 | #include "chrome/browser/prefs/pref_service.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 34 | #include "chrome/common/chrome_switches.h" |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 35 | #include "chrome/common/pref_names.h" |
[email protected] | d9f3793 | 2011-05-09 20:09:24 | [diff] [blame] | 36 | #include "content/browser/gpu/gpu_process_host.h" |
[email protected] | 567812d | 2011-02-24 17:40:50 | [diff] [blame] | 37 | #include "content/browser/in_process_webkit/indexed_db_key_utility_client.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 38 | #include "content/public/browser/browser_thread.h" |
[email protected] | 5d1fa24 | 2011-10-18 23:35:38 | [diff] [blame] | 39 | #include "content/public/common/content_client.h" |
[email protected] | 36aea270 | 2011-10-26 01:12:22 | [diff] [blame] | 40 | #include "content/public/common/url_fetcher.h" |
[email protected] | 822581d | 2010-12-16 17:27:15 | [diff] [blame] | 41 | #include "net/base/cert_verifier.h" |
[email protected] | f6c21cb | 2011-02-16 19:45:41 | [diff] [blame] | 42 | #include "net/base/cookie_monster.h" |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 43 | #include "net/base/default_origin_bound_cert_store.h" |
[email protected] | 2db58053 | 2010-10-08 14:32:37 | [diff] [blame] | 44 | #include "net/base/dnsrr_resolver.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 45 | #include "net/base/host_cache.h" |
| 46 | #include "net/base/host_resolver.h" |
[email protected] | f2d8c421 | 2010-02-02 00:56:35 | [diff] [blame] | 47 | #include "net/base/host_resolver_impl.h" |
[email protected] | 8693361 | 2010-10-16 23:10:33 | [diff] [blame] | 48 | #include "net/base/mapped_host_resolver.h" |
[email protected] | 32eaa33 | 2010-02-08 22:15:54 | [diff] [blame] | 49 | #include "net/base/net_util.h" |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 50 | #include "net/base/origin_bound_cert_service.h" |
[email protected] | 3b543ab | 2011-09-17 21:47:00 | [diff] [blame] | 51 | #include "net/base/sdch_manager.h" |
[email protected] | 4b0112ab | 2011-07-22 15:58:20 | [diff] [blame] | 52 | #include "net/dns/async_host_resolver.h" |
[email protected] | 933bc5c6 | 2011-04-12 19:08:02 | [diff] [blame] | 53 | #include "net/ftp/ftp_network_layer.h" |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 54 | #include "net/http/http_auth_filter.h" |
[email protected] | fa55e19 | 2010-02-15 14:25:50 | [diff] [blame] | 55 | #include "net/http/http_auth_handler_factory.h" |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 56 | #include "net/http/http_network_layer.h" |
[email protected] | 57cb0f7 | 2011-01-28 06:33:58 | [diff] [blame] | 57 | #include "net/http/http_network_session.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 58 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 59 | #include "net/proxy/proxy_config_service.h" |
[email protected] | 8693361 | 2010-10-16 23:10:33 | [diff] [blame] | 60 | #include "net/proxy/proxy_script_fetcher_impl.h" |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 61 | #include "net/proxy/proxy_service.h" |
[email protected] | 5f6f83e | 2011-05-24 18:03:08 | [diff] [blame] | 62 | #include "net/socket/dns_cert_provenance_checker.h" |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 63 | |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 64 | #if defined(USE_NSS) |
| 65 | #include "net/ocsp/nss_ocsp.h" |
| 66 | #endif // defined(USE_NSS) |
| 67 | |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 68 | #if defined(OS_CHROMEOS) |
| 69 | #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 70 | #endif // defined(OS_CHROMEOS) |
| 71 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 72 | using content::BrowserThread; |
| 73 | |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 74 | // The IOThread object must outlive any tasks posted to the IO thread before the |
| 75 | // Quit task, so base::Bind() calls are not refcounted. |
| 76 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 77 | namespace { |
| 78 | |
[email protected] | bd0875e | 2011-03-25 05:13:35 | [diff] [blame] | 79 | // Custom URLRequestContext used by requests which aren't associated with a |
| 80 | // particular profile. We need to use a subclass of URLRequestContext in order |
| 81 | // to provide the correct User-Agent. |
| 82 | class URLRequestContextWithUserAgent : public net::URLRequestContext { |
| 83 | public: |
| 84 | virtual const std::string& GetUserAgent( |
| 85 | const GURL& url) const OVERRIDE { |
[email protected] | b7552023 | 2011-10-12 23:45:25 | [diff] [blame] | 86 | return content::GetUserAgent(url); |
[email protected] | bd0875e | 2011-03-25 05:13:35 | [diff] [blame] | 87 | } |
| 88 | }; |
| 89 | |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 90 | // Used for the "system" URLRequestContext. If this grows more complicated, then |
| 91 | // consider inheriting directly from URLRequestContext rather than using |
| 92 | // implementation inheritance. |
| 93 | class SystemURLRequestContext : public URLRequestContextWithUserAgent { |
| 94 | public: |
| 95 | SystemURLRequestContext() { |
| 96 | #if defined(USE_NSS) |
| 97 | net::SetURLRequestContextForOCSP(this); |
| 98 | #endif // defined(USE_NSS) |
| 99 | } |
| 100 | |
| 101 | private: |
| 102 | virtual ~SystemURLRequestContext() { |
| 103 | #if defined(USE_NSS) |
| 104 | net::SetURLRequestContextForOCSP(NULL); |
| 105 | #endif // defined(USE_NSS) |
| 106 | } |
| 107 | }; |
| 108 | |
[email protected] | ee094b8 | 2010-08-24 15:55:51 | [diff] [blame] | 109 | net::HostResolver* CreateGlobalHostResolver(net::NetLog* net_log) { |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 110 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 111 | |
| 112 | size_t parallelism = net::HostResolver::kDefaultParallelism; |
| 113 | |
| 114 | // Use the concurrency override from the command-line, if any. |
| 115 | if (command_line.HasSwitch(switches::kHostResolverParallelism)) { |
| 116 | std::string s = |
| 117 | command_line.GetSwitchValueASCII(switches::kHostResolverParallelism); |
| 118 | |
| 119 | // Parse the switch (it should be a positive integer formatted as decimal). |
| 120 | int n; |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 121 | if (base::StringToInt(s, &n) && n > 0) { |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 122 | parallelism = static_cast<size_t>(n); |
| 123 | } else { |
| 124 | LOG(ERROR) << "Invalid switch for host resolver parallelism: " << s; |
| 125 | } |
[email protected] | ecd95ae | 2010-10-20 23:58:17 | [diff] [blame] | 126 | } else { |
| 127 | // Set up a field trial to see what impact the total number of concurrent |
| 128 | // resolutions have on DNS resolutions. |
| 129 | base::FieldTrial::Probability kDivisor = 1000; |
| 130 | // For each option (i.e., non-default), we have a fixed probability. |
| 131 | base::FieldTrial::Probability kProbabilityPerGroup = 100; // 10%. |
| 132 | |
[email protected] | 933729bc | 2011-01-19 18:52:32 | [diff] [blame] | 133 | // After June 30, 2011 builds, it will always be in default group |
| 134 | // (parallel_default). |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 135 | scoped_refptr<base::FieldTrial> trial( |
[email protected] | 933729bc | 2011-01-19 18:52:32 | [diff] [blame] | 136 | new base::FieldTrial( |
| 137 | "DnsParallelism", kDivisor, "parallel_default", 2011, 6, 30)); |
[email protected] | ecd95ae | 2010-10-20 23:58:17 | [diff] [blame] | 138 | |
| 139 | // List options with different counts. |
| 140 | // Firefox limits total to 8 in parallel, and default is currently 50. |
| 141 | int parallel_6 = trial->AppendGroup("parallel_6", kProbabilityPerGroup); |
[email protected] | 755a9335 | 2010-10-29 06:33:59 | [diff] [blame] | 142 | int parallel_7 = trial->AppendGroup("parallel_7", kProbabilityPerGroup); |
[email protected] | ecd95ae | 2010-10-20 23:58:17 | [diff] [blame] | 143 | int parallel_8 = trial->AppendGroup("parallel_8", kProbabilityPerGroup); |
[email protected] | 755a9335 | 2010-10-29 06:33:59 | [diff] [blame] | 144 | int parallel_9 = trial->AppendGroup("parallel_9", kProbabilityPerGroup); |
[email protected] | ecd95ae | 2010-10-20 23:58:17 | [diff] [blame] | 145 | int parallel_10 = trial->AppendGroup("parallel_10", kProbabilityPerGroup); |
| 146 | int parallel_14 = trial->AppendGroup("parallel_14", kProbabilityPerGroup); |
| 147 | int parallel_20 = trial->AppendGroup("parallel_20", kProbabilityPerGroup); |
| 148 | |
[email protected] | ecd95ae | 2010-10-20 23:58:17 | [diff] [blame] | 149 | if (trial->group() == parallel_6) |
| 150 | parallelism = 6; |
[email protected] | 755a9335 | 2010-10-29 06:33:59 | [diff] [blame] | 151 | else if (trial->group() == parallel_7) |
| 152 | parallelism = 7; |
[email protected] | ecd95ae | 2010-10-20 23:58:17 | [diff] [blame] | 153 | else if (trial->group() == parallel_8) |
| 154 | parallelism = 8; |
[email protected] | 755a9335 | 2010-10-29 06:33:59 | [diff] [blame] | 155 | else if (trial->group() == parallel_9) |
| 156 | parallelism = 9; |
[email protected] | ecd95ae | 2010-10-20 23:58:17 | [diff] [blame] | 157 | else if (trial->group() == parallel_10) |
| 158 | parallelism = 10; |
| 159 | else if (trial->group() == parallel_14) |
| 160 | parallelism = 14; |
| 161 | else if (trial->group() == parallel_20) |
| 162 | parallelism = 20; |
[email protected] | 962b9821 | 2010-07-17 03:37:51 | [diff] [blame] | 163 | } |
| 164 | |
[email protected] | 06ef6d9 | 2011-05-19 04:24:58 | [diff] [blame] | 165 | size_t retry_attempts = net::HostResolver::kDefaultRetryAttempts; |
| 166 | |
| 167 | // Use the retry attempts override from the command-line, if any. |
| 168 | if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) { |
| 169 | std::string s = |
| 170 | command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts); |
| 171 | // Parse the switch (it should be a non-negative integer). |
| 172 | int n; |
| 173 | if (base::StringToInt(s, &n) && n >= 0) { |
| 174 | retry_attempts = static_cast<size_t>(n); |
| 175 | } else { |
| 176 | LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s; |
| 177 | } |
| 178 | } |
| 179 | |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 180 | net::HostResolver* global_host_resolver = NULL; |
| 181 | if (command_line.HasSwitch(switches::kDnsServer)) { |
| 182 | std::string dns_ip_string = |
| 183 | command_line.GetSwitchValueASCII(switches::kDnsServer); |
| 184 | net::IPAddressNumber dns_ip_number; |
| 185 | if (net::ParseIPLiteralToNumber(dns_ip_string, &dns_ip_number)) { |
| 186 | global_host_resolver = |
| 187 | net::CreateAsyncHostResolver(parallelism, dns_ip_number, net_log); |
| 188 | } else { |
| 189 | LOG(ERROR) << "Invalid IP address specified for --dns-server: " |
| 190 | << dns_ip_string; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | if (!global_host_resolver) { |
| 195 | global_host_resolver = |
[email protected] | 06ef6d9 | 2011-05-19 04:24:58 | [diff] [blame] | 196 | net::CreateSystemHostResolver(parallelism, retry_attempts, net_log); |
[email protected] | d987cca | 2011-07-21 12:54:37 | [diff] [blame] | 197 | } |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 198 | |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 199 | // Determine if we should disable IPv6 support. |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 200 | if (!command_line.HasSwitch(switches::kEnableIPv6)) { |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 201 | if (command_line.HasSwitch(switches::kDisableIPv6)) { |
[email protected] | 46f6e20 | 2010-02-26 06:07:25 | [diff] [blame] | 202 | global_host_resolver->SetDefaultAddressFamily(net::ADDRESS_FAMILY_IPV4); |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 203 | } else { |
[email protected] | a78f427 | 2011-10-21 19:16:33 | [diff] [blame] | 204 | global_host_resolver->ProbeIPv6Support(); |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 205 | } |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 206 | } |
| 207 | |
[email protected] | 9087aa3 | 2010-02-18 08:03:38 | [diff] [blame] | 208 | // If hostname remappings were specified on the command-line, layer these |
| 209 | // rules on top of the real host resolver. This allows forwarding all requests |
| 210 | // through a designated test server. |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 211 | if (!command_line.HasSwitch(switches::kHostResolverRules)) |
| 212 | return global_host_resolver; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 213 | |
[email protected] | 0f8f1b43 | 2010-03-16 19:06:03 | [diff] [blame] | 214 | net::MappedHostResolver* remapped_resolver = |
| 215 | new net::MappedHostResolver(global_host_resolver); |
| 216 | remapped_resolver->SetRulesFromString( |
| 217 | command_line.GetSwitchValueASCII(switches::kHostResolverRules)); |
| 218 | return remapped_resolver; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 219 | } |
| 220 | |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 221 | class LoggingNetworkChangeObserver |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 222 | : public net::NetworkChangeNotifier::IPAddressObserver { |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 223 | public: |
| 224 | // |net_log| must remain valid throughout our lifetime. |
| 225 | explicit LoggingNetworkChangeObserver(net::NetLog* net_log) |
| 226 | : net_log_(net_log) { |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 227 | net::NetworkChangeNotifier::AddIPAddressObserver(this); |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | ~LoggingNetworkChangeObserver() { |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 231 | net::NetworkChangeNotifier::RemoveIPAddressObserver(this); |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | virtual void OnIPAddressChanged() { |
[email protected] | 8e96e50 | 2010-10-21 20:57:12 | [diff] [blame] | 235 | VLOG(1) << "Observed a change to the network IP addresses"; |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 236 | |
[email protected] | d3aaf3f | 2010-09-02 20:45:55 | [diff] [blame] | 237 | net_log_->AddEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED, |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 238 | base::TimeTicks::Now(), |
[email protected] | d2cbfbe | 2010-08-12 17:38:16 | [diff] [blame] | 239 | net::NetLog::Source(), |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 240 | net::NetLog::PHASE_NONE, |
| 241 | NULL); |
| 242 | } |
| 243 | |
| 244 | private: |
| 245 | net::NetLog* net_log_; |
| 246 | DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); |
| 247 | }; |
| 248 | |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 249 | // Create a separate request context for PAC fetches to avoid reference cycles. |
| 250 | // See IOThread::Globals for details. |
[email protected] | aeb53f0 | 2011-01-15 00:21:34 | [diff] [blame] | 251 | scoped_refptr<net::URLRequestContext> |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 252 | ConstructProxyScriptFetcherContext(IOThread::Globals* globals, |
| 253 | net::NetLog* net_log) { |
[email protected] | bd0875e | 2011-03-25 05:13:35 | [diff] [blame] | 254 | scoped_refptr<net::URLRequestContext> context( |
| 255 | new URLRequestContextWithUserAgent); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 256 | context->set_net_log(net_log); |
| 257 | context->set_host_resolver(globals->host_resolver.get()); |
| 258 | context->set_cert_verifier(globals->cert_verifier.get()); |
| 259 | context->set_dnsrr_resolver(globals->dnsrr_resolver.get()); |
| 260 | context->set_http_auth_handler_factory( |
| 261 | globals->http_auth_handler_factory.get()); |
| 262 | context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); |
| 263 | context->set_http_transaction_factory( |
[email protected] | 52617df | 2010-12-24 07:30:01 | [diff] [blame] | 264 | globals->proxy_script_fetcher_http_transaction_factory.get()); |
[email protected] | 933bc5c6 | 2011-04-12 19:08:02 | [diff] [blame] | 265 | context->set_ftp_transaction_factory( |
| 266 | globals->proxy_script_fetcher_ftp_transaction_factory.get()); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 267 | context->set_cookie_store(globals->system_cookie_store.get()); |
| 268 | context->set_origin_bound_cert_service( |
| 269 | globals->system_origin_bound_cert_service.get()); |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 270 | context->set_network_delegate(globals->system_network_delegate.get()); |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 271 | // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
| 272 | // system URLRequestContext too. There's no reason this should be tied to a |
| 273 | // profile. |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 274 | return context; |
| 275 | } |
| 276 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 277 | scoped_refptr<net::URLRequestContext> |
| 278 | ConstructSystemRequestContext(IOThread::Globals* globals, |
| 279 | net::NetLog* net_log) { |
[email protected] | bd0875e | 2011-03-25 05:13:35 | [diff] [blame] | 280 | scoped_refptr<net::URLRequestContext> context( |
[email protected] | 77feb46 | 2011-05-16 23:37:25 | [diff] [blame] | 281 | new SystemURLRequestContext); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 282 | context->set_net_log(net_log); |
| 283 | context->set_host_resolver(globals->host_resolver.get()); |
| 284 | context->set_cert_verifier(globals->cert_verifier.get()); |
| 285 | context->set_dnsrr_resolver(globals->dnsrr_resolver.get()); |
| 286 | context->set_http_auth_handler_factory( |
| 287 | globals->http_auth_handler_factory.get()); |
| 288 | context->set_proxy_service(globals->system_proxy_service.get()); |
| 289 | context->set_http_transaction_factory( |
| 290 | globals->system_http_transaction_factory.get()); |
[email protected] | 933bc5c6 | 2011-04-12 19:08:02 | [diff] [blame] | 291 | context->set_ftp_transaction_factory( |
| 292 | globals->system_ftp_transaction_factory.get()); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 293 | context->set_cookie_store(globals->system_cookie_store.get()); |
| 294 | context->set_origin_bound_cert_service( |
| 295 | globals->system_origin_bound_cert_service.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 296 | return context; |
| 297 | } |
| 298 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 299 | } // namespace |
| 300 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 301 | class SystemURLRequestContextGetter : public net::URLRequestContextGetter { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 302 | public: |
| 303 | explicit SystemURLRequestContextGetter(IOThread* io_thread); |
| 304 | virtual ~SystemURLRequestContextGetter(); |
| 305 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 306 | // Implementation for net::UrlRequestContextGetter. |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 307 | virtual net::URLRequestContext* GetURLRequestContext(); |
| 308 | virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const; |
| 309 | |
| 310 | private: |
| 311 | IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess. |
| 312 | scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
| 313 | |
| 314 | base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; |
| 315 | }; |
| 316 | |
| 317 | SystemURLRequestContextGetter::SystemURLRequestContextGetter( |
| 318 | IOThread* io_thread) |
| 319 | : io_thread_(io_thread), |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 320 | io_message_loop_proxy_( |
| 321 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} |
| 325 | |
| 326 | net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { |
| 327 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 328 | DCHECK(io_thread_->globals()->system_request_context); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 329 | |
| 330 | return io_thread_->globals()->system_request_context; |
| 331 | } |
| 332 | |
| 333 | scoped_refptr<base::MessageLoopProxy> |
| 334 | SystemURLRequestContextGetter::GetIOMessageLoopProxy() const { |
| 335 | return io_message_loop_proxy_; |
| 336 | } |
| 337 | |
[email protected] | 1889dc1b | 2010-10-14 22:03:13 | [diff] [blame] | 338 | IOThread::Globals::Globals() {} |
| 339 | |
| 340 | IOThread::Globals::~Globals() {} |
| 341 | |
[email protected] | cc87500b | 2011-06-24 20:59:19 | [diff] [blame] | 342 | IOThread::Globals::MediaGlobals::MediaGlobals() {} |
| 343 | |
| 344 | IOThread::Globals::MediaGlobals::~MediaGlobals() {} |
| 345 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 346 | // |local_state| is passed in explicitly in order to (1) reduce implicit |
| 347 | // dependencies and (2) make IOThread more flexible for testing. |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 348 | IOThread::IOThread( |
| 349 | PrefService* local_state, |
| 350 | ChromeNetLog* net_log, |
| 351 | ExtensionEventRouterForwarder* extension_event_router_forwarder) |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 352 | : net_log_(net_log), |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 353 | extension_event_router_forwarder_(extension_event_router_forwarder), |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 354 | globals_(NULL), |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 355 | sdch_manager_(NULL), |
[email protected] | 21ee224e | 2011-11-21 02:17:53 | [diff] [blame] | 356 | ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 357 | // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make |
| 358 | // sure that everything is initialized in the right order. |
| 359 | RegisterPrefs(local_state); |
| 360 | auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); |
| 361 | negotiate_disable_cname_lookup_ = local_state->GetBoolean( |
| 362 | prefs::kDisableAuthNegotiateCnameLookup); |
| 363 | negotiate_enable_port_ = local_state->GetBoolean( |
| 364 | prefs::kEnableAuthNegotiatePort); |
| 365 | auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); |
| 366 | auth_delegate_whitelist_ = local_state->GetString( |
| 367 | prefs::kAuthNegotiateDelegateWhitelist); |
[email protected] | ac7f3fdb | 2010-11-12 12:47:05 | [diff] [blame] | 368 | gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 369 | pref_proxy_config_tracker_.reset( |
| 370 | ProxyServiceFactory::CreatePrefProxyConfigTracker(local_state)); |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 371 | ChromeNetworkDelegate::InitializeReferrersEnabled(&system_enable_referrers_, |
| 372 | local_state); |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 373 | ssl_config_service_manager_.reset( |
| 374 | SSLConfigServiceManager::CreateDefaultManager(local_state)); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 375 | |
| 376 | BrowserThread::SetDelegate(BrowserThread::IO, this); |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 377 | } |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 378 | |
| 379 | IOThread::~IOThread() { |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 380 | // This isn't needed for production code, but in tests, IOThread may |
| 381 | // be multiply constructed. |
| 382 | BrowserThread::SetDelegate(BrowserThread::IO, NULL); |
| 383 | |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 384 | if (pref_proxy_config_tracker_.get()) |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 385 | pref_proxy_config_tracker_->DetachFromPrefService(); |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 386 | DCHECK(!globals_); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 387 | } |
| 388 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 389 | IOThread::Globals* IOThread::globals() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 390 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 391 | return globals_; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 392 | } |
| 393 | |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 394 | ChromeNetLog* IOThread::net_log() { |
| 395 | return net_log_; |
| 396 | } |
| 397 | |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 398 | net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 399 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 400 | if (!system_url_request_context_getter_) { |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 401 | InitSystemRequestContext(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 402 | } |
| 403 | return system_url_request_context_getter_; |
| 404 | } |
| 405 | |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 406 | void IOThread::Init() { |
[email protected] | ba74b0d2 | 2010-10-23 05:19:20 | [diff] [blame] | 407 | // Though this thread is called the "IO" thread, it actually just routes |
| 408 | // messages around; it shouldn't be allowed to perform any blocking disk I/O. |
| 409 | base::ThreadRestrictions::SetIOAllowed(false); |
[email protected] | ba74b0d2 | 2010-10-23 05:19:20 | [diff] [blame] | 410 | |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 411 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 70b9234 | 2010-10-12 05:54:06 | [diff] [blame] | 412 | |
| 413 | #if defined(USE_NSS) |
| 414 | net::SetMessageLoopForOCSP(); |
[email protected] | ecd95ae | 2010-10-20 23:58:17 | [diff] [blame] | 415 | #endif // defined(USE_NSS) |
[email protected] | 70b9234 | 2010-10-12 05:54:06 | [diff] [blame] | 416 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 417 | DCHECK(!globals_); |
| 418 | globals_ = new Globals; |
| 419 | |
[email protected] | cc87500b | 2011-06-24 20:59:19 | [diff] [blame] | 420 | globals_->media.media_internals.reset(new MediaInternals()); |
| 421 | |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 422 | // Add an observer that will emit network change events to the ChromeNetLog. |
| 423 | // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be |
| 424 | // logging the network change before other IO thread consumers respond to it. |
| 425 | network_change_observer_.reset( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 426 | new LoggingNetworkChangeObserver(net_log_)); |
[email protected] | 58bc704 | 2010-07-07 18:04:14 | [diff] [blame] | 427 | |
[email protected] | 3ce0241 | 2011-03-01 12:01:15 | [diff] [blame] | 428 | globals_->extension_event_router_forwarder = |
| 429 | extension_event_router_forwarder_; |
| 430 | globals_->system_network_delegate.reset(new ChromeNetworkDelegate( |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 431 | extension_event_router_forwarder_, |
[email protected] | c357acb4 | 2011-06-09 20:52:42 | [diff] [blame] | 432 | NULL, |
[email protected] | 67351452 | 2011-07-13 18:17:18 | [diff] [blame] | 433 | NULL, |
[email protected] | 6a5f77c3 | 2011-09-04 19:19:59 | [diff] [blame] | 434 | NULL, |
[email protected] | a8c1e745 | 2011-05-14 06:17:07 | [diff] [blame] | 435 | &system_enable_referrers_)); |
[email protected] | 73c4532 | 2010-10-01 23:57:54 | [diff] [blame] | 436 | globals_->host_resolver.reset( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 437 | CreateGlobalHostResolver(net_log_)); |
[email protected] | 822581d | 2010-12-16 17:27:15 | [diff] [blame] | 438 | globals_->cert_verifier.reset(new net::CertVerifier); |
[email protected] | 2db58053 | 2010-10-08 14:32:37 | [diff] [blame] | 439 | globals_->dnsrr_resolver.reset(new net::DnsRRResolver); |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 440 | globals_->ssl_config_service = GetSSLConfigService(); |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 441 | globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( |
[email protected] | 73c4532 | 2010-10-01 23:57:54 | [diff] [blame] | 442 | globals_->host_resolver.get())); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 443 | globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 444 | // For the ProxyScriptFetcher, we use a direct ProxyService. |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 445 | globals_->proxy_script_fetcher_proxy_service.reset( |
| 446 | net::ProxyService::CreateDirectWithNetLog(net_log_)); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 447 | // In-memory cookie store. |
| 448 | globals_->system_cookie_store = new net::CookieMonster(NULL, NULL); |
| 449 | // In-memory origin-bound cert store. |
| 450 | globals_->system_origin_bound_cert_service.reset( |
| 451 | new net::OriginBoundCertService( |
| 452 | new net::DefaultOriginBoundCertStore(NULL))); |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 453 | net::HttpNetworkSession::Params session_params; |
| 454 | session_params.host_resolver = globals_->host_resolver.get(); |
| 455 | session_params.cert_verifier = globals_->cert_verifier.get(); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 456 | session_params.origin_bound_cert_service = |
| 457 | globals_->system_origin_bound_cert_service.get(); |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 458 | session_params.proxy_service = |
| 459 | globals_->proxy_script_fetcher_proxy_service.get(); |
| 460 | session_params.http_auth_handler_factory = |
| 461 | globals_->http_auth_handler_factory.get(); |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 462 | session_params.network_delegate = globals_->system_network_delegate.get(); |
[email protected] | db96a88 | 2011-10-09 02:01:54 | [diff] [blame] | 463 | // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the |
| 464 | // system URLRequestContext too. There's no reason this should be tied to a |
| 465 | // profile. |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 466 | session_params.http_server_properties = |
| 467 | globals_->http_server_properties.get(); |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 468 | session_params.net_log = net_log_; |
| 469 | session_params.ssl_config_service = globals_->ssl_config_service; |
[email protected] | 57cb0f7 | 2011-01-28 06:33:58 | [diff] [blame] | 470 | scoped_refptr<net::HttpNetworkSession> network_session( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 471 | new net::HttpNetworkSession(session_params)); |
[email protected] | 57cb0f7 | 2011-01-28 06:33:58 | [diff] [blame] | 472 | globals_->proxy_script_fetcher_http_transaction_factory.reset( |
| 473 | new net::HttpNetworkLayer(network_session)); |
[email protected] | 933bc5c6 | 2011-04-12 19:08:02 | [diff] [blame] | 474 | globals_->proxy_script_fetcher_ftp_transaction_factory.reset( |
| 475 | new net::FtpNetworkLayer(globals_->host_resolver.get())); |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 476 | |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 477 | globals_->proxy_script_fetcher_context = |
[email protected] | 2fb62920 | 2010-12-23 23:52:57 | [diff] [blame] | 478 | ConstructProxyScriptFetcherContext(globals_, net_log_); |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 479 | |
| 480 | sdch_manager_ = new net::SdchManager(); |
| 481 | sdch_manager_->set_sdch_fetcher(new SdchDictionaryFetcher); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 482 | |
| 483 | // InitSystemRequestContext turns right around and posts a task back |
| 484 | // to the IO thread, so we can't let it run until we know the IO |
| 485 | // thread has started. |
| 486 | // |
| 487 | // Note that since we are at BrowserThread::Init time, the UI thread |
| 488 | // is blocked waiting for the thread to start. Therefore, posting |
| 489 | // this task to the main thread's message loop here is guaranteed to |
| 490 | // get it onto the message loop while the IOThread object still |
| 491 | // exists. However, the message might not be processed on the UI |
| 492 | // thread until after IOThread is gone, so use a weak pointer. |
| 493 | BrowserThread::PostTask(BrowserThread::UI, |
| 494 | FROM_HERE, |
| 495 | base::Bind(&IOThread::InitSystemRequestContext, |
| 496 | weak_factory_.GetWeakPtr())); |
| 497 | |
| 498 | // We constructed the weak pointer on the IO thread but it will be |
| 499 | // used on the UI thread. Call this to avoid a thread checker |
| 500 | // error. |
| 501 | weak_factory_.DetachFromThread(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 502 | } |
| 503 | |
[email protected] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 504 | void IOThread::CleanUp() { |
[email protected] | 4a10949 | 2011-09-24 21:00:12 | [diff] [blame] | 505 | delete sdch_manager_; |
| 506 | sdch_manager_ = NULL; |
| 507 | |
[email protected] | 0ee7a3b | 2010-11-09 06:13:40 | [diff] [blame] | 508 | // Step 1: Kill all things that might be holding onto |
[email protected] | aeb53f0 | 2011-01-15 00:21:34 | [diff] [blame] | 509 | // net::URLRequest/net::URLRequestContexts. |
[email protected] | 0ee7a3b | 2010-11-09 06:13:40 | [diff] [blame] | 510 | |
[email protected] | 59a3b36 | 2010-10-21 21:52:41 | [diff] [blame] | 511 | #if defined(USE_NSS) |
| 512 | net::ShutdownOCSP(); |
| 513 | #endif // defined(USE_NSS) |
| 514 | |
[email protected] | 0b1ad31 | 2010-10-22 01:01:38 | [diff] [blame] | 515 | // Destroy all URLRequests started by URLFetchers. |
[email protected] | 36aea270 | 2011-10-26 01:12:22 | [diff] [blame] | 516 | content::URLFetcher::CancelAll(); |
[email protected] | 0b1ad31 | 2010-10-22 01:01:38 | [diff] [blame] | 517 | |
[email protected] | 5377d89 | 2011-01-21 18:25:43 | [diff] [blame] | 518 | IndexedDBKeyUtilityClient::Shutdown(); |
| 519 | |
[email protected] | 325a71f | 2010-05-21 23:05:27 | [diff] [blame] | 520 | // If any child processes are still running, terminate them and |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 521 | // and delete the BrowserChildProcessHost instances to release whatever |
[email protected] | 325a71f | 2010-05-21 23:05:27 | [diff] [blame] | 522 | // IO thread only resources they are referencing. |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 523 | BrowserChildProcessHost::TerminateAll(); |
[email protected] | 325a71f | 2010-05-21 23:05:27 | [diff] [blame] | 524 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 525 | system_url_request_context_getter_ = NULL; |
| 526 | |
[email protected] | aeb53f0 | 2011-01-15 00:21:34 | [diff] [blame] | 527 | // Step 2: Release objects that the net::URLRequestContext could have been |
| 528 | // pointing to. |
[email protected] | 0ee7a3b | 2010-11-09 06:13:40 | [diff] [blame] | 529 | |
| 530 | // This must be reset before the ChromeNetLog is destroyed. |
| 531 | network_change_observer_.reset(); |
| 532 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 533 | system_proxy_config_service_.reset(); |
| 534 | |
[email protected] | d13c327 | 2010-02-04 00:24:51 | [diff] [blame] | 535 | delete globals_; |
| 536 | globals_ = NULL; |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 537 | |
[email protected] | 569c760 | 2011-03-03 20:40:32 | [diff] [blame] | 538 | // net::URLRequest instances must NOT outlive the IO thread. |
| 539 | base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); |
[email protected] | 2a92cd9 | 2010-04-27 00:01:41 | [diff] [blame] | 540 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 541 | base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 542 | } |
| 543 | |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 544 | // static |
| 545 | void IOThread::RegisterPrefs(PrefService* local_state) { |
| 546 | local_state->RegisterStringPref(prefs::kAuthSchemes, |
| 547 | "basic,digest,ntlm,negotiate"); |
| 548 | local_state->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, |
| 549 | false); |
| 550 | local_state->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false); |
| 551 | local_state->RegisterStringPref(prefs::kAuthServerWhitelist, ""); |
| 552 | local_state->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist, ""); |
[email protected] | ac7f3fdb | 2010-11-12 12:47:05 | [diff] [blame] | 553 | local_state->RegisterStringPref(prefs::kGSSAPILibraryName, ""); |
[email protected] | 0a8db0d | 2011-04-13 15:15:40 | [diff] [blame] | 554 | local_state->RegisterBooleanPref(prefs::kEnableReferrers, true); |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 555 | } |
| 556 | |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 557 | net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory( |
| 558 | net::HostResolver* resolver) { |
[email protected] | 9030a63 | 2010-11-19 20:12:09 | [diff] [blame] | 559 | net::HttpAuthFilterWhitelist* auth_filter_default_credentials = NULL; |
| 560 | if (!auth_server_whitelist_.empty()) { |
| 561 | auth_filter_default_credentials = |
| 562 | new net::HttpAuthFilterWhitelist(auth_server_whitelist_); |
| 563 | } |
| 564 | net::HttpAuthFilterWhitelist* auth_filter_delegate = NULL; |
| 565 | if (!auth_delegate_whitelist_.empty()) { |
| 566 | auth_filter_delegate = |
| 567 | new net::HttpAuthFilterWhitelist(auth_delegate_whitelist_); |
| 568 | } |
[email protected] | b4955e7d | 2010-04-16 20:22:30 | [diff] [blame] | 569 | globals_->url_security_manager.reset( |
[email protected] | d201b200e | 2010-08-27 17:35:02 | [diff] [blame] | 570 | net::URLSecurityManager::Create(auth_filter_default_credentials, |
| 571 | auth_filter_delegate)); |
[email protected] | b730416 | 2010-08-23 17:42:29 | [diff] [blame] | 572 | std::vector<std::string> supported_schemes; |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 573 | base::SplitString(auth_schemes_, ',', &supported_schemes); |
[email protected] | b730416 | 2010-08-23 17:42:29 | [diff] [blame] | 574 | |
| 575 | return net::HttpAuthHandlerRegistryFactory::Create( |
| 576 | supported_schemes, |
| 577 | globals_->url_security_manager.get(), |
| 578 | resolver, |
[email protected] | ac7f3fdb | 2010-11-12 12:47:05 | [diff] [blame] | 579 | gssapi_library_name_, |
[email protected] | bcefe0f | 2010-11-10 16:19:10 | [diff] [blame] | 580 | negotiate_disable_cname_lookup_, |
| 581 | negotiate_enable_port_); |
[email protected] | eb3cac7 | 2010-02-26 21:07:45 | [diff] [blame] | 582 | } |
| 583 | |
[email protected] | d6f37fc | 2011-02-13 23:58:41 | [diff] [blame] | 584 | void IOThread::ClearHostCache() { |
| 585 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 586 | |
[email protected] | 489d1a8 | 2011-10-12 03:09:11 | [diff] [blame] | 587 | net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); |
| 588 | if (host_cache) |
| 589 | host_cache->clear(); |
[email protected] | 0ac8368 | 2010-01-22 17:46:27 | [diff] [blame] | 590 | } |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 591 | |
[email protected] | 4d45a6de | 2011-05-13 05:20:18 | [diff] [blame] | 592 | net::SSLConfigService* IOThread::GetSSLConfigService() { |
| 593 | return ssl_config_service_manager_->Get(); |
| 594 | } |
| 595 | |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 596 | void IOThread::InitSystemRequestContext() { |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 597 | if (system_url_request_context_getter_) |
| 598 | return; |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 599 | // If we're in unit_tests, IOThread may not be run. |
[email protected] | dd48370 | 2011-12-02 14:47:42 | [diff] [blame^] | 600 | if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO)) |
[email protected] | 63e2682 | 2011-07-16 19:07:35 | [diff] [blame] | 601 | return; |
[email protected] | 6f96cbcb | 2011-11-04 02:26:07 | [diff] [blame] | 602 | ChromeProxyConfigService* proxy_config_service = |
| 603 | ProxyServiceFactory::CreateProxyConfigService(); |
| 604 | system_proxy_config_service_.reset(proxy_config_service); |
| 605 | if (pref_proxy_config_tracker_.get()) { |
| 606 | pref_proxy_config_tracker_->SetChromeProxyConfigService( |
| 607 | proxy_config_service); |
| 608 | } |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 609 | system_url_request_context_getter_ = |
| 610 | new SystemURLRequestContextGetter(this); |
[email protected] | 2e5b60a2 | 2011-11-28 15:56:41 | [diff] [blame] | 611 | // Safe to post an unretained this pointer, since IOThread is |
| 612 | // guaranteed to outlive the IO BrowserThread. |
[email protected] | dd48370 | 2011-12-02 14:47:42 | [diff] [blame^] | 613 | BrowserThread::PostTask( |
| 614 | BrowserThread::IO, |
| 615 | FROM_HERE, |
| 616 | base::Bind(&IOThread::InitSystemRequestContextOnIOThread, |
| 617 | base::Unretained(this))); |
[email protected] | addb324 | 2011-06-13 21:39:16 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | void IOThread::InitSystemRequestContextOnIOThread() { |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 621 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 622 | DCHECK(!globals_->system_proxy_service.get()); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 623 | DCHECK(system_proxy_config_service_.get()); |
| 624 | |
| 625 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 626 | globals_->system_proxy_service.reset( |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 627 | ProxyServiceFactory::CreateProxyService( |
| 628 | net_log_, |
| 629 | globals_->proxy_script_fetcher_context, |
| 630 | system_proxy_config_service_.release(), |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 631 | command_line)); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 632 | net::HttpNetworkSession::Params system_params; |
| 633 | system_params.host_resolver = globals_->host_resolver.get(); |
| 634 | system_params.cert_verifier = globals_->cert_verifier.get(); |
[email protected] | 273e37d | 2011-08-11 01:49:12 | [diff] [blame] | 635 | system_params.origin_bound_cert_service = |
| 636 | globals_->system_origin_bound_cert_service.get(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 637 | system_params.dnsrr_resolver = globals_->dnsrr_resolver.get(); |
| 638 | system_params.dns_cert_checker = NULL; |
| 639 | system_params.ssl_host_info_factory = NULL; |
| 640 | system_params.proxy_service = globals_->system_proxy_service.get(); |
| 641 | system_params.ssl_config_service = globals_->ssl_config_service.get(); |
| 642 | system_params.http_auth_handler_factory = |
| 643 | globals_->http_auth_handler_factory.get(); |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 644 | system_params.http_server_properties = globals_->http_server_properties.get(); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 645 | system_params.network_delegate = globals_->system_network_delegate.get(); |
| 646 | system_params.net_log = net_log_; |
| 647 | globals_->system_http_transaction_factory.reset( |
| 648 | new net::HttpNetworkLayer( |
| 649 | new net::HttpNetworkSession(system_params))); |
[email protected] | 933bc5c6 | 2011-04-12 19:08:02 | [diff] [blame] | 650 | globals_->system_ftp_transaction_factory.reset( |
| 651 | new net::FtpNetworkLayer(globals_->host_resolver.get())); |
[email protected] | db0e86dd | 2011-03-16 14:47:21 | [diff] [blame] | 652 | globals_->system_request_context = |
| 653 | ConstructSystemRequestContext(globals_, net_log_); |
| 654 | } |