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

Side by Side Diff: ios/chrome/browser/ios_chrome_io_thread.cc

Issue 1464083002: Upstream IOSChromeIOThread to hold data primarily used on IO thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git cl upload --similarity=30 Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/ios_chrome_io_thread.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/io_thread.h" 5 #include "ios/chrome/browser/ios_chrome_io_thread.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base64.h"
10 #include "base/bind.h" 9 #include "base/bind.h"
11 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 11 #include "base/command_line.h"
13 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
14 #include "base/debug/leak_tracker.h" 13 #include "base/debug/leak_tracker.h"
15 #include "base/environment.h" 14 #include "base/environment.h"
16 #include "base/logging.h" 15 #include "base/logging.h"
17 #include "base/metrics/field_trial.h" 16 #include "base/metrics/field_trial.h"
18 #include "base/prefs/pref_registry_simple.h"
19 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
20 #include "base/profiler/scoped_tracker.h"
21 #include "base/stl_util.h" 18 #include "base/stl_util.h"
22 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_piece.h" 20 #include "base/strings/string_piece.h"
24 #include "base/strings/string_split.h" 21 #include "base/strings/string_split.h"
25 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
26 #include "base/threading/sequenced_worker_pool.h" 23 #include "base/threading/sequenced_worker_pool.h"
27 #include "base/threading/thread.h" 24 #include "base/threading/thread.h"
28 #include "base/threading/worker_pool.h" 25 #include "base/threading/worker_pool.h"
29 #include "base/time/time.h" 26 #include "base/time/time.h"
30 #include "base/trace_event/trace_event.h" 27 #include "base/trace_event/trace_event.h"
31 #include "build/build_config.h"
32 #include "chrome/browser/browser_process.h"
33 #include "chrome/browser/data_usage/tab_id_annotator.h"
34 #include "chrome/browser/net/async_dns_field_trial.h"
35 #include "chrome/browser/net/chrome_network_delegate.h"
36 #include "chrome/browser/net/connect_interceptor.h"
37 #include "chrome/browser/net/dns_probe_service.h"
38 #include "chrome/browser/net/proxy_service_factory.h"
39 #include "chrome/common/channel_info.h"
40 #include "chrome/common/chrome_content_client.h"
41 #include "chrome/common/chrome_switches.h"
42 #include "chrome/common/pref_names.h"
43 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_pref s.h"
44 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" 28 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
45 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
46 #include "components/data_usage/core/data_use_aggregator.h"
47 #include "components/data_usage/core/data_use_amortizer.h"
48 #include "components/data_usage/core/data_use_annotator.h"
49 #include "components/net_log/chrome_net_log.h" 29 #include "components/net_log/chrome_net_log.h"
50 #include "components/policy/core/common/policy_service.h"
51 #include "components/proxy_config/pref_proxy_config_tracker.h" 30 #include "components/proxy_config/pref_proxy_config_tracker.h"
52 #include "components/variations/variations_associated_data.h" 31 #include "components/variations/variations_associated_data.h"
53 #include "components/version_info/version_info.h" 32 #include "components/version_info/version_info.h"
54 #include "content/public/browser/browser_thread.h" 33 #include "ios/chrome/browser/chrome_switches.h"
55 #include "content/public/browser/cookie_store_factory.h" 34 #include "ios/chrome/browser/net/cookie_util.h"
56 #include "content/public/common/content_switches.h" 35 #include "ios/chrome/browser/net/ios_chrome_network_delegate.h"
57 #include "content/public/common/user_agent.h" 36 #include "ios/chrome/browser/net/proxy_service_factory.h"
37 #include "ios/chrome/common/channel_info.h"
38 #include "ios/web/public/user_agent.h"
39 #include "ios/web/public/web_client.h"
40 #include "ios/web/public/web_thread.h"
58 #include "net/base/external_estimate_provider.h" 41 #include "net/base/external_estimate_provider.h"
59 #include "net/base/host_mapping_rules.h"
60 #include "net/base/net_util.h" 42 #include "net/base/net_util.h"
61 #include "net/base/network_quality_estimator.h" 43 #include "net/base/network_quality_estimator.h"
62 #include "net/base/sdch_manager.h" 44 #include "net/base/sdch_manager.h"
63 #include "net/cert/cert_policy_enforcer.h" 45 #include "net/cert/cert_policy_enforcer.h"
64 #include "net/cert/cert_verifier.h" 46 #include "net/cert/cert_verifier.h"
65 #include "net/cert/cert_verify_proc.h" 47 #include "net/cert/cert_verify_proc.h"
66 #include "net/cert/ct_known_logs.h" 48 #include "net/cert/ct_known_logs.h"
67 #include "net/cert/ct_known_logs_static.h" 49 #include "net/cert/ct_known_logs_static.h"
68 #include "net/cert/ct_log_verifier.h" 50 #include "net/cert/ct_log_verifier.h"
69 #include "net/cert/ct_verifier.h" 51 #include "net/cert/ct_verifier.h"
70 #include "net/cert/multi_log_ct_verifier.h" 52 #include "net/cert/multi_log_ct_verifier.h"
71 #include "net/cert/multi_threaded_cert_verifier.h" 53 #include "net/cert/multi_threaded_cert_verifier.h"
54 #include "net/cert_net/nss_ocsp.h"
55 #include "net/cookies/cookie_monster.h"
72 #include "net/cookies/cookie_store.h" 56 #include "net/cookies/cookie_store.h"
73 #include "net/dns/host_cache.h" 57 #include "net/dns/host_cache.h"
74 #include "net/dns/host_resolver.h" 58 #include "net/dns/host_resolver.h"
75 #include "net/dns/mapped_host_resolver.h" 59 #include "net/dns/mapped_host_resolver.h"
76 #include "net/ftp/ftp_network_layer.h"
77 #include "net/http/http_auth_filter.h" 60 #include "net/http/http_auth_filter.h"
78 #include "net/http/http_auth_handler_factory.h" 61 #include "net/http/http_auth_handler_factory.h"
79 #include "net/http/http_network_layer.h" 62 #include "net/http/http_network_layer.h"
80 #include "net/http/http_network_session.h" 63 #include "net/http/http_network_session.h"
81 #include "net/http/http_server_properties_impl.h" 64 #include "net/http/http_server_properties_impl.h"
82 #include "net/proxy/proxy_config_service.h" 65 #include "net/proxy/proxy_config_service.h"
83 #include "net/proxy/proxy_script_fetcher_impl.h" 66 #include "net/proxy/proxy_script_fetcher_impl.h"
84 #include "net/proxy/proxy_service.h" 67 #include "net/proxy/proxy_service.h"
85 #include "net/quic/crypto/crypto_protocol.h" 68 #include "net/quic/crypto/crypto_protocol.h"
86 #include "net/quic/quic_protocol.h" 69 #include "net/quic/quic_protocol.h"
87 #include "net/quic/quic_utils.h" 70 #include "net/quic/quic_utils.h"
88 #include "net/socket/ssl_client_socket.h"
89 #include "net/socket/tcp_client_socket.h" 71 #include "net/socket/tcp_client_socket.h"
90 #include "net/spdy/spdy_session.h" 72 #include "net/spdy/spdy_session.h"
91 #include "net/ssl/channel_id_service.h" 73 #include "net/ssl/channel_id_service.h"
92 #include "net/ssl/default_channel_id_store.h" 74 #include "net/ssl/default_channel_id_store.h"
93 #include "net/url_request/data_protocol_handler.h" 75 #include "net/url_request/data_protocol_handler.h"
94 #include "net/url_request/file_protocol_handler.h" 76 #include "net/url_request/file_protocol_handler.h"
95 #include "net/url_request/ftp_protocol_handler.h"
96 #include "net/url_request/static_http_user_agent_settings.h" 77 #include "net/url_request/static_http_user_agent_settings.h"
97 #include "net/url_request/url_fetcher.h"
98 #include "net/url_request/url_request_backoff_manager.h" 78 #include "net/url_request/url_request_backoff_manager.h"
99 #include "net/url_request/url_request_context.h" 79 #include "net/url_request/url_request_context.h"
100 #include "net/url_request/url_request_context_builder.h" 80 #include "net/url_request/url_request_context_builder.h"
101 #include "net/url_request/url_request_context_getter.h" 81 #include "net/url_request/url_request_context_getter.h"
102 #include "net/url_request/url_request_job_factory_impl.h" 82 #include "net/url_request/url_request_job_factory_impl.h"
103 #include "url/url_constants.h" 83 #include "url/url_constants.h"
104 84
105 #if defined(ENABLE_CONFIGURATION_POLICY) 85 // The IOSChromeIOThread object must outlive any tasks posted to the IO thread
106 #include "policy/policy_constants.h" 86 // before the Quit task, so base::Bind() calls are not refcounted.
107 #endif
108
109 #if defined(ENABLE_EXTENSIONS)
110 #include "chrome/browser/extensions/event_router_forwarder.h"
111 #endif
112
113 #if defined(USE_NSS_CERTS) || defined(OS_IOS)
114 #include "net/cert_net/nss_ocsp.h"
115 #endif
116
117 #if defined(OS_ANDROID)
118 #include "base/android/build_info.h"
119 #include "chrome/browser/android/data_usage/external_data_use_observer.h"
120 #include "chrome/browser/android/net/external_estimate_provider_android.h"
121 #include "components/data_usage/android/traffic_stats_amortizer.h"
122 #endif
123
124 #if defined(OS_CHROMEOS)
125 #include "chrome/browser/chromeos/net/cert_verify_proc_chromeos.h"
126 #include "chromeos/network/host_resolver_impl_chromeos.h"
127 #endif
128
129 using content::BrowserThread;
130
131 class SafeBrowsingURLRequestContext;
132
133 // The IOThread object must outlive any tasks posted to the IO thread before the
134 // Quit task, so base::Bind() calls are not refcounted.
135 87
136 namespace { 88 namespace {
137 89
90 const char kSupportedAuthSchemes[] = "basic,digest,ntlm,negotiate";
davidben 2015/11/23 17:43:27 I doubt Negotiate works on iOS. I believe it requi
91
138 const char kTCPFastOpenFieldTrialName[] = "TCPFastOpen"; 92 const char kTCPFastOpenFieldTrialName[] = "TCPFastOpen";
139 const char kTCPFastOpenHttpsEnabledGroupName[] = "HttpsEnabled"; 93 const char kTCPFastOpenHttpsEnabledGroupName[] = "HttpsEnabled";
140 94
141 const char kQuicFieldTrialName[] = "QUIC"; 95 const char kQuicFieldTrialName[] = "QUIC";
142 const char kQuicFieldTrialEnabledGroupName[] = "Enabled"; 96 const char kQuicFieldTrialEnabledGroupName[] = "Enabled";
143 const char kQuicFieldTrialHttpsEnabledGroupName[] = "HttpsEnabled"; 97 const char kQuicFieldTrialHttpsEnabledGroupName[] = "HttpsEnabled";
144 98
145 // The SPDY trial composes two different trial plus control groups: 99 // The SPDY trial composes two different trial plus control groups:
146 // * A "holdback" group with SPDY disabled, and corresponding control 100 // * A "holdback" group with SPDY disabled, and corresponding control
147 // (SPDY/3.1). The primary purpose of the holdback group is to encourage site 101 // (SPDY/3.1). The primary purpose of the holdback group is to encourage site
(...skipping 10 matching lines...) Expand all
158 // Field trial for network quality estimator. Seeds RTT and downstream 112 // Field trial for network quality estimator. Seeds RTT and downstream
159 // throughput observations with values that correspond to the connection type 113 // throughput observations with values that correspond to the connection type
160 // determined by the operating system. 114 // determined by the operating system.
161 const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator"; 115 const char kNetworkQualityEstimatorFieldTrialName[] = "NetworkQualityEstimator";
162 116
163 // Field trial for NPN. 117 // Field trial for NPN.
164 const char kNpnTrialName[] = "NPN"; 118 const char kNpnTrialName[] = "NPN";
165 const char kNpnTrialEnabledGroupNamePrefix[] = "Enable"; 119 const char kNpnTrialEnabledGroupNamePrefix[] = "Enable";
166 const char kNpnTrialDisabledGroupNamePrefix[] = "Disable"; 120 const char kNpnTrialDisabledGroupNamePrefix[] = "Disable";
167 121
168 #if defined(OS_MACOSX) && !defined(OS_IOS)
169 void ObserveKeychainEvents() {
170 DCHECK_CURRENTLY_ON(BrowserThread::UI);
171 net::CertDatabase::GetInstance()->SetMessageLoopForKeychainEvents();
172 }
173 #endif
174
175 // Gets file path into ssl_keylog_file from command line argument or
176 // environment variable. Command line argument has priority when
177 // both specified.
178 std::string GetSSLKeyLogFile(const base::CommandLine& command_line) {
179 if (command_line.HasSwitch(switches::kSSLKeyLogFile)) {
180 std::string file =
181 command_line.GetSwitchValueASCII(switches::kSSLKeyLogFile);
182 if (!file.empty()) {
183 return file;
184 }
185
186 LOG(WARNING) << "ssl-key-log-file argument missing";
187 }
188 scoped_ptr<base::Environment> env(base::Environment::Create());
189 std::string file;
190 env->GetVar("SSLKEYLOGFILE", &file);
191 return file;
192 }
193
194 // Used for the "system" URLRequestContext. 122 // Used for the "system" URLRequestContext.
195 class SystemURLRequestContext : public net::URLRequestContext { 123 class SystemURLRequestContext : public net::URLRequestContext {
196 public: 124 public:
197 SystemURLRequestContext() { 125 SystemURLRequestContext() { net::SetURLRequestContextForNSSHttpIO(this); }
198 #if defined(USE_NSS_CERTS) || defined(OS_IOS)
199 net::SetURLRequestContextForNSSHttpIO(this);
200 #endif
201 }
202 126
203 private: 127 private:
204 ~SystemURLRequestContext() override { 128 ~SystemURLRequestContext() override {
205 AssertNoURLRequests(); 129 AssertNoURLRequests();
206 #if defined(USE_NSS_CERTS) || defined(OS_IOS) 130 net::SetURLRequestContextForNSSHttpIO(nullptr);
207 net::SetURLRequestContextForNSSHttpIO(NULL);
208 #endif
209 } 131 }
210 }; 132 };
211 133
212 scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) { 134 scoped_ptr<net::HostResolver> CreateGlobalHostResolver(net::NetLog* net_log) {
213 TRACE_EVENT0("startup", "IOThread::CreateGlobalHostResolver"); 135 TRACE_EVENT0("startup", "IOSChromeIOThread::CreateGlobalHostResolver");
214 const base::CommandLine& command_line = 136 const base::CommandLine& command_line =
215 *base::CommandLine::ForCurrentProcess(); 137 *base::CommandLine::ForCurrentProcess();
216 138
217 net::HostResolver::Options options; 139 scoped_ptr<net::HostResolver> global_host_resolver =
218 140 net::HostResolver::CreateSystemResolver(net::HostResolver::Options(),
219 // Use the retry attempts override from the command-line, if any. 141 net_log);
220 if (command_line.HasSwitch(switches::kHostResolverRetryAttempts)) {
221 std::string s =
222 command_line.GetSwitchValueASCII(switches::kHostResolverRetryAttempts);
223 // Parse the switch (it should be a non-negative integer).
224 int n;
225 if (base::StringToInt(s, &n) && n >= 0) {
226 options.max_retry_attempts = static_cast<size_t>(n);
227 } else {
228 LOG(ERROR) << "Invalid switch for host resolver retry attempts: " << s;
229 }
230 }
231
232 scoped_ptr<net::HostResolver> global_host_resolver;
233 #if defined OS_CHROMEOS
234 global_host_resolver =
235 chromeos::HostResolverImplChromeOS::CreateSystemResolver(options,
236 net_log);
237 #else
238 global_host_resolver =
239 net::HostResolver::CreateSystemResolver(options, net_log);
240 #endif
241 142
242 // If hostname remappings were specified on the command-line, layer these 143 // If hostname remappings were specified on the command-line, layer these
243 // rules on top of the real host resolver. This allows forwarding all requests 144 // rules on top of the real host resolver. This allows forwarding all requests
244 // through a designated test server. 145 // through a designated test server.
245 if (!command_line.HasSwitch(switches::kHostResolverRules)) 146 if (!command_line.HasSwitch(switches::kIOSHostResolverRules))
246 return global_host_resolver.Pass(); 147 return global_host_resolver.Pass();
247 148
248 scoped_ptr<net::MappedHostResolver> remapped_resolver( 149 scoped_ptr<net::MappedHostResolver> remapped_resolver(
249 new net::MappedHostResolver(global_host_resolver.Pass())); 150 new net::MappedHostResolver(global_host_resolver.Pass()));
250 remapped_resolver->SetRulesFromString( 151 remapped_resolver->SetRulesFromString(
251 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); 152 command_line.GetSwitchValueASCII(switches::kIOSHostResolverRules));
252 return remapped_resolver.Pass(); 153 return remapped_resolver.Pass();
253 } 154 }
254 155
255 int GetSwitchValueAsInt(const base::CommandLine& command_line, 156 int GetSwitchValueAsInt(const base::CommandLine& command_line,
256 const std::string& switch_name) { 157 const std::string& switch_name) {
257 int value; 158 int value;
258 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name), 159 if (!base::StringToInt(command_line.GetSwitchValueASCII(switch_name),
259 &value)) { 160 &value)) {
260 return 0; 161 return 0;
261 } 162 }
262 return value; 163 return value;
263 } 164 }
264 165
265 // Returns the value associated with |key| in |params| or "" if the 166 // Returns the value associated with |key| in |params| or "" if the
266 // key is not present in the map. 167 // key is not present in the map.
267 const std::string& GetVariationParam( 168 const std::string& GetVariationParam(
268 const std::map<std::string, std::string>& params, 169 const std::map<std::string, std::string>& params,
269 const std::string& key) { 170 const std::string& key) {
270 std::map<std::string, std::string>::const_iterator it = params.find(key); 171 std::map<std::string, std::string>::const_iterator it = params.find(key);
271 if (it == params.end()) 172 if (it == params.end())
272 return base::EmptyString(); 173 return base::EmptyString();
273 174
274 return it->second; 175 return it->second;
275 } 176 }
276 177
277 // Parse kUseSpdy command line flag options, which may contain the following:
278 //
279 // "off" : Disables SPDY support entirely.
280 // "no-ping" : Disables SPDY ping connection testing.
281 // "exclude=<host>" : Disables SPDY support for the host <host>.
282 // "no-compress" : Disables SPDY header compression.
283 // "init-max-streams=<limit>" : Specifies the maximum number of concurrent
284 // streams for a SPDY session, unless the
285 // specifies a different value via SETTINGS.
286 void ConfigureSpdyGlobalsFromUseSpdyArgument(const std::string& mode,
287 IOThread::Globals* globals) {
288 static const char kOff[] = "off";
289 static const char kDisablePing[] = "no-ping";
290 static const char kExclude[] = "exclude"; // Hosts to exclude
291 static const char kDisableCompression[] = "no-compress";
292 static const char kInitialMaxConcurrentStreams[] = "init-max-streams";
293
294 for (const base::StringPiece& element : base::SplitStringPiece(
295 mode, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
296 std::vector<base::StringPiece> name_value = base::SplitStringPiece(
297 element, "=", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
298 const base::StringPiece option =
299 name_value.size() > 0 ? name_value[0] : base::StringPiece();
300 const base::StringPiece value =
301 name_value.size() > 1 ? name_value[1] : base::StringPiece();
302
303 if (option == kOff) {
304 net::HttpStreamFactory::set_spdy_enabled(false);
305 continue;
306 }
307 if (option == kDisablePing) {
308 globals->enable_spdy_ping_based_connection_checking.set(false);
309 continue;
310 }
311 if (option == kExclude) {
312 globals->forced_spdy_exclusions.insert(
313 net::HostPortPair::FromURL(GURL(value.as_string())));
314 continue;
315 }
316 if (option == kDisableCompression) {
317 globals->enable_spdy_compression.set(false);
318 continue;
319 }
320 if (option == kInitialMaxConcurrentStreams) {
321 int streams;
322 if (base::StringToInt(value, &streams)) {
323 globals->initial_max_spdy_concurrent_streams.set(streams);
324 continue;
325 }
326 }
327 LOG(DFATAL) << "Unrecognized spdy option: " << option.as_string();
328 }
329 }
330
331 } // namespace 178 } // namespace
332 179
333 class IOThread::LoggingNetworkChangeObserver 180 class IOSChromeIOThread::LoggingNetworkChangeObserver
334 : public net::NetworkChangeNotifier::IPAddressObserver, 181 : public net::NetworkChangeNotifier::IPAddressObserver,
335 public net::NetworkChangeNotifier::ConnectionTypeObserver, 182 public net::NetworkChangeNotifier::ConnectionTypeObserver,
336 public net::NetworkChangeNotifier::NetworkChangeObserver { 183 public net::NetworkChangeNotifier::NetworkChangeObserver {
337 public: 184 public:
338 // |net_log| must remain valid throughout our lifetime. 185 // |net_log| must remain valid throughout our lifetime.
339 explicit LoggingNetworkChangeObserver(net::NetLog* net_log) 186 explicit LoggingNetworkChangeObserver(net::NetLog* net_log)
340 : net_log_(net_log) { 187 : net_log_(net_log) {
341 net::NetworkChangeNotifier::AddIPAddressObserver(this); 188 net::NetworkChangeNotifier::AddIPAddressObserver(this);
342 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 189 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
343 net::NetworkChangeNotifier::AddNetworkChangeObserver(this); 190 net::NetworkChangeNotifier::AddNetworkChangeObserver(this);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 net::NetLog::StringCallback("new_connection_type", &type_as_string)); 230 net::NetLog::StringCallback("new_connection_type", &type_as_string));
384 } 231 }
385 232
386 private: 233 private:
387 net::NetLog* net_log_; 234 net::NetLog* net_log_;
388 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); 235 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver);
389 }; 236 };
390 237
391 class SystemURLRequestContextGetter : public net::URLRequestContextGetter { 238 class SystemURLRequestContextGetter : public net::URLRequestContextGetter {
392 public: 239 public:
393 explicit SystemURLRequestContextGetter(IOThread* io_thread); 240 explicit SystemURLRequestContextGetter(IOSChromeIOThread* io_thread);
394 241
395 // Implementation for net::UrlRequestContextGetter. 242 // Implementation for net::UrlRequestContextGetter.
396 net::URLRequestContext* GetURLRequestContext() override; 243 net::URLRequestContext* GetURLRequestContext() override;
397 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() 244 scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
398 const override; 245 const override;
399 246
400 protected: 247 protected:
401 ~SystemURLRequestContextGetter() override; 248 ~SystemURLRequestContextGetter() override;
402 249
403 private: 250 private:
404 IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess. 251 IOSChromeIOThread* const
252 io_thread_; // Weak pointer, owned by ApplicationContext.
405 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 253 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
406 254
407 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; 255 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_;
408 }; 256 };
409 257
410 SystemURLRequestContextGetter::SystemURLRequestContextGetter( 258 SystemURLRequestContextGetter::SystemURLRequestContextGetter(
411 IOThread* io_thread) 259 IOSChromeIOThread* io_thread)
412 : io_thread_(io_thread), 260 : io_thread_(io_thread),
413 network_task_runner_( 261 network_task_runner_(
414 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) { 262 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)) {}
415 }
416 263
417 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} 264 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {}
418 265
419 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { 266 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() {
420 DCHECK_CURRENTLY_ON(BrowserThread::IO); 267 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO);
421 DCHECK(io_thread_->globals()->system_request_context.get()); 268 DCHECK(io_thread_->globals()->system_request_context.get());
422 269
423 return io_thread_->globals()->system_request_context.get(); 270 return io_thread_->globals()->system_request_context.get();
424 } 271 }
425 272
426 scoped_refptr<base::SingleThreadTaskRunner> 273 scoped_refptr<base::SingleThreadTaskRunner>
427 SystemURLRequestContextGetter::GetNetworkTaskRunner() const { 274 SystemURLRequestContextGetter::GetNetworkTaskRunner() const {
428 return network_task_runner_; 275 return network_task_runner_;
429 } 276 }
430 277
431 IOThread::Globals:: 278 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker::
432 SystemRequestContextLeakChecker::SystemRequestContextLeakChecker( 279 SystemRequestContextLeakChecker(Globals* globals)
433 Globals* globals)
434 : globals_(globals) { 280 : globals_(globals) {
435 DCHECK(globals_); 281 DCHECK(globals_);
436 } 282 }
437 283
438 IOThread::Globals:: 284 IOSChromeIOThread::Globals::SystemRequestContextLeakChecker::
439 SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() { 285 ~SystemRequestContextLeakChecker() {
440 if (globals_->system_request_context.get()) 286 if (globals_->system_request_context.get())
441 globals_->system_request_context->AssertNoURLRequests(); 287 globals_->system_request_context->AssertNoURLRequests();
442 } 288 }
443 289
444 IOThread::Globals::Globals() 290 IOSChromeIOThread::Globals::Globals()
445 : system_request_context_leak_checker(this), 291 : system_request_context_leak_checker(this),
446 ignore_certificate_errors(false),
447 testing_fixed_http_port(0), 292 testing_fixed_http_port(0),
448 testing_fixed_https_port(0), 293 testing_fixed_https_port(0) {}
449 enable_user_alternate_protocol_ports(false) {
450 }
451 294
452 IOThread::Globals::~Globals() {} 295 IOSChromeIOThread::Globals::~Globals() {}
453 296
454 // |local_state| is passed in explicitly in order to (1) reduce implicit 297 // |local_state| is passed in explicitly in order to (1) reduce implicit
455 // dependencies and (2) make IOThread more flexible for testing. 298 // dependencies and (2) make IOSChromeIOThread more flexible for testing.
456 IOThread::IOThread( 299 IOSChromeIOThread::IOSChromeIOThread(PrefService* local_state,
457 PrefService* local_state, 300 net_log::ChromeNetLog* net_log)
458 policy::PolicyService* policy_service,
459 net_log::ChromeNetLog* net_log,
460 extensions::EventRouterForwarder* extension_event_router_forwarder)
461 : net_log_(net_log), 301 : net_log_(net_log),
462 #if defined(ENABLE_EXTENSIONS) 302 globals_(nullptr),
463 extension_event_router_forwarder_(extension_event_router_forwarder),
464 #endif
465 globals_(NULL),
466 is_spdy_disabled_by_policy_(false),
467 is_quic_allowed_by_policy_(true),
468 creation_time_(base::TimeTicks::Now()), 303 creation_time_(base::TimeTicks::Now()),
469 weak_factory_(this) { 304 weak_factory_(this) {
470 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); 305 pref_proxy_config_tracker_ =
471 negotiate_disable_cname_lookup_ = local_state->GetBoolean( 306 ios::ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
472 prefs::kDisableAuthNegotiateCnameLookup); 307 local_state);
473 negotiate_enable_port_ = local_state->GetBoolean( 308 IOSChromeNetworkDelegate::InitializePrefsOnUIThread(nullptr, local_state);
474 prefs::kEnableAuthNegotiatePort);
475 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist);
476 auth_delegate_whitelist_ = local_state->GetString(
477 prefs::kAuthNegotiateDelegateWhitelist);
478 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
479 auth_android_negotiate_account_type_ =
480 local_state->GetString(prefs::kAuthAndroidNegotiateAccountType);
481 pref_proxy_config_tracker_.reset(
482 ProxyServiceFactory::CreatePrefProxyConfigTrackerOfLocalState(
483 local_state));
484 ChromeNetworkDelegate::InitializePrefsOnUIThread(
485 &system_enable_referrers_,
486 NULL,
487 NULL,
488 NULL,
489 local_state);
490 ssl_config_service_manager_.reset( 309 ssl_config_service_manager_.reset(
491 ssl_config::SSLConfigServiceManager::CreateDefaultManager( 310 ssl_config::SSLConfigServiceManager::CreateDefaultManager(
492 local_state, 311 local_state,
493 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); 312 web::WebThread::GetTaskRunnerForThread(web::WebThread::IO)));
494 313
495 base::Value* dns_client_enabled_default = new base::FundamentalValue( 314 web::WebThread::SetDelegate(web::WebThread::IO, this);
496 chrome_browser_net::ConfigureAsyncDnsFieldTrial());
497 local_state->SetDefaultPrefValue(prefs::kBuiltInDnsClientEnabled,
498 dns_client_enabled_default);
499 chrome_browser_net::LogAsyncDnsPrefSource(
500 local_state->FindPreference(prefs::kBuiltInDnsClientEnabled));
501
502 dns_client_enabled_.Init(prefs::kBuiltInDnsClientEnabled,
503 local_state,
504 base::Bind(&IOThread::UpdateDnsClientEnabled,
505 base::Unretained(this)));
506 dns_client_enabled_.MoveToThread(
507 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
508
509 quick_check_enabled_.Init(prefs::kQuickCheckEnabled,
510 local_state);
511 quick_check_enabled_.MoveToThread(
512 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
513
514 #if defined(ENABLE_CONFIGURATION_POLICY)
515 is_spdy_disabled_by_policy_ = policy_service->GetPolicies(
516 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, std::string())).Get(
517 policy::key::kDisableSpdy) != NULL;
518
519 const base::Value* value = policy_service->GetPolicies(
520 policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME,
521 std::string())).GetValue(policy::key::kQuicAllowed);
522 if (value)
523 value->GetAsBoolean(&is_quic_allowed_by_policy_);
524 #endif // ENABLE_CONFIGURATION_POLICY
525
526 BrowserThread::SetDelegate(BrowserThread::IO, this);
527 } 315 }
528 316
529 IOThread::~IOThread() { 317 IOSChromeIOThread::~IOSChromeIOThread() {
530 // This isn't needed for production code, but in tests, IOThread may 318 // This isn't needed for production code, but in tests, IOSChromeIOThread may
531 // be multiply constructed. 319 // be multiply constructed.
532 BrowserThread::SetDelegate(BrowserThread::IO, NULL); 320 web::WebThread::SetDelegate(web::WebThread::IO, nullptr);
533 321
534 pref_proxy_config_tracker_->DetachFromPrefService(); 322 pref_proxy_config_tracker_->DetachFromPrefService();
535 DCHECK(!globals_); 323 DCHECK(!globals_);
536 } 324 }
537 325
538 IOThread::Globals* IOThread::globals() { 326 IOSChromeIOThread::Globals* IOSChromeIOThread::globals() {
539 DCHECK_CURRENTLY_ON(BrowserThread::IO); 327 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO);
540 return globals_; 328 return globals_;
541 } 329 }
542 330
543 void IOThread::SetGlobalsForTesting(Globals* globals) { 331 void IOSChromeIOThread::SetGlobalsForTesting(Globals* globals) {
544 DCHECK_CURRENTLY_ON(BrowserThread::IO); 332 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO);
545 DCHECK(!globals || !globals_); 333 DCHECK(!globals || !globals_);
546 globals_ = globals; 334 globals_ = globals;
547 } 335 }
548 336
549 net_log::ChromeNetLog* IOThread::net_log() { 337 net_log::ChromeNetLog* IOSChromeIOThread::net_log() {
550 return net_log_; 338 return net_log_;
551 } 339 }
552 340
553 void IOThread::ChangedToOnTheRecord() { 341 void IOSChromeIOThread::ChangedToOnTheRecord() {
554 DCHECK_CURRENTLY_ON(BrowserThread::UI); 342 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
555 BrowserThread::PostTask( 343 web::WebThread::PostTask(
556 BrowserThread::IO, 344 web::WebThread::IO, FROM_HERE,
557 FROM_HERE, 345 base::Bind(&IOSChromeIOThread::ChangedToOnTheRecordOnIOThread,
558 base::Bind(&IOThread::ChangedToOnTheRecordOnIOThread,
559 base::Unretained(this))); 346 base::Unretained(this)));
560 } 347 }
561 348
562 net::URLRequestContextGetter* IOThread::system_url_request_context_getter() { 349 net::URLRequestContextGetter*
563 DCHECK_CURRENTLY_ON(BrowserThread::UI); 350 IOSChromeIOThread::system_url_request_context_getter() {
351 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
564 if (!system_url_request_context_getter_.get()) { 352 if (!system_url_request_context_getter_.get()) {
565 InitSystemRequestContext(); 353 InitSystemRequestContext();
566 } 354 }
567 return system_url_request_context_getter_.get(); 355 return system_url_request_context_getter_.get();
568 } 356 }
569 357
570 void IOThread::Init() { 358 void IOSChromeIOThread::Init() {
571 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 359 TRACE_EVENT0("startup", "IOSChromeIOThread::InitAsync");
572 // is fixed. 360 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO);
573 tracked_objects::ScopedTracker tracking_profile1(
574 FROM_HERE_WITH_EXPLICIT_FUNCTION("466432 IOThread::InitAsync::Start"));
575 TRACE_EVENT0("startup", "IOThread::InitAsync");
576 DCHECK_CURRENTLY_ON(BrowserThread::IO);
577 361
578 #if defined(USE_NSS_CERTS) || defined(OS_IOS)
579 net::SetMessageLoopForNSSHttpIO(); 362 net::SetMessageLoopForNSSHttpIO();
580 #endif
581 363
582 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
583 // is fixed.
584 tracked_objects::ScopedTracker tracking_profile2(
585 FROM_HERE_WITH_EXPLICIT_FUNCTION(
586 "466432 IOThread::InitAsync::CommandLineForCurrentProcess"));
587 const base::CommandLine& command_line = 364 const base::CommandLine& command_line =
588 *base::CommandLine::ForCurrentProcess(); 365 *base::CommandLine::ForCurrentProcess();
589 366
590 // Export ssl keys if log file specified.
591 std::string ssl_keylog_file = GetSSLKeyLogFile(command_line);
592 if (!ssl_keylog_file.empty()) {
593 net::SSLClientSocket::SetSSLKeyLogFile(ssl_keylog_file);
594 }
595
596 DCHECK(!globals_); 367 DCHECK(!globals_);
597 globals_ = new Globals; 368 globals_ = new Globals;
598 369
599 // Add an observer that will emit network change events to the ChromeNetLog. 370 // Add an observer that will emit network change events to the ChromeNetLog.
600 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be 371 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be
601 // logging the network change before other IO thread consumers respond to it. 372 // logging the network change before other IO thread consumers respond to it.
602 network_change_observer_.reset( 373 network_change_observer_.reset(new LoggingNetworkChangeObserver(net_log_));
603 new LoggingNetworkChangeObserver(net_log_));
604 374
605 // Setup the HistogramWatcher to run on the IO thread. 375 // Setup the HistogramWatcher to run on the IO thread.
606 net::NetworkChangeNotifier::InitHistogramWatcher(); 376 net::NetworkChangeNotifier::InitHistogramWatcher();
607 377
608 #if defined(ENABLE_EXTENSIONS) 378 scoped_ptr<IOSChromeNetworkDelegate> chrome_network_delegate(
609 globals_->extension_event_router_forwarder = 379 new IOSChromeNetworkDelegate());
610 extension_event_router_forwarder_;
611 #endif
612 380
613 scoped_ptr<data_usage::DataUseAmortizer> data_use_amortizer;
614 #if defined(OS_ANDROID)
615 data_use_amortizer.reset(new data_usage::android::TrafficStatsAmortizer());
616 #endif
617
618 globals_->data_use_aggregator.reset(new data_usage::DataUseAggregator(
619 scoped_ptr<data_usage::DataUseAnnotator>(
620 new chrome_browser_data_usage::TabIdAnnotator()),
621 data_use_amortizer.Pass()));
622
623 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
624 // is fixed.
625 tracked_objects::ScopedTracker tracking_profile3(
626 FROM_HERE_WITH_EXPLICIT_FUNCTION(
627 "466432 IOThread::InitAsync::ChromeNetworkDelegate"));
628 scoped_ptr<ChromeNetworkDelegate> chrome_network_delegate(
629 new ChromeNetworkDelegate(extension_event_router_forwarder(),
630 &system_enable_referrers_));
631 // By default, data usage is considered off the record.
632 chrome_network_delegate->set_data_use_aggregator(
633 globals_->data_use_aggregator.get(),
634 true /* is_data_usage_off_the_record */);
635
636 #if defined(OS_ANDROID)
637 globals_->external_data_use_observer.reset(
638 new chrome::android::ExternalDataUseObserver(
639 globals_->data_use_aggregator.get(),
640 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
641 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)));
642 #endif
643
644 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
645 // is fixed.
646 tracked_objects::ScopedTracker tracking_profile4(
647 FROM_HERE_WITH_EXPLICIT_FUNCTION(
648 "466432 IOThread::InitAsync::CreateGlobalHostResolver"));
649 globals_->system_network_delegate = chrome_network_delegate.Pass(); 381 globals_->system_network_delegate = chrome_network_delegate.Pass();
650 globals_->host_resolver = CreateGlobalHostResolver(net_log_); 382 globals_->host_resolver = CreateGlobalHostResolver(net_log_);
651 383
652 std::map<std::string, std::string> network_quality_estimator_params; 384 std::map<std::string, std::string> network_quality_estimator_params;
653 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName, 385 variations::GetVariationParams(kNetworkQualityEstimatorFieldTrialName,
654 &network_quality_estimator_params); 386 &network_quality_estimator_params);
655 387
656 scoped_ptr<net::ExternalEstimateProvider> external_estimate_provider; 388 scoped_ptr<net::ExternalEstimateProvider> external_estimate_provider;
657 #if defined(OS_ANDROID)
658 external_estimate_provider.reset(
659 new chrome::android::ExternalEstimateProviderAndroid());
660 #endif
661 // Pass ownership. 389 // Pass ownership.
662 globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator( 390 globals_->network_quality_estimator.reset(new net::NetworkQualityEstimator(
663 external_estimate_provider.Pass(), network_quality_estimator_params)); 391 external_estimate_provider.Pass(), network_quality_estimator_params));
664 392
665 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 393 globals_->cert_verifier.reset(
666 // is fixed. 394 new net::MultiThreadedCertVerifier(net::CertVerifyProc::CreateDefault()));
667 tracked_objects::ScopedTracker tracking_profile5(
668 FROM_HERE_WITH_EXPLICIT_FUNCTION(
669 "466432 IOThread::InitAsync::UpdateDnsClientEnabled::Start"));
670 UpdateDnsClientEnabled();
671 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
672 // is fixed.
673 tracked_objects::ScopedTracker tracking_profile6(
674 FROM_HERE_WITH_EXPLICIT_FUNCTION(
675 "466432 IOThread::InitAsync::UpdateDnsClientEnabled::End"));
676 #if defined(OS_CHROMEOS)
677 // Creates a CertVerifyProc that doesn't allow any profile-provided certs.
678 globals_->cert_verifier.reset(new net::MultiThreadedCertVerifier(
679 new chromeos::CertVerifyProcChromeOS()));
680 #else
681 globals_->cert_verifier.reset(new net::MultiThreadedCertVerifier(
682 net::CertVerifyProc::CreateDefault()));
683 #endif
684 395
685 globals_->transport_security_state.reset(new net::TransportSecurityState()); 396 globals_->transport_security_state.reset(new net::TransportSecurityState());
686 397
687 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
688 // is fixed.
689 tracked_objects::ScopedTracker tracking_profile8(
690 FROM_HERE_WITH_EXPLICIT_FUNCTION(
691 "466432 IOThread::InitAsync::CreateLogVerifiers::Start"));
692 std::vector<scoped_refptr<net::CTLogVerifier>> ct_logs( 398 std::vector<scoped_refptr<net::CTLogVerifier>> ct_logs(
693 net::ct::CreateLogVerifiersForKnownLogs()); 399 net::ct::CreateLogVerifiersForKnownLogs());
694 400
695 // Add logs from command line
696 if (command_line.HasSwitch(switches::kCertificateTransparencyLog)) {
697 std::string switch_value = command_line.GetSwitchValueASCII(
698 switches::kCertificateTransparencyLog);
699 for (const base::StringPiece& curr_log : base::SplitStringPiece(
700 switch_value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
701 std::vector<std::string> log_metadata = base::SplitString(
702 curr_log, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
703 CHECK_GE(log_metadata.size(), 3u)
704 << "CT log metadata missing: Switch format is "
705 << "'description:base64_key:url_without_schema'.";
706 std::string log_description(log_metadata[0]);
707 std::string log_url(std::string("https://") + log_metadata[2]);
708 std::string ct_public_key_data;
709 CHECK(base::Base64Decode(log_metadata[1], &ct_public_key_data))
710 << "Unable to decode CT public key.";
711 scoped_refptr<net::CTLogVerifier> external_log_verifier(
712 net::CTLogVerifier::Create(ct_public_key_data, log_description,
713 log_url));
714 CHECK(external_log_verifier) << "Unable to parse CT public key.";
715 VLOG(1) << "Adding log with description " << log_description;
716 ct_logs.push_back(external_log_verifier);
717 }
718 }
719
720 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
721 // is fixed.
722 tracked_objects::ScopedTracker tracking_profile9(
723 FROM_HERE_WITH_EXPLICIT_FUNCTION(
724 "466432 IOThread::InitAsync::CreateLogVerifiers::End"));
725 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
726 // is fixed.
727 tracked_objects::ScopedTracker tracking_profile7(
728 FROM_HERE_WITH_EXPLICIT_FUNCTION(
729 "466432 IOThread::InitAsync::CreateMultiLogVerifier"));
730 net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier(); 401 net::MultiLogCTVerifier* ct_verifier = new net::MultiLogCTVerifier();
731 globals_->cert_transparency_verifier.reset(ct_verifier); 402 globals_->cert_transparency_verifier.reset(ct_verifier);
732 // Add built-in logs 403 // Add built-in logs
733 ct_verifier->AddLogs(ct_logs); 404 ct_verifier->AddLogs(ct_logs);
734 405
735 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
736 // is fixed.
737 tracked_objects::ScopedTracker tracking_profile10(
738 FROM_HERE_WITH_EXPLICIT_FUNCTION(
739 "466432 IOThread::InitAsync::CertPolicyEnforcer"));
740 net::CertPolicyEnforcer* policy_enforcer = new net::CertPolicyEnforcer; 406 net::CertPolicyEnforcer* policy_enforcer = new net::CertPolicyEnforcer;
741 globals_->cert_policy_enforcer.reset(policy_enforcer); 407 globals_->cert_policy_enforcer.reset(policy_enforcer);
742 408
743 globals_->ssl_config_service = GetSSLConfigService(); 409 globals_->ssl_config_service = GetSSLConfigService();
744 410
745 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( 411 globals_->http_auth_handler_factory.reset(
746 globals_->host_resolver.get())); 412 CreateDefaultAuthHandlerFactory(globals_->host_resolver.get()));
747 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl()); 413 globals_->http_server_properties.reset(new net::HttpServerPropertiesImpl());
748 // For the ProxyScriptFetcher, we use a direct ProxyService.
749 globals_->proxy_script_fetcher_proxy_service =
750 net::ProxyService::CreateDirectWithNetLog(net_log_);
751 // In-memory cookie store. 414 // In-memory cookie store.
752 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 415 globals_->system_cookie_store = new net::CookieMonster(nullptr, nullptr);
753 // is fixed.
754 tracked_objects::ScopedTracker tracking_profile11(
755 FROM_HERE_WITH_EXPLICIT_FUNCTION(
756 "466432 IOThread::InitAsync::CreateCookieStore::Start"));
757 globals_->system_cookie_store =
758 content::CreateCookieStore(content::CookieStoreConfig());
759 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
760 // is fixed.
761 tracked_objects::ScopedTracker tracking_profile12(
762 FROM_HERE_WITH_EXPLICIT_FUNCTION(
763 "466432 IOThread::InitAsync::CreateCookieStore::End"));
764 // In-memory channel ID store. 416 // In-memory channel ID store.
765 globals_->system_channel_id_service.reset( 417 globals_->system_channel_id_service.reset(
766 new net::ChannelIDService( 418 new net::ChannelIDService(new net::DefaultChannelIDStore(nullptr),
767 new net::DefaultChannelIDStore(NULL), 419 base::WorkerPool::GetTaskRunner(true)));
768 base::WorkerPool::GetTaskRunner(true))); 420 globals_->http_user_agent_settings.reset(new net::StaticHttpUserAgentSettings(
769 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432 421 std::string(), web::GetWebClient()->GetUserAgent(false)));
770 // is fixed. 422 if (command_line.HasSwitch(switches::kIOSTestingFixedHttpPort)) {
771 tracked_objects::ScopedTracker tracking_profile12_1( 423 globals_->testing_fixed_http_port =
772 FROM_HERE_WITH_EXPLICIT_FUNCTION( 424 GetSwitchValueAsInt(command_line, switches::kIOSTestingFixedHttpPort);
773 "466432 IOThread::InitAsync::CreateDnsProbeService"));
774 globals_->dns_probe_service.reset(new chrome_browser_net::DnsProbeService());
775 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
776 // is fixed.
777 tracked_objects::ScopedTracker tracking_profile12_2(
778 FROM_HERE_WITH_EXPLICIT_FUNCTION(
779 "466432 IOThread::InitAsync::CreateHostMappingRules"));
780 globals_->host_mapping_rules.reset(new net::HostMappingRules());
781 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
782 // is fixed.
783 tracked_objects::ScopedTracker tracking_profile12_3(
784 FROM_HERE_WITH_EXPLICIT_FUNCTION(
785 "466432 IOThread::InitAsync::CreateHTTPUserAgentSettings"));
786 globals_->http_user_agent_settings.reset(
787 new net::StaticHttpUserAgentSettings(std::string(), GetUserAgent()));
788 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
789 // is fixed.
790 tracked_objects::ScopedTracker tracking_profile12_4(
791 FROM_HERE_WITH_EXPLICIT_FUNCTION(
792 "466432 IOThread::InitAsync::CommandLineConfiguration"));
793 if (command_line.HasSwitch(switches::kHostRules)) {
794 TRACE_EVENT_BEGIN0("startup", "IOThread::InitAsync:SetRulesFromString");
795 globals_->host_mapping_rules->SetRulesFromString(
796 command_line.GetSwitchValueASCII(switches::kHostRules));
797 TRACE_EVENT_END0("startup", "IOThread::InitAsync:SetRulesFromString");
798 } 425 }
799 if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) 426 if (command_line.HasSwitch(switches::kIOSTestingFixedHttpsPort)) {
800 globals_->ignore_certificate_errors = true; 427 globals_->testing_fixed_https_port =
801 if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { 428 GetSwitchValueAsInt(command_line, switches::kIOSTestingFixedHttpsPort);
802 globals_->testing_fixed_http_port =
803 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort);
804 } 429 }
805 if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { 430 ConfigureQuic();
806 globals_->testing_fixed_https_port = 431 InitializeNetworkOptions();
807 GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpsPort);
808 }
809 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
810 // is fixed.
811 tracked_objects::ScopedTracker tracking_profile12_5(
812 FROM_HERE_WITH_EXPLICIT_FUNCTION(
813 "466432 IOThread::InitAsync::QuicConfiguration"));
814 ConfigureQuic(command_line);
815 if (command_line.HasSwitch(
816 switches::kEnableUserAlternateProtocolPorts)) {
817 globals_->enable_user_alternate_protocol_ports = true;
818 }
819 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
820 // is fixed.
821 tracked_objects::ScopedTracker tracking_profile13(
822 FROM_HERE_WITH_EXPLICIT_FUNCTION(
823 "466432 IOThread::InitAsync::InitializeNetworkOptions"));
824 InitializeNetworkOptions(command_line);
825 432
826 TRACE_EVENT_BEGIN0("startup", 433 const version_info::Channel channel = ::GetChannel();
827 "IOThread::Init:ProxyScriptFetcherRequestContext");
828 globals_->proxy_script_fetcher_context.reset(
829 ConstructProxyScriptFetcherContext(globals_, net_log_));
830 TRACE_EVENT_END0("startup",
831 "IOThread::Init:ProxyScriptFetcherRequestContext");
832
833 const version_info::Channel channel = chrome::GetChannel();
834 if (channel == version_info::Channel::UNKNOWN || 434 if (channel == version_info::Channel::UNKNOWN ||
835 channel == version_info::Channel::CANARY || 435 channel == version_info::Channel::CANARY ||
836 channel == version_info::Channel::DEV) { 436 channel == version_info::Channel::DEV) {
837 globals_->url_request_backoff_manager.reset( 437 globals_->url_request_backoff_manager.reset(
838 new net::URLRequestBackoffManager()); 438 new net::URLRequestBackoffManager());
839 } 439 }
840 440
841 #if defined(OS_MACOSX) && !defined(OS_IOS)
842 // Start observing Keychain events. This needs to be done on the UI thread,
843 // as Keychain services requires a CFRunLoop.
844 BrowserThread::PostTask(BrowserThread::UI,
845 FROM_HERE,
846 base::Bind(&ObserveKeychainEvents));
847 #endif
848
849 // InitSystemRequestContext turns right around and posts a task back 441 // InitSystemRequestContext turns right around and posts a task back
850 // to the IO thread, so we can't let it run until we know the IO 442 // to the IO thread, so we can't let it run until we know the IO
851 // thread has started. 443 // thread has started.
852 // 444 //
853 // Note that since we are at BrowserThread::Init time, the UI thread 445 // Note that since we are at WebThread::Init time, the UI thread
854 // is blocked waiting for the thread to start. Therefore, posting 446 // is blocked waiting for the thread to start. Therefore, posting
855 // this task to the main thread's message loop here is guaranteed to 447 // this task to the main thread's message loop here is guaranteed to
856 // get it onto the message loop while the IOThread object still 448 // get it onto the message loop while the IOSChromeIOThread object still
857 // exists. However, the message might not be processed on the UI 449 // exists. However, the message might not be processed on the UI
858 // thread until after IOThread is gone, so use a weak pointer. 450 // thread until after IOSChromeIOThread is gone, so use a weak pointer.
859 BrowserThread::PostTask(BrowserThread::UI, 451 web::WebThread::PostTask(
860 FROM_HERE, 452 web::WebThread::UI, FROM_HERE,
861 base::Bind(&IOThread::InitSystemRequestContext, 453 base::Bind(&IOSChromeIOThread::InitSystemRequestContext,
862 weak_factory_.GetWeakPtr())); 454 weak_factory_.GetWeakPtr()));
863 } 455 }
864 456
865 void IOThread::CleanUp() { 457 void IOSChromeIOThread::InitAsync() {}
866 base::debug::LeakTracker<SafeBrowsingURLRequestContext>::CheckForLeaks();
867 458
868 #if defined(USE_NSS_CERTS) || defined(OS_IOS) 459 void IOSChromeIOThread::CleanUp() {
869 net::ShutdownNSSHttpIO(); 460 net::ShutdownNSSHttpIO();
870 #endif
871 461
872 system_url_request_context_getter_ = NULL; 462 system_url_request_context_getter_ = nullptr;
873 463
874 // Release objects that the net::URLRequestContext could have been pointing 464 // Release objects that the net::URLRequestContext could have been pointing
875 // to. 465 // to.
876 466
877 // Shutdown the HistogramWatcher on the IO thread. 467 // Shutdown the HistogramWatcher on the IO thread.
878 net::NetworkChangeNotifier::ShutdownHistogramWatcher(); 468 net::NetworkChangeNotifier::ShutdownHistogramWatcher();
879 469
880 // This must be reset before the ChromeNetLog is destroyed. 470 // This must be reset before the ChromeNetLog is destroyed.
881 network_change_observer_.reset(); 471 network_change_observer_.reset();
882 472
883 system_proxy_config_service_.reset(); 473 system_proxy_config_service_.reset();
884 474
885 delete globals_; 475 delete globals_;
886 globals_ = NULL; 476 globals_ = nullptr;
887 477
888 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); 478 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
889 } 479 }
890 480
891 void IOThread::InitializeNetworkOptions(const base::CommandLine& command_line) { 481 void IOSChromeIOThread::InitializeNetworkOptions() {
892 // Only handle use-spdy command line flags if "spdy.disabled" preference is 482 std::string group = base::FieldTrialList::FindFullName(kSpdyFieldTrialName);
893 // not disabled via policy. 483 VariationParameters params;
894 if (is_spdy_disabled_by_policy_) { 484 if (!variations::GetVariationParams(kSpdyFieldTrialName, &params)) {
895 base::FieldTrial* trial = base::FieldTrialList::Find(kSpdyFieldTrialName); 485 params.clear();
896 if (trial)
897 trial->Disable();
898 } else {
899 std::string group = base::FieldTrialList::FindFullName(kSpdyFieldTrialName);
900 VariationParameters params;
901 if (!variations::GetVariationParams(kSpdyFieldTrialName, &params)) {
902 params.clear();
903 }
904 ConfigureSpdyGlobals(command_line, group, params, globals_);
905 } 486 }
487 ConfigureSpdyGlobals(group, params, globals_);
906 488
907 ConfigureTCPFastOpen(command_line); 489 ConfigureSSLTCPFastOpen();
908 490
909 ConfigureNPNGlobals(base::FieldTrialList::FindFullName(kNpnTrialName), 491 ConfigureNPNGlobals(base::FieldTrialList::FindFullName(kNpnTrialName),
910 globals_); 492 globals_);
911 493
912 // TODO(rch): Make the client socket factory a per-network session 494 // TODO(rch): Make the client socket factory a per-network session
913 // instance, constructed from a NetworkSession::Params, to allow us 495 // instance, constructed from a NetworkSession::Params, to allow us
914 // to move this option to IOThread::Globals & 496 // to move this option to IOSChromeIOThread::Globals &
915 // HttpNetworkSession::Params. 497 // HttpNetworkSession::Params.
916 } 498 }
917 499
918 void IOThread::ConfigureTCPFastOpen(const base::CommandLine& command_line) { 500 void IOSChromeIOThread::ConfigureSSLTCPFastOpen() {
919 const std::string trial_group = 501 const std::string trial_group =
920 base::FieldTrialList::FindFullName(kTCPFastOpenFieldTrialName); 502 base::FieldTrialList::FindFullName(kTCPFastOpenFieldTrialName);
921 if (trial_group == kTCPFastOpenHttpsEnabledGroupName) 503 if (trial_group == kTCPFastOpenHttpsEnabledGroupName)
922 globals_->enable_tcp_fast_open_for_ssl.set(true); 504 globals_->enable_tcp_fast_open_for_ssl.set(true);
923 bool always_enable_if_supported =
924 command_line.HasSwitch(switches::kEnableTcpFastOpen);
925 // Check for OS support of TCP FastOpen, and turn it on for all connections
926 // if indicated by user.
927 net::CheckSupportAndMaybeEnableTCPFastOpen(always_enable_if_supported);
928 } 505 }
929 506
930 // static 507 // static
931 void IOThread::ConfigureSpdyGlobals( 508 void IOSChromeIOThread::ConfigureSpdyGlobals(
932 const base::CommandLine& command_line,
933 base::StringPiece spdy_trial_group, 509 base::StringPiece spdy_trial_group,
934 const VariationParameters& spdy_trial_params, 510 const VariationParameters& spdy_trial_params,
935 IOThread::Globals* globals) { 511 IOSChromeIOThread::Globals* globals) {
936 if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) {
937 globals->trusted_spdy_proxy.set(
938 command_line.GetSwitchValueASCII(switches::kTrustedSpdyProxy));
939 }
940 if (command_line.HasSwitch(switches::kIgnoreUrlFetcherCertRequests))
941 net::URLFetcher::SetIgnoreCertificateRequests(true);
942
943 if (command_line.HasSwitch(switches::kUseSpdy)) {
944 std::string spdy_mode =
945 command_line.GetSwitchValueASCII(switches::kUseSpdy);
946 ConfigureSpdyGlobalsFromUseSpdyArgument(spdy_mode, globals);
947 return;
948 }
949
950 globals->next_protos.clear(); 512 globals->next_protos.clear();
951 513
952 bool enable_quic = false; 514 bool enable_quic = false;
953 globals->enable_quic.CopyToIfSet(&enable_quic); 515 globals->enable_quic.CopyToIfSet(&enable_quic);
954 if (enable_quic) { 516 if (enable_quic) {
955 globals->next_protos.push_back(net::kProtoQUIC1SPDY3); 517 globals->next_protos.push_back(net::kProtoQUIC1SPDY3);
956 } 518 }
957 519
958 // No SPDY command-line flags have been specified. Examine trial groups. 520 // No SPDY command-line flags have been specified. Examine trial groups.
959 if (spdy_trial_group.starts_with(kSpdyFieldTrialHoldbackGroupNamePrefix)) { 521 if (spdy_trial_group.starts_with(kSpdyFieldTrialHoldbackGroupNamePrefix)) {
(...skipping 24 matching lines...) Expand all
984 // By default, enable HTTP/2. 546 // By default, enable HTTP/2.
985 globals->next_protos.push_back(net::kProtoHTTP2); 547 globals->next_protos.push_back(net::kProtoHTTP2);
986 globals->next_protos.push_back(net::kProtoSPDY31); 548 globals->next_protos.push_back(net::kProtoSPDY31);
987 } 549 }
988 550
989 // Enable HTTP/1.1 in all cases as the last protocol. 551 // Enable HTTP/1.1 in all cases as the last protocol.
990 globals->next_protos.push_back(net::kProtoHTTP11); 552 globals->next_protos.push_back(net::kProtoHTTP11);
991 } 553 }
992 554
993 // static 555 // static
994 void IOThread::ConfigureNPNGlobals(base::StringPiece npn_trial_group, 556 void IOSChromeIOThread::ConfigureNPNGlobals(
995 IOThread::Globals* globals) { 557 base::StringPiece npn_trial_group,
558 IOSChromeIOThread::Globals* globals) {
996 if (npn_trial_group.starts_with(kNpnTrialEnabledGroupNamePrefix)) { 559 if (npn_trial_group.starts_with(kNpnTrialEnabledGroupNamePrefix)) {
997 globals->enable_npn.set(true); 560 globals->enable_npn.set(true);
998 } else if (npn_trial_group.starts_with(kNpnTrialDisabledGroupNamePrefix)) { 561 } else if (npn_trial_group.starts_with(kNpnTrialDisabledGroupNamePrefix)) {
999 globals->enable_npn.set(false); 562 globals->enable_npn.set(false);
1000 } 563 }
1001 } 564 }
1002 565
1003 void IOThread::RegisterPrefs(PrefRegistrySimple* registry) { 566 net::HttpAuthHandlerFactory* IOSChromeIOThread::CreateDefaultAuthHandlerFactory(
1004 registry->RegisterStringPref(prefs::kAuthSchemes,
1005 "basic,digest,ntlm,negotiate");
1006 registry->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, false);
1007 registry->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false);
1008 registry->RegisterStringPref(prefs::kAuthServerWhitelist, std::string());
1009 registry->RegisterStringPref(prefs::kAuthNegotiateDelegateWhitelist,
1010 std::string());
1011 registry->RegisterStringPref(prefs::kGSSAPILibraryName, std::string());
1012 registry->RegisterStringPref(prefs::kAuthAndroidNegotiateAccountType,
1013 std::string());
1014 registry->RegisterStringPref(
1015 data_reduction_proxy::prefs::kDataReductionProxy, std::string());
1016 registry->RegisterBooleanPref(prefs::kEnableReferrers, true);
1017 data_reduction_proxy::RegisterPrefs(registry);
1018 registry->RegisterBooleanPref(prefs::kBuiltInDnsClientEnabled, true);
1019 registry->RegisterBooleanPref(prefs::kQuickCheckEnabled, true);
1020 }
1021
1022 net::HttpAuthHandlerFactory* IOThread::CreateDefaultAuthHandlerFactory(
1023 net::HostResolver* resolver) { 567 net::HostResolver* resolver) {
1024 net::HttpAuthFilterWhitelist* auth_filter_default_credentials = NULL; 568 globals_->url_security_manager.reset(net::URLSecurityManager::Create(
1025 if (!auth_server_whitelist_.empty()) { 569 nullptr /* whitelist_default */, nullptr /* whitelist_delegate */));
1026 auth_filter_default_credentials =
1027 new net::HttpAuthFilterWhitelist(auth_server_whitelist_);
1028 }
1029 net::HttpAuthFilterWhitelist* auth_filter_delegate = NULL;
1030 if (!auth_delegate_whitelist_.empty()) {
1031 auth_filter_delegate =
1032 new net::HttpAuthFilterWhitelist(auth_delegate_whitelist_);
1033 }
1034 globals_->url_security_manager.reset(
1035 net::URLSecurityManager::Create(auth_filter_default_credentials,
1036 auth_filter_delegate));
1037 std::vector<std::string> supported_schemes = base::SplitString( 570 std::vector<std::string> supported_schemes = base::SplitString(
1038 auth_schemes_, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 571 kSupportedAuthSchemes, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
1039 572
1040 scoped_ptr<net::HttpAuthHandlerRegistryFactory> registry_factory( 573 scoped_ptr<net::HttpAuthHandlerRegistryFactory> registry_factory(
1041 net::HttpAuthHandlerRegistryFactory::Create( 574 net::HttpAuthHandlerRegistryFactory::Create(
1042 supported_schemes, globals_->url_security_manager.get(), resolver, 575 supported_schemes, globals_->url_security_manager.get(), resolver,
1043 gssapi_library_name_, auth_android_negotiate_account_type_, 576 std::string() /* gssapi_library_name */,
1044 negotiate_disable_cname_lookup_, negotiate_enable_port_)); 577 std::string() /* auth_android_negotiate_account_type */,
578 false /* negotiate_disable_cname_lookup */,
579 false /* negotiate_enable_port */));
1045 return registry_factory.release(); 580 return registry_factory.release();
1046 } 581 }
1047 582
1048 void IOThread::ClearHostCache() { 583 void IOSChromeIOThread::ClearHostCache() {
1049 DCHECK_CURRENTLY_ON(BrowserThread::IO); 584 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO);
1050 585
1051 net::HostCache* host_cache = globals_->host_resolver->GetHostCache(); 586 net::HostCache* host_cache = globals_->host_resolver->GetHostCache();
1052 if (host_cache) 587 if (host_cache)
1053 host_cache->clear(); 588 host_cache->clear();
1054 } 589 }
1055 590
1056 void IOThread::InitializeNetworkSessionParams( 591 void IOSChromeIOThread::InitializeNetworkSessionParams(
1057 net::HttpNetworkSession::Params* params) { 592 net::HttpNetworkSession::Params* params) {
1058 InitializeNetworkSessionParamsFromGlobals(*globals_, params); 593 InitializeNetworkSessionParamsFromGlobals(*globals_, params);
1059 } 594 }
1060 595
1061 void IOThread::InitializeNetworkSessionParamsFromGlobals( 596 void IOSChromeIOThread::InitializeNetworkSessionParamsFromGlobals(
1062 const IOThread::Globals& globals, 597 const IOSChromeIOThread::Globals& globals,
1063 net::HttpNetworkSession::Params* params) { 598 net::HttpNetworkSession::Params* params) {
1064 // The next two properties of the params don't seem to be 599 // The next two properties of the params don't seem to be
1065 // elements of URLRequestContext, so they must be set here. 600 // elements of URLRequestContext, so they must be set here.
1066 params->cert_policy_enforcer = globals.cert_policy_enforcer.get(); 601 params->cert_policy_enforcer = globals.cert_policy_enforcer.get();
1067 params->host_mapping_rules = globals.host_mapping_rules.get();
1068 602
1069 params->ignore_certificate_errors = globals.ignore_certificate_errors; 603 params->ignore_certificate_errors = false;
1070 params->testing_fixed_http_port = globals.testing_fixed_http_port; 604 params->testing_fixed_http_port = globals.testing_fixed_http_port;
1071 params->testing_fixed_https_port = globals.testing_fixed_https_port; 605 params->testing_fixed_https_port = globals.testing_fixed_https_port;
1072 globals.enable_tcp_fast_open_for_ssl.CopyToIfSet( 606 globals.enable_tcp_fast_open_for_ssl.CopyToIfSet(
1073 &params->enable_tcp_fast_open_for_ssl); 607 &params->enable_tcp_fast_open_for_ssl);
1074 608
1075 globals.initial_max_spdy_concurrent_streams.CopyToIfSet( 609 globals.initial_max_spdy_concurrent_streams.CopyToIfSet(
1076 &params->spdy_initial_max_concurrent_streams); 610 &params->spdy_initial_max_concurrent_streams);
1077 globals.enable_spdy_compression.CopyToIfSet( 611 globals.enable_spdy_compression.CopyToIfSet(&params->enable_spdy_compression);
1078 &params->enable_spdy_compression);
1079 globals.enable_spdy_ping_based_connection_checking.CopyToIfSet( 612 globals.enable_spdy_ping_based_connection_checking.CopyToIfSet(
1080 &params->enable_spdy_ping_based_connection_checking); 613 &params->enable_spdy_ping_based_connection_checking);
1081 globals.spdy_default_protocol.CopyToIfSet(
1082 &params->spdy_default_protocol);
1083 params->next_protos = globals.next_protos; 614 params->next_protos = globals.next_protos;
1084 globals.trusted_spdy_proxy.CopyToIfSet(&params->trusted_spdy_proxy);
1085 params->forced_spdy_exclusions = globals.forced_spdy_exclusions; 615 params->forced_spdy_exclusions = globals.forced_spdy_exclusions;
1086 globals.use_alternative_services.CopyToIfSet( 616 globals.use_alternative_services.CopyToIfSet(
1087 &params->use_alternative_services); 617 &params->use_alternative_services);
1088 globals.alternative_service_probability_threshold.CopyToIfSet( 618 globals.alternative_service_probability_threshold.CopyToIfSet(
1089 &params->alternative_service_probability_threshold); 619 &params->alternative_service_probability_threshold);
1090 620
1091 globals.enable_npn.CopyToIfSet(&params->enable_npn); 621 globals.enable_npn.CopyToIfSet(&params->enable_npn);
1092 622
1093 globals.enable_quic.CopyToIfSet(&params->enable_quic); 623 globals.enable_quic.CopyToIfSet(&params->enable_quic);
1094 globals.enable_quic_for_proxies.CopyToIfSet(&params->enable_quic_for_proxies); 624 globals.enable_quic_for_proxies.CopyToIfSet(&params->enable_quic_for_proxies);
1095 globals.quic_always_require_handshake_confirmation.CopyToIfSet( 625 globals.quic_always_require_handshake_confirmation.CopyToIfSet(
1096 &params->quic_always_require_handshake_confirmation); 626 &params->quic_always_require_handshake_confirmation);
1097 globals.quic_disable_connection_pooling.CopyToIfSet( 627 globals.quic_disable_connection_pooling.CopyToIfSet(
1098 &params->quic_disable_connection_pooling); 628 &params->quic_disable_connection_pooling);
1099 globals.quic_load_server_info_timeout_srtt_multiplier.CopyToIfSet( 629 globals.quic_load_server_info_timeout_srtt_multiplier.CopyToIfSet(
1100 &params->quic_load_server_info_timeout_srtt_multiplier); 630 &params->quic_load_server_info_timeout_srtt_multiplier);
1101 globals.quic_enable_connection_racing.CopyToIfSet( 631 globals.quic_enable_connection_racing.CopyToIfSet(
1102 &params->quic_enable_connection_racing); 632 &params->quic_enable_connection_racing);
1103 globals.quic_enable_non_blocking_io.CopyToIfSet( 633 globals.quic_enable_non_blocking_io.CopyToIfSet(
1104 &params->quic_enable_non_blocking_io); 634 &params->quic_enable_non_blocking_io);
1105 globals.quic_prefer_aes.CopyToIfSet(&params->quic_prefer_aes); 635 globals.quic_prefer_aes.CopyToIfSet(&params->quic_prefer_aes);
1106 globals.quic_disable_disk_cache.CopyToIfSet( 636 globals.quic_disable_disk_cache.CopyToIfSet(&params->quic_disable_disk_cache);
1107 &params->quic_disable_disk_cache);
1108 globals.quic_max_number_of_lossy_connections.CopyToIfSet( 637 globals.quic_max_number_of_lossy_connections.CopyToIfSet(
1109 &params->quic_max_number_of_lossy_connections); 638 &params->quic_max_number_of_lossy_connections);
1110 globals.quic_packet_loss_threshold.CopyToIfSet( 639 globals.quic_packet_loss_threshold.CopyToIfSet(
1111 &params->quic_packet_loss_threshold); 640 &params->quic_packet_loss_threshold);
1112 globals.quic_socket_receive_buffer_size.CopyToIfSet( 641 globals.quic_socket_receive_buffer_size.CopyToIfSet(
1113 &params->quic_socket_receive_buffer_size); 642 &params->quic_socket_receive_buffer_size);
1114 globals.quic_delay_tcp_race.CopyToIfSet(&params->quic_delay_tcp_race); 643 globals.quic_delay_tcp_race.CopyToIfSet(&params->quic_delay_tcp_race);
1115 globals.enable_quic_port_selection.CopyToIfSet( 644 params->enable_quic_port_selection = false;
1116 &params->enable_quic_port_selection);
1117 globals.quic_max_packet_length.CopyToIfSet(&params->quic_max_packet_length); 645 globals.quic_max_packet_length.CopyToIfSet(&params->quic_max_packet_length);
1118 globals.quic_user_agent_id.CopyToIfSet(&params->quic_user_agent_id); 646 globals.quic_user_agent_id.CopyToIfSet(&params->quic_user_agent_id);
1119 globals.quic_supported_versions.CopyToIfSet( 647 globals.quic_supported_versions.CopyToIfSet(&params->quic_supported_versions);
1120 &params->quic_supported_versions);
1121 params->quic_connection_options = globals.quic_connection_options; 648 params->quic_connection_options = globals.quic_connection_options;
1122 globals.quic_close_sessions_on_ip_change.CopyToIfSet( 649 globals.quic_close_sessions_on_ip_change.CopyToIfSet(
1123 &params->quic_close_sessions_on_ip_change); 650 &params->quic_close_sessions_on_ip_change);
1124 651
1125 globals.origin_to_force_quic_on.CopyToIfSet( 652 params->enable_user_alternate_protocol_ports = false;
1126 &params->origin_to_force_quic_on);
1127 params->enable_user_alternate_protocol_ports =
1128 globals.enable_user_alternate_protocol_ports;
1129 } 653 }
1130 654
1131 base::TimeTicks IOThread::creation_time() const { 655 base::TimeTicks IOSChromeIOThread::creation_time() const {
1132 return creation_time_; 656 return creation_time_;
1133 } 657 }
1134 658
1135 net::SSLConfigService* IOThread::GetSSLConfigService() { 659 net::SSLConfigService* IOSChromeIOThread::GetSSLConfigService() {
1136 return ssl_config_service_manager_->Get(); 660 return ssl_config_service_manager_->Get();
1137 } 661 }
1138 662
1139 void IOThread::ChangedToOnTheRecordOnIOThread() { 663 void IOSChromeIOThread::ChangedToOnTheRecordOnIOThread() {
1140 DCHECK_CURRENTLY_ON(BrowserThread::IO); 664 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO);
1141 665
1142 // Clear the host cache to avoid showing entries from the OTR session 666 // Clear the host cache to avoid showing entries from the OTR session
1143 // in about:net-internals. 667 // in about:net-internals.
1144 ClearHostCache(); 668 ClearHostCache();
1145 } 669 }
1146 670
1147 void IOThread::InitSystemRequestContext() { 671 void IOSChromeIOThread::InitSystemRequestContext() {
1148 if (system_url_request_context_getter_.get()) 672 if (system_url_request_context_getter_.get())
1149 return; 673 return;
1150 // If we're in unit_tests, IOThread may not be run. 674 // If we're in unit_tests, IOSChromeIOThread may not be run.
1151 if (!BrowserThread::IsMessageLoopValid(BrowserThread::IO)) 675 if (!web::WebThread::IsMessageLoopValid(web::WebThread::IO))
1152 return; 676 return;
1153 system_proxy_config_service_ = ProxyServiceFactory::CreateProxyConfigService( 677 system_proxy_config_service_ =
1154 pref_proxy_config_tracker_.get()); 678 ios::ProxyServiceFactory::CreateProxyConfigService(
1155 system_url_request_context_getter_ = 679 pref_proxy_config_tracker_.get());
1156 new SystemURLRequestContextGetter(this); 680
1157 // Safe to post an unretained this pointer, since IOThread is 681 system_url_request_context_getter_ = new SystemURLRequestContextGetter(this);
1158 // guaranteed to outlive the IO BrowserThread. 682 // Safe to post an unretained this pointer, since IOSChromeIOThread is
1159 BrowserThread::PostTask( 683 // guaranteed to outlive the IO WebThread.
1160 BrowserThread::IO, 684 web::WebThread::PostTask(
1161 FROM_HERE, 685 web::WebThread::IO, FROM_HERE,
1162 base::Bind(&IOThread::InitSystemRequestContextOnIOThread, 686 base::Bind(&IOSChromeIOThread::InitSystemRequestContextOnIOThread,
1163 base::Unretained(this))); 687 base::Unretained(this)));
1164 } 688 }
1165 689
1166 void IOThread::InitSystemRequestContextOnIOThread() { 690 void IOSChromeIOThread::InitSystemRequestContextOnIOThread() {
1167 DCHECK_CURRENTLY_ON(BrowserThread::IO); 691 DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::IO);
1168 DCHECK(!globals_->system_proxy_service.get()); 692 DCHECK(!globals_->system_proxy_service.get());
1169 DCHECK(system_proxy_config_service_.get()); 693 DCHECK(system_proxy_config_service_.get());
1170 694
1171 const base::CommandLine& command_line = 695 globals_->system_proxy_service = ios::ProxyServiceFactory::CreateProxyService(
1172 *base::CommandLine::ForCurrentProcess(); 696 net_log_, nullptr, globals_->system_network_delegate.get(),
1173 globals_->system_proxy_service = ProxyServiceFactory::CreateProxyService( 697 system_proxy_config_service_.Pass(), true /* quick_check_enabled */);
1174 net_log_, globals_->proxy_script_fetcher_context.get(),
1175 globals_->system_network_delegate.get(),
1176 system_proxy_config_service_.Pass(), command_line,
1177 quick_check_enabled_.GetValue());
1178 698
1179 globals_->system_request_context.reset( 699 globals_->system_request_context.reset(
1180 ConstructSystemRequestContext(globals_, net_log_)); 700 ConstructSystemRequestContext(globals_, net_log_));
1181 } 701 }
1182 702
1183 void IOThread::UpdateDnsClientEnabled() { 703 void IOSChromeIOThread::ConfigureQuic() {
1184 globals()->host_resolver->SetDnsClientEnabled(*dns_client_enabled_);
1185 }
1186
1187 void IOThread::ConfigureQuic(const base::CommandLine& command_line) {
1188 // Always fetch the field trial group to ensure it is reported correctly. 704 // Always fetch the field trial group to ensure it is reported correctly.
1189 // The command line flags will be associated with a group that is reported 705 // The command line flags will be associated with a group that is reported
1190 // so long as trial is actually queried. 706 // so long as trial is actually queried.
1191 std::string group = 707 std::string group = base::FieldTrialList::FindFullName(kQuicFieldTrialName);
1192 base::FieldTrialList::FindFullName(kQuicFieldTrialName);
1193 VariationParameters params; 708 VariationParameters params;
1194 if (!variations::GetVariationParams(kQuicFieldTrialName, &params)) { 709 if (!variations::GetVariationParams(kQuicFieldTrialName, &params)) {
1195 params.clear(); 710 params.clear();
1196 } 711 }
1197 712
1198 ConfigureQuicGlobals(command_line, group, params, is_quic_allowed_by_policy_, 713 ConfigureQuicGlobals(group, params, globals_);
1199 globals_);
1200 } 714 }
1201 715
1202 void IOThread::ConfigureQuicGlobals( 716 void IOSChromeIOThread::ConfigureQuicGlobals(
1203 const base::CommandLine& command_line,
1204 base::StringPiece quic_trial_group, 717 base::StringPiece quic_trial_group,
1205 const VariationParameters& quic_trial_params, 718 const VariationParameters& quic_trial_params,
1206 bool quic_allowed_by_policy, 719 IOSChromeIOThread::Globals* globals) {
1207 IOThread::Globals* globals) { 720 bool enable_quic = ShouldEnableQuic(quic_trial_group);
1208 bool enable_quic = ShouldEnableQuic(command_line, quic_trial_group,
1209 quic_allowed_by_policy);
1210 globals->enable_quic.set(enable_quic); 721 globals->enable_quic.set(enable_quic);
1211 bool enable_quic_for_proxies = ShouldEnableQuicForProxies( 722 bool enable_quic_for_proxies = ShouldEnableQuicForProxies(quic_trial_group);
1212 command_line, quic_trial_group, quic_allowed_by_policy);
1213 globals->enable_quic_for_proxies.set(enable_quic_for_proxies); 723 globals->enable_quic_for_proxies.set(enable_quic_for_proxies);
1214 globals->use_alternative_services.set( 724 globals->use_alternative_services.set(
1215 ShouldQuicEnableAlternativeServices(command_line, quic_trial_params)); 725 ShouldQuicEnableAlternativeServices(quic_trial_params));
1216 if (enable_quic) { 726 if (enable_quic) {
1217 globals->quic_always_require_handshake_confirmation.set( 727 globals->quic_always_require_handshake_confirmation.set(
1218 ShouldQuicAlwaysRequireHandshakeConfirmation(quic_trial_params)); 728 ShouldQuicAlwaysRequireHandshakeConfirmation(quic_trial_params));
1219 globals->quic_disable_connection_pooling.set( 729 globals->quic_disable_connection_pooling.set(
1220 ShouldQuicDisableConnectionPooling(quic_trial_params)); 730 ShouldQuicDisableConnectionPooling(quic_trial_params));
1221 int receive_buffer_size = GetQuicSocketReceiveBufferSize(quic_trial_params); 731 int receive_buffer_size = GetQuicSocketReceiveBufferSize(quic_trial_params);
1222 if (receive_buffer_size != 0) { 732 if (receive_buffer_size != 0) {
1223 globals->quic_socket_receive_buffer_size.set(receive_buffer_size); 733 globals->quic_socket_receive_buffer_size.set(receive_buffer_size);
1224 } 734 }
1225 globals->quic_delay_tcp_race.set(ShouldQuicDelayTcpRace(quic_trial_params)); 735 globals->quic_delay_tcp_race.set(ShouldQuicDelayTcpRace(quic_trial_params));
1226 float load_server_info_timeout_srtt_multiplier = 736 float load_server_info_timeout_srtt_multiplier =
1227 GetQuicLoadServerInfoTimeoutSrttMultiplier(quic_trial_params); 737 GetQuicLoadServerInfoTimeoutSrttMultiplier(quic_trial_params);
1228 if (load_server_info_timeout_srtt_multiplier != 0) { 738 if (load_server_info_timeout_srtt_multiplier != 0) {
1229 globals->quic_load_server_info_timeout_srtt_multiplier.set( 739 globals->quic_load_server_info_timeout_srtt_multiplier.set(
1230 load_server_info_timeout_srtt_multiplier); 740 load_server_info_timeout_srtt_multiplier);
1231 } 741 }
1232 globals->quic_enable_connection_racing.set( 742 globals->quic_enable_connection_racing.set(
1233 ShouldQuicEnableConnectionRacing(quic_trial_params)); 743 ShouldQuicEnableConnectionRacing(quic_trial_params));
1234 globals->quic_enable_non_blocking_io.set( 744 globals->quic_enable_non_blocking_io.set(
1235 ShouldQuicEnableNonBlockingIO(quic_trial_params)); 745 ShouldQuicEnableNonBlockingIO(quic_trial_params));
1236 globals->quic_disable_disk_cache.set( 746 globals->quic_disable_disk_cache.set(
1237 ShouldQuicDisableDiskCache(quic_trial_params)); 747 ShouldQuicDisableDiskCache(quic_trial_params));
1238 globals->quic_prefer_aes.set( 748 globals->quic_prefer_aes.set(ShouldQuicPreferAes(quic_trial_params));
1239 ShouldQuicPreferAes(quic_trial_params)); 749 int max_number_of_lossy_connections =
1240 int max_number_of_lossy_connections = GetQuicMaxNumberOfLossyConnections( 750 GetQuicMaxNumberOfLossyConnections(quic_trial_params);
1241 quic_trial_params);
1242 if (max_number_of_lossy_connections != 0) { 751 if (max_number_of_lossy_connections != 0) {
1243 globals->quic_max_number_of_lossy_connections.set( 752 globals->quic_max_number_of_lossy_connections.set(
1244 max_number_of_lossy_connections); 753 max_number_of_lossy_connections);
1245 } 754 }
1246 float packet_loss_threshold = GetQuicPacketLossThreshold(quic_trial_params); 755 float packet_loss_threshold = GetQuicPacketLossThreshold(quic_trial_params);
1247 if (packet_loss_threshold != 0) 756 if (packet_loss_threshold != 0)
1248 globals->quic_packet_loss_threshold.set(packet_loss_threshold); 757 globals->quic_packet_loss_threshold.set(packet_loss_threshold);
1249 globals->enable_quic_port_selection.set(
1250 ShouldEnableQuicPortSelection(command_line));
1251 globals->quic_connection_options = 758 globals->quic_connection_options =
1252 GetQuicConnectionOptions(command_line, quic_trial_params); 759 GetQuicConnectionOptions(quic_trial_params);
1253 globals->quic_close_sessions_on_ip_change.set( 760 globals->quic_close_sessions_on_ip_change.set(
1254 ShouldQuicCloseSessionsOnIpChange(quic_trial_params)); 761 ShouldQuicCloseSessionsOnIpChange(quic_trial_params));
1255 } 762 }
1256 763
1257 size_t max_packet_length = GetQuicMaxPacketLength(command_line, 764 size_t max_packet_length = GetQuicMaxPacketLength(quic_trial_params);
1258 quic_trial_params);
1259 if (max_packet_length != 0) { 765 if (max_packet_length != 0) {
1260 globals->quic_max_packet_length.set(max_packet_length); 766 globals->quic_max_packet_length.set(max_packet_length);
1261 } 767 }
1262 768
1263 std::string quic_user_agent_id = chrome::GetChannelString(); 769 std::string quic_user_agent_id = ::GetChannelString();
1264 if (!quic_user_agent_id.empty()) 770 if (!quic_user_agent_id.empty())
1265 quic_user_agent_id.push_back(' '); 771 quic_user_agent_id.push_back(' ');
1266 quic_user_agent_id.append( 772 quic_user_agent_id.append(
1267 version_info::GetProductNameAndVersionForUserAgent()); 773 version_info::GetProductNameAndVersionForUserAgent());
1268 quic_user_agent_id.push_back(' '); 774 quic_user_agent_id.push_back(' ');
1269 quic_user_agent_id.append(content::BuildOSCpuInfo()); 775 quic_user_agent_id.append(web::BuildOSCpuInfo());
1270 globals->quic_user_agent_id.set(quic_user_agent_id); 776 globals->quic_user_agent_id.set(quic_user_agent_id);
1271 777
1272 net::QuicVersion version = GetQuicVersion(command_line, quic_trial_params); 778 net::QuicVersion version = GetQuicVersion(quic_trial_params);
1273 if (version != net::QUIC_VERSION_UNSUPPORTED) { 779 if (version != net::QUIC_VERSION_UNSUPPORTED) {
1274 net::QuicVersionVector supported_versions; 780 net::QuicVersionVector supported_versions;
1275 supported_versions.push_back(version); 781 supported_versions.push_back(version);
1276 globals->quic_supported_versions.set(supported_versions); 782 globals->quic_supported_versions.set(supported_versions);
1277 } 783 }
1278 784
1279 double threshold = GetAlternativeProtocolProbabilityThreshold( 785 double threshold =
1280 command_line, quic_trial_params); 786 GetAlternativeProtocolProbabilityThreshold(quic_trial_params);
1281 if (threshold >=0 && threshold <= 1) { 787 if (threshold >= 0 && threshold <= 1) {
1282 globals->alternative_service_probability_threshold.set(threshold); 788 globals->alternative_service_probability_threshold.set(threshold);
1283 globals->http_server_properties->SetAlternativeServiceProbabilityThreshold( 789 globals->http_server_properties->SetAlternativeServiceProbabilityThreshold(
1284 threshold); 790 threshold);
1285 } 791 }
1286
1287 if (command_line.HasSwitch(switches::kOriginToForceQuicOn)) {
1288 net::HostPortPair quic_origin =
1289 net::HostPortPair::FromString(
1290 command_line.GetSwitchValueASCII(switches::kOriginToForceQuicOn));
1291 if (!quic_origin.IsEmpty()) {
1292 globals->origin_to_force_quic_on.set(quic_origin);
1293 }
1294 }
1295 } 792 }
1296 793
1297 bool IOThread::ShouldEnableQuic(const base::CommandLine& command_line, 794 bool IOSChromeIOThread::ShouldEnableQuic(base::StringPiece quic_trial_group) {
1298 base::StringPiece quic_trial_group,
1299 bool quic_allowed_by_policy) {
1300 if (command_line.HasSwitch(switches::kDisableQuic) || !quic_allowed_by_policy)
1301 return false;
1302
1303 if (command_line.HasSwitch(switches::kEnableQuic))
1304 return true;
1305
1306 return quic_trial_group.starts_with(kQuicFieldTrialEnabledGroupName) || 795 return quic_trial_group.starts_with(kQuicFieldTrialEnabledGroupName) ||
1307 quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName); 796 quic_trial_group.starts_with(kQuicFieldTrialHttpsEnabledGroupName);
1308 } 797 }
1309 798
1310 bool IOThread::ShouldEnableQuicForProxies(const base::CommandLine& command_line, 799 bool IOSChromeIOThread::ShouldEnableQuicForProxies(
1311 base::StringPiece quic_trial_group, 800 base::StringPiece quic_trial_group) {
1312 bool quic_allowed_by_policy) { 801 return ShouldEnableQuic(quic_trial_group) ||
1313 return ShouldEnableQuic( 802 ShouldEnableQuicForDataReductionProxy();
1314 command_line, quic_trial_group, quic_allowed_by_policy) ||
1315 ShouldEnableQuicForDataReductionProxy();
1316 } 803 }
1317 804
1318 bool IOThread::ShouldEnableQuicForDataReductionProxy() { 805 bool IOSChromeIOThread::ShouldEnableQuicForDataReductionProxy() {
1319 const base::CommandLine& command_line =
1320 *base::CommandLine::ForCurrentProcess();
1321
1322 if (command_line.HasSwitch(switches::kDisableQuic))
1323 return false;
1324
1325 return data_reduction_proxy::params::IsIncludedInQuicFieldTrial(); 806 return data_reduction_proxy::params::IsIncludedInQuicFieldTrial();
1326 } 807 }
1327 808
1328 bool IOThread::ShouldEnableQuicPortSelection( 809 net::QuicTagVector IOSChromeIOThread::GetQuicConnectionOptions(
1329 const base::CommandLine& command_line) {
1330 if (command_line.HasSwitch(switches::kDisableQuicPortSelection))
1331 return false;
1332
1333 if (command_line.HasSwitch(switches::kEnableQuicPortSelection))
1334 return true;
1335
1336 return false; // Default to disabling port selection on all channels.
1337 }
1338
1339 net::QuicTagVector IOThread::GetQuicConnectionOptions(
1340 const base::CommandLine& command_line,
1341 const VariationParameters& quic_trial_params) { 810 const VariationParameters& quic_trial_params) {
1342 if (command_line.HasSwitch(switches::kQuicConnectionOptions)) {
1343 return net::QuicUtils::ParseQuicConnectionOptions(
1344 command_line.GetSwitchValueASCII(switches::kQuicConnectionOptions));
1345 }
1346
1347 VariationParameters::const_iterator it = 811 VariationParameters::const_iterator it =
1348 quic_trial_params.find("connection_options"); 812 quic_trial_params.find("connection_options");
1349 if (it == quic_trial_params.end()) { 813 if (it == quic_trial_params.end()) {
1350 return net::QuicTagVector(); 814 return net::QuicTagVector();
1351 } 815 }
1352 816
1353 return net::QuicUtils::ParseQuicConnectionOptions(it->second); 817 return net::QuicUtils::ParseQuicConnectionOptions(it->second);
1354 } 818 }
1355 819
1356 double IOThread::GetAlternativeProtocolProbabilityThreshold( 820 double IOSChromeIOThread::GetAlternativeProtocolProbabilityThreshold(
1357 const base::CommandLine& command_line,
1358 const VariationParameters& quic_trial_params) { 821 const VariationParameters& quic_trial_params) {
1359 double value; 822 double value;
1360 if (command_line.HasSwitch(
1361 switches::kAlternativeServiceProbabilityThreshold)) {
1362 if (base::StringToDouble(
1363 command_line.GetSwitchValueASCII(
1364 switches::kAlternativeServiceProbabilityThreshold),
1365 &value)) {
1366 return value;
1367 }
1368 }
1369 if (command_line.HasSwitch(switches::kEnableQuic)) {
1370 return 0;
1371 }
1372 // TODO(bnc): Remove when new parameter name rolls out and server 823 // TODO(bnc): Remove when new parameter name rolls out and server
1373 // configuration is changed. 824 // configuration is changed.
1374 if (base::StringToDouble( 825 if (base::StringToDouble(
1375 GetVariationParam(quic_trial_params, 826 GetVariationParam(quic_trial_params,
1376 "alternate_protocol_probability_threshold"), 827 "alternate_protocol_probability_threshold"),
1377 &value)) { 828 &value)) {
1378 return value; 829 return value;
1379 } 830 }
1380 if (base::StringToDouble( 831 if (base::StringToDouble(
1381 GetVariationParam(quic_trial_params, 832 GetVariationParam(quic_trial_params,
1382 "alternative_service_probability_threshold"), 833 "alternative_service_probability_threshold"),
1383 &value)) { 834 &value)) {
1384 return value; 835 return value;
1385 } 836 }
1386 return -1; 837 return -1;
1387 } 838 }
1388 839
1389 bool IOThread::ShouldQuicAlwaysRequireHandshakeConfirmation( 840 bool IOSChromeIOThread::ShouldQuicAlwaysRequireHandshakeConfirmation(
1390 const VariationParameters& quic_trial_params) { 841 const VariationParameters& quic_trial_params) {
1391 return base::LowerCaseEqualsASCII( 842 return base::LowerCaseEqualsASCII(
1392 GetVariationParam(quic_trial_params, 843 GetVariationParam(quic_trial_params,
1393 "always_require_handshake_confirmation"), 844 "always_require_handshake_confirmation"),
1394 "true"); 845 "true");
1395 } 846 }
1396 847
1397 bool IOThread::ShouldQuicDisableConnectionPooling( 848 bool IOSChromeIOThread::ShouldQuicDisableConnectionPooling(
1398 const VariationParameters& quic_trial_params) { 849 const VariationParameters& quic_trial_params) {
1399 return base::LowerCaseEqualsASCII( 850 return base::LowerCaseEqualsASCII(
1400 GetVariationParam(quic_trial_params, "disable_connection_pooling"), 851 GetVariationParam(quic_trial_params, "disable_connection_pooling"),
1401 "true"); 852 "true");
1402 } 853 }
1403 854
1404 float IOThread::GetQuicLoadServerInfoTimeoutSrttMultiplier( 855 float IOSChromeIOThread::GetQuicLoadServerInfoTimeoutSrttMultiplier(
1405 const VariationParameters& quic_trial_params) { 856 const VariationParameters& quic_trial_params) {
1406 double value; 857 double value;
1407 if (base::StringToDouble(GetVariationParam(quic_trial_params, 858 if (base::StringToDouble(
1408 "load_server_info_time_to_srtt"), 859 GetVariationParam(quic_trial_params, "load_server_info_time_to_srtt"),
1409 &value)) { 860 &value)) {
1410 return static_cast<float>(value); 861 return static_cast<float>(value);
1411 } 862 }
1412 return 0.0f; 863 return 0.0f;
1413 } 864 }
1414 865
1415 bool IOThread::ShouldQuicEnableConnectionRacing( 866 bool IOSChromeIOThread::ShouldQuicEnableConnectionRacing(
1416 const VariationParameters& quic_trial_params) { 867 const VariationParameters& quic_trial_params) {
1417 return base::LowerCaseEqualsASCII( 868 return base::LowerCaseEqualsASCII(
1418 GetVariationParam(quic_trial_params, "enable_connection_racing"), 869 GetVariationParam(quic_trial_params, "enable_connection_racing"), "true");
1419 "true");
1420 } 870 }
1421 871
1422 bool IOThread::ShouldQuicEnableNonBlockingIO( 872 bool IOSChromeIOThread::ShouldQuicEnableNonBlockingIO(
1423 const VariationParameters& quic_trial_params) { 873 const VariationParameters& quic_trial_params) {
1424 return base::LowerCaseEqualsASCII( 874 return base::LowerCaseEqualsASCII(
1425 GetVariationParam(quic_trial_params, "enable_non_blocking_io"), 875 GetVariationParam(quic_trial_params, "enable_non_blocking_io"), "true");
1426 "true");
1427 } 876 }
1428 877
1429 bool IOThread::ShouldQuicDisableDiskCache( 878 bool IOSChromeIOThread::ShouldQuicDisableDiskCache(
1430 const VariationParameters& quic_trial_params) { 879 const VariationParameters& quic_trial_params) {
1431 return base::LowerCaseEqualsASCII( 880 return base::LowerCaseEqualsASCII(
1432 GetVariationParam(quic_trial_params, "disable_disk_cache"), "true"); 881 GetVariationParam(quic_trial_params, "disable_disk_cache"), "true");
1433 } 882 }
1434 883
1435 bool IOThread::ShouldQuicPreferAes( 884 bool IOSChromeIOThread::ShouldQuicPreferAes(
1436 const VariationParameters& quic_trial_params) { 885 const VariationParameters& quic_trial_params) {
1437 return base::LowerCaseEqualsASCII( 886 return base::LowerCaseEqualsASCII(
1438 GetVariationParam(quic_trial_params, "prefer_aes"), "true"); 887 GetVariationParam(quic_trial_params, "prefer_aes"), "true");
1439 } 888 }
1440 889
1441 bool IOThread::ShouldQuicEnableAlternativeServices( 890 bool IOSChromeIOThread::ShouldQuicEnableAlternativeServices(
1442 const base::CommandLine& command_line,
1443 const VariationParameters& quic_trial_params) { 891 const VariationParameters& quic_trial_params) {
1444 return command_line.HasSwitch(switches::kEnableAlternativeServices) || 892 return base::LowerCaseEqualsASCII(
1445 base::LowerCaseEqualsASCII( 893 GetVariationParam(quic_trial_params, "use_alternative_services"), "true");
1446 GetVariationParam(quic_trial_params, "use_alternative_services"),
1447 "true");
1448 } 894 }
1449 895
1450 int IOThread::GetQuicMaxNumberOfLossyConnections( 896 int IOSChromeIOThread::GetQuicMaxNumberOfLossyConnections(
1451 const VariationParameters& quic_trial_params) { 897 const VariationParameters& quic_trial_params) {
1452 int value; 898 int value;
1453 if (base::StringToInt(GetVariationParam(quic_trial_params, 899 if (base::StringToInt(GetVariationParam(quic_trial_params,
1454 "max_number_of_lossy_connections"), 900 "max_number_of_lossy_connections"),
1455 &value)) { 901 &value)) {
1456 return value; 902 return value;
1457 } 903 }
1458 return 0; 904 return 0;
1459 } 905 }
1460 906
1461 float IOThread::GetQuicPacketLossThreshold( 907 float IOSChromeIOThread::GetQuicPacketLossThreshold(
1462 const VariationParameters& quic_trial_params) { 908 const VariationParameters& quic_trial_params) {
1463 double value; 909 double value;
1464 if (base::StringToDouble(GetVariationParam(quic_trial_params, 910 if (base::StringToDouble(
1465 "packet_loss_threshold"), 911 GetVariationParam(quic_trial_params, "packet_loss_threshold"),
1466 &value)) { 912 &value)) {
1467 return static_cast<float>(value); 913 return static_cast<float>(value);
1468 } 914 }
1469 return 0.0f; 915 return 0.0f;
1470 } 916 }
1471 917
1472 int IOThread::GetQuicSocketReceiveBufferSize( 918 int IOSChromeIOThread::GetQuicSocketReceiveBufferSize(
1473 const VariationParameters& quic_trial_params) { 919 const VariationParameters& quic_trial_params) {
1474 int value; 920 int value;
1475 if (base::StringToInt(GetVariationParam(quic_trial_params, 921 if (base::StringToInt(
1476 "receive_buffer_size"), 922 GetVariationParam(quic_trial_params, "receive_buffer_size"),
1477 &value)) { 923 &value)) {
1478 return value; 924 return value;
1479 } 925 }
1480 return 0; 926 return 0;
1481 } 927 }
1482 928
1483 bool IOThread::ShouldQuicDelayTcpRace( 929 bool IOSChromeIOThread::ShouldQuicDelayTcpRace(
1484 const VariationParameters& quic_trial_params) { 930 const VariationParameters& quic_trial_params) {
1485 return base::LowerCaseEqualsASCII( 931 return base::LowerCaseEqualsASCII(
1486 GetVariationParam(quic_trial_params, "delay_tcp_race"), "true"); 932 GetVariationParam(quic_trial_params, "delay_tcp_race"), "true");
1487 } 933 }
1488 934
1489 bool IOThread::ShouldQuicCloseSessionsOnIpChange( 935 bool IOSChromeIOThread::ShouldQuicCloseSessionsOnIpChange(
1490 const VariationParameters& quic_trial_params) { 936 const VariationParameters& quic_trial_params) {
1491 return base::LowerCaseEqualsASCII( 937 return base::LowerCaseEqualsASCII(
1492 GetVariationParam(quic_trial_params, "close_sessions_on_ip_change"), 938 GetVariationParam(quic_trial_params, "close_sessions_on_ip_change"),
1493 "true"); 939 "true");
1494 } 940 }
1495 941
1496 size_t IOThread::GetQuicMaxPacketLength( 942 size_t IOSChromeIOThread::GetQuicMaxPacketLength(
1497 const base::CommandLine& command_line,
1498 const VariationParameters& quic_trial_params) { 943 const VariationParameters& quic_trial_params) {
1499 if (command_line.HasSwitch(switches::kQuicMaxPacketLength)) {
1500 unsigned value;
1501 if (!base::StringToUint(
1502 command_line.GetSwitchValueASCII(switches::kQuicMaxPacketLength),
1503 &value)) {
1504 return 0;
1505 }
1506 return value;
1507 }
1508
1509 unsigned value; 944 unsigned value;
1510 if (base::StringToUint(GetVariationParam(quic_trial_params, 945 if (base::StringToUint(
1511 "max_packet_length"), 946 GetVariationParam(quic_trial_params, "max_packet_length"), &value)) {
1512 &value)) {
1513 return value; 947 return value;
1514 } 948 }
1515 return 0; 949 return 0;
1516 } 950 }
1517 951
1518 net::QuicVersion IOThread::GetQuicVersion( 952 net::QuicVersion IOSChromeIOThread::GetQuicVersion(
1519 const base::CommandLine& command_line,
1520 const VariationParameters& quic_trial_params) { 953 const VariationParameters& quic_trial_params) {
1521 if (command_line.HasSwitch(switches::kQuicVersion)) {
1522 return ParseQuicVersion(
1523 command_line.GetSwitchValueASCII(switches::kQuicVersion));
1524 }
1525
1526 return ParseQuicVersion(GetVariationParam(quic_trial_params, "quic_version")); 954 return ParseQuicVersion(GetVariationParam(quic_trial_params, "quic_version"));
1527 } 955 }
1528 956
1529 net::QuicVersion IOThread::ParseQuicVersion(const std::string& quic_version) { 957 net::QuicVersion IOSChromeIOThread::ParseQuicVersion(
958 const std::string& quic_version) {
1530 net::QuicVersionVector supported_versions = net::QuicSupportedVersions(); 959 net::QuicVersionVector supported_versions = net::QuicSupportedVersions();
1531 for (size_t i = 0; i < supported_versions.size(); ++i) { 960 for (size_t i = 0; i < supported_versions.size(); ++i) {
1532 net::QuicVersion version = supported_versions[i]; 961 net::QuicVersion version = supported_versions[i];
1533 if (net::QuicVersionToString(version) == quic_version) { 962 if (net::QuicVersionToString(version) == quic_version) {
1534 return version; 963 return version;
1535 } 964 }
1536 } 965 }
1537 966
1538 return net::QUIC_VERSION_UNSUPPORTED; 967 return net::QUIC_VERSION_UNSUPPORTED;
1539 } 968 }
1540 969
1541 net::URLRequestContext* IOThread::ConstructSystemRequestContext( 970 net::URLRequestContext* IOSChromeIOThread::ConstructSystemRequestContext(
1542 IOThread::Globals* globals, 971 IOSChromeIOThread::Globals* globals,
1543 net::NetLog* net_log) { 972 net::NetLog* net_log) {
1544 net::URLRequestContext* context = new SystemURLRequestContext; 973 net::URLRequestContext* context = new SystemURLRequestContext;
1545 context->set_net_log(net_log); 974 context->set_net_log(net_log);
1546 context->set_host_resolver(globals->host_resolver.get()); 975 context->set_host_resolver(globals->host_resolver.get());
1547 context->set_cert_verifier(globals->cert_verifier.get()); 976 context->set_cert_verifier(globals->cert_verifier.get());
1548 context->set_transport_security_state( 977 context->set_transport_security_state(
1549 globals->transport_security_state.get()); 978 globals->transport_security_state.get());
1550 context->set_cert_transparency_verifier( 979 context->set_cert_transparency_verifier(
1551 globals->cert_transparency_verifier.get()); 980 globals->cert_transparency_verifier.get());
1552 context->set_ssl_config_service(globals->ssl_config_service.get()); 981 context->set_ssl_config_service(globals->ssl_config_service.get());
1553 context->set_http_auth_handler_factory( 982 context->set_http_auth_handler_factory(
1554 globals->http_auth_handler_factory.get()); 983 globals->http_auth_handler_factory.get());
1555 context->set_proxy_service(globals->system_proxy_service.get()); 984 context->set_proxy_service(globals->system_proxy_service.get());
1556 985
1557 globals->system_url_request_job_factory.reset( 986 net::URLRequestJobFactoryImpl* system_job_factory =
1558 new net::URLRequestJobFactoryImpl()); 987 new net::URLRequestJobFactoryImpl();
988 // Data URLs are always loaded through the system request context on iOS
989 // (due to UIWebView limitations).
990 bool set_protocol = system_job_factory->SetProtocolHandler(
991 url::kDataScheme, make_scoped_ptr(new net::DataProtocolHandler()));
992 DCHECK(set_protocol);
993 globals->system_url_request_job_factory.reset(system_job_factory);
1559 context->set_job_factory(globals->system_url_request_job_factory.get()); 994 context->set_job_factory(globals->system_url_request_job_factory.get());
1560 995
1561 context->set_cookie_store(globals->system_cookie_store.get()); 996 context->set_cookie_store(globals->system_cookie_store.get());
1562 context->set_channel_id_service( 997 context->set_channel_id_service(globals->system_channel_id_service.get());
1563 globals->system_channel_id_service.get());
1564 context->set_network_delegate(globals->system_network_delegate.get()); 998 context->set_network_delegate(globals->system_network_delegate.get());
1565 context->set_http_user_agent_settings( 999 context->set_http_user_agent_settings(
1566 globals->http_user_agent_settings.get()); 1000 globals->http_user_agent_settings.get());
1567 context->set_network_quality_estimator( 1001 context->set_network_quality_estimator(
1568 globals->network_quality_estimator.get()); 1002 globals->network_quality_estimator.get());
1569 context->set_backoff_manager(globals->url_request_backoff_manager.get()); 1003 context->set_backoff_manager(globals->url_request_backoff_manager.get());
1570 1004
1571 context->set_http_server_properties( 1005 context->set_http_server_properties(
1572 globals->http_server_properties->GetWeakPtr()); 1006 globals->http_server_properties->GetWeakPtr());
1573 1007
1574 net::HttpNetworkSession::Params system_params; 1008 net::HttpNetworkSession::Params system_params;
1575 InitializeNetworkSessionParamsFromGlobals(*globals, &system_params); 1009 InitializeNetworkSessionParamsFromGlobals(*globals, &system_params);
1576 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents( 1010 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(
1577 context, &system_params); 1011 context, &system_params);
1578 1012
1579 globals->system_http_network_session.reset( 1013 globals->system_http_network_session.reset(
1580 new net::HttpNetworkSession(system_params)); 1014 new net::HttpNetworkSession(system_params));
1581 globals->system_http_transaction_factory.reset( 1015 globals->system_http_transaction_factory.reset(
1582 new net::HttpNetworkLayer(globals->system_http_network_session.get())); 1016 new net::HttpNetworkLayer(globals->system_http_network_session.get()));
1583 context->set_http_transaction_factory( 1017 context->set_http_transaction_factory(
1584 globals->system_http_transaction_factory.get()); 1018 globals->system_http_transaction_factory.get());
1585 1019
1586 return context; 1020 return context;
1587 } 1021 }
1588
1589 net::URLRequestContext* IOThread::ConstructProxyScriptFetcherContext(
1590 IOThread::Globals* globals,
1591 net::NetLog* net_log) {
1592 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
1593 // is fixed.
1594 tracked_objects::ScopedTracker tracking_profile1(
1595 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1596 "466432 IOThread::ConstructProxyScriptFetcherContext1"));
1597 net::URLRequestContext* context = new net::URLRequestContext;
1598 context->set_net_log(net_log);
1599 context->set_host_resolver(globals->host_resolver.get());
1600 context->set_cert_verifier(globals->cert_verifier.get());
1601 context->set_transport_security_state(
1602 globals->transport_security_state.get());
1603 context->set_cert_transparency_verifier(
1604 globals->cert_transparency_verifier.get());
1605 context->set_ssl_config_service(globals->ssl_config_service.get());
1606 context->set_http_auth_handler_factory(
1607 globals->http_auth_handler_factory.get());
1608 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get());
1609
1610 context->set_job_factory(
1611 globals->proxy_script_fetcher_url_request_job_factory.get());
1612
1613 context->set_cookie_store(globals->system_cookie_store.get());
1614 context->set_channel_id_service(
1615 globals->system_channel_id_service.get());
1616 context->set_network_delegate(globals->system_network_delegate.get());
1617 context->set_http_user_agent_settings(
1618 globals->http_user_agent_settings.get());
1619 context->set_http_server_properties(
1620 globals->http_server_properties->GetWeakPtr());
1621
1622 net::HttpNetworkSession::Params session_params;
1623 InitializeNetworkSessionParamsFromGlobals(*globals, &session_params);
1624 net::URLRequestContextBuilder::SetHttpNetworkSessionComponents(
1625 context, &session_params);
1626
1627 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
1628 // is fixed.
1629 tracked_objects::ScopedTracker tracking_profile2(
1630 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1631 "466432 IOThread::ConstructProxyScriptFetcherContext2"));
1632 globals->proxy_script_fetcher_http_network_session.reset(
1633 new net::HttpNetworkSession(session_params));
1634 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466432
1635 // is fixed.
1636 tracked_objects::ScopedTracker tracking_profile3(
1637 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1638 "466432 IOThread::ConstructProxyScriptFetcherContext3"));
1639 globals->proxy_script_fetcher_http_transaction_factory.reset(
1640 new net::HttpNetworkLayer(
1641 globals->proxy_script_fetcher_http_network_session.get()));
1642 context->set_http_transaction_factory(
1643 globals->proxy_script_fetcher_http_transaction_factory.get());
1644
1645 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
1646 new net::URLRequestJobFactoryImpl());
1647
1648 job_factory->SetProtocolHandler(
1649 url::kDataScheme, make_scoped_ptr(new net::DataProtocolHandler()));
1650 job_factory->SetProtocolHandler(
1651 url::kFileScheme,
1652 make_scoped_ptr(new net::FileProtocolHandler(
1653 content::BrowserThread::GetBlockingPool()
1654 ->GetTaskRunnerWithShutdownBehavior(
1655 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))));
1656 #if !defined(DISABLE_FTP_SUPPORT)
1657 globals->proxy_script_fetcher_ftp_transaction_factory.reset(
1658 new net::FtpNetworkLayer(globals->host_resolver.get()));
1659 job_factory->SetProtocolHandler(
1660 url::kFtpScheme,
1661 make_scoped_ptr(new net::FtpProtocolHandler(
1662 globals->proxy_script_fetcher_ftp_transaction_factory.get())));
1663 #endif
1664 globals->proxy_script_fetcher_url_request_job_factory = job_factory.Pass();
1665
1666 context->set_job_factory(
1667 globals->proxy_script_fetcher_url_request_job_factory.get());
1668
1669 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
1670 // system URLRequestContext too. There's no reason this should be tied to a
1671 // profile.
1672 return context;
1673 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/ios_chrome_io_thread.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698