OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_IO_THREAD_H_ | 5 #ifndef CHROME_BROWSER_IO_THREAD_H_ |
6 #define CHROME_BROWSER_IO_THREAD_H_ | 6 #define CHROME_BROWSER_IO_THREAD_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
30 #include "content/public/browser/browser_thread_delegate.h" | 30 #include "content/public/browser/browser_thread_delegate.h" |
31 #include "net/base/network_change_notifier.h" | 31 #include "net/base/network_change_notifier.h" |
32 #include "net/http/http_network_session.h" | 32 #include "net/http/http_network_session.h" |
33 | 33 |
34 class PrefProxyConfigTracker; | 34 class PrefProxyConfigTracker; |
35 class PrefService; | 35 class PrefService; |
36 class PrefRegistrySimple; | 36 class PrefRegistrySimple; |
37 class SystemURLRequestContextGetter; | 37 class SystemURLRequestContextGetter; |
38 | 38 |
39 namespace base { | |
40 class CommandLine; | |
41 } | |
42 | |
43 #if BUILDFLAG(ANDROID_JAVA_UI) | 39 #if BUILDFLAG(ANDROID_JAVA_UI) |
44 namespace chrome { | 40 namespace chrome { |
45 namespace android { | 41 namespace android { |
46 class ExternalDataUseObserver; | 42 class ExternalDataUseObserver; |
47 } | 43 } |
48 } | 44 } |
49 #endif // BUILDFLAG(ANDROID_JAVA_UI) | 45 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
50 | 46 |
51 namespace chrome_browser_net { | 47 namespace chrome_browser_net { |
52 class DnsProbeService; | 48 class DnsProbeService; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 std::unique_ptr<net::HostMappingRules> host_mapping_rules; | 174 std::unique_ptr<net::HostMappingRules> host_mapping_rules; |
179 std::unique_ptr<net::HttpUserAgentSettings> http_user_agent_settings; | 175 std::unique_ptr<net::HttpUserAgentSettings> http_user_agent_settings; |
180 std::unique_ptr<net::NetworkQualityEstimator> network_quality_estimator; | 176 std::unique_ptr<net::NetworkQualityEstimator> network_quality_estimator; |
181 | 177 |
182 // NetErrorTabHelper uses |dns_probe_service| to send DNS probes when a | 178 // NetErrorTabHelper uses |dns_probe_service| to send DNS probes when a |
183 // main frame load fails with a DNS error in order to provide more useful | 179 // main frame load fails with a DNS error in order to provide more useful |
184 // information to the renderer so it can show a more specific error page. | 180 // information to the renderer so it can show a more specific error page. |
185 std::unique_ptr<chrome_browser_net::DnsProbeService> dns_probe_service; | 181 std::unique_ptr<chrome_browser_net::DnsProbeService> dns_probe_service; |
186 }; | 182 }; |
187 | 183 |
188 // Helper class to configure HttpNetworkSession::Params and | |
189 // HttpServerProperties based on field trials, policy, and command line. | |
190 class NetworkSessionConfigurator { | |
191 public: | |
192 // Configure |params| based on field trials and policy arguments. | |
193 static void ParseFieldTrials(bool is_spdy_allowed_by_policy, | |
194 bool is_quic_allowed_by_policy, | |
195 net::HttpNetworkSession::Params* params); | |
196 | |
197 // Configure |params| based on field trials, policy arguments, | |
198 // and command line. | |
199 static void ParseFieldTrialsAndCommandLine( | |
200 bool is_spdy_allowed_by_policy, | |
201 bool is_quic_allowed_by_policy, | |
202 net::HttpNetworkSession::Params* params); | |
203 | |
204 // Returns true if QUIC should be enabled for data reduction proxy, either | |
205 // as a result of a field trial or a command line flag. | |
206 static bool ShouldEnableQuicForDataReductionProxy( | |
207 const base::CommandLine& command_line); | |
208 | |
209 private: | |
210 // Map from name to value for all parameters associate with a field trial. | |
211 using VariationParameters = std::map<std::string, std::string>; | |
212 | |
213 static void ParseFieldTrialsAndCommandLineInternal( | |
214 const base::CommandLine& command_line, | |
215 bool is_spdy_allowed_by_policy, | |
216 bool is_quic_allowed_by_policy, | |
217 net::HttpNetworkSession::Params* params); | |
218 | |
219 // Configures Alternative Services based on command line options and the | |
220 // field trial group. | |
221 static void ConfigureAltSvcParams(const base::CommandLine& command_line, | |
222 base::StringPiece altsvc_trial_group, | |
223 net::HttpNetworkSession::Params* params); | |
224 | |
225 // Configures QUIC options based on the flags in |command_line| as well as | |
226 // the QUIC field trial group and parameters. Must be called before | |
227 // ConfigureSpdyParams. | |
228 static void ConfigureQuicParams( | |
229 const base::CommandLine& command_line, | |
230 base::StringPiece quic_trial_group, | |
231 const VariationParameters& quic_trial_params, | |
232 bool is_quic_allowed_by_policy, | |
233 net::HttpNetworkSession::Params* params); | |
234 | |
235 // Configures available SPDY protocol versions and parameters based on | |
236 // command line flags as well as SPDY field trial group and parameters. | |
237 // Must be called after ConfigureQuicParams. | |
238 static void ConfigureSpdyParams( | |
239 const base::CommandLine& command_line, | |
240 base::StringPiece spdy_trial_group, | |
241 const VariationParameters& spdy_trial_params, | |
242 bool is_spdy_allowed_by_policy, | |
243 net::HttpNetworkSession::Params* params); | |
244 | |
245 // Configure TCP FastOpen based on the field trial group. | |
246 static void ConfigureTCPFastOpenParams( | |
247 base::StringPiece tfo_trial_group, | |
248 net::HttpNetworkSession::Params* params); | |
249 | |
250 // Configures NPN based on command line and the field trial group. | |
251 static void ConfigureNPNParams(const base::CommandLine& command_line, | |
252 base::StringPiece npn_trial_group, | |
253 net::HttpNetworkSession::Params* params); | |
254 | |
255 // Configures the use of priority dependencies based on the field trial | |
256 // group. | |
257 static void ConfigurePriorityDependencies( | |
258 base::StringPiece priority_dependencies_trial_group, | |
259 net::HttpNetworkSession::Params* params); | |
260 | |
261 // Returns true if QUIC should be disabled when a connection times out with | |
262 // open streams. | |
263 static bool ShouldDisableQuicWhenConnectionTimesOutWithOpenStreams( | |
264 const VariationParameters& quic_trial_params); | |
265 | |
266 // Returns true if QUIC should be enabled, either as a result of a field | |
267 // trial or a command line flag. | |
268 static bool ShouldEnableQuic(const base::CommandLine& command_line, | |
269 base::StringPiece quic_trial_group, | |
270 bool quic_allowed_by_policy); | |
271 | |
272 // Returns true if QUIC should be enabled for proxies, either as a result of | |
273 // a field trial or a command line flag. | |
274 static bool ShouldEnableQuicForProxies( | |
275 const base::CommandLine& command_line, | |
276 base::StringPiece quic_trial_group, | |
277 bool quic_allowed_by_policy); | |
278 | |
279 // Returns true if the selection of the ephemeral port in bind() should be | |
280 // performed by Chromium, and false if the OS should select the port. The | |
281 // OS option is used to prevent Windows from posting a security warning | |
282 // dialog. | |
283 static bool ShouldEnableQuicPortSelection( | |
284 const base::CommandLine& command_line); | |
285 | |
286 // Returns true if QUIC should always require handshake confirmation during | |
287 // the QUIC handshake. | |
288 static bool ShouldQuicAlwaysRequireHandshakeConfirmation( | |
289 const VariationParameters& quic_trial_params); | |
290 | |
291 // Returns true if QUIC should disable connection pooling. | |
292 static bool ShouldQuicDisableConnectionPooling( | |
293 const VariationParameters& quic_trial_params); | |
294 | |
295 // Returns the ratio of time to load QUIC sever information from disk cache | |
296 // to 'smoothed RTT' based on field trial. Returns 0 if there is an error | |
297 // parsing the field trial params, or if the default value should be used. | |
298 static float GetQuicLoadServerInfoTimeoutSrttMultiplier( | |
299 const VariationParameters& quic_trial_params); | |
300 | |
301 // Returns true if QUIC's connection racing should be enabled. | |
302 static bool ShouldQuicEnableConnectionRacing( | |
303 const VariationParameters& quic_trial_params); | |
304 | |
305 // Returns true if QUIC's should use non-blocking IO. | |
306 static bool ShouldQuicEnableNonBlockingIO( | |
307 const VariationParameters& quic_trial_params); | |
308 | |
309 // Returns true if QUIC shouldn't load QUIC server information from the disk | |
310 // cache. | |
311 static bool ShouldQuicDisableDiskCache( | |
312 const VariationParameters& quic_trial_params); | |
313 | |
314 // Returns true if QUIC should prefer AES-GCN even without hardware support. | |
315 static bool ShouldQuicPreferAes( | |
316 const VariationParameters& quic_trial_params); | |
317 | |
318 // Returns true if QUIC should enable alternative services for different | |
319 // host. | |
320 static bool ShouldQuicEnableAlternativeServicesForDifferentHost( | |
321 const base::CommandLine& command_line, | |
322 const VariationParameters& quic_trial_params); | |
323 | |
324 // Returns the maximum number of QUIC connections with high packet loss in a | |
325 // row after which QUIC should be disabled. Returns 0 if the default value | |
326 // should be used. | |
327 static int GetQuicMaxNumberOfLossyConnections( | |
328 const VariationParameters& quic_trial_params); | |
329 | |
330 // Returns the packet loss rate in fraction after which a QUIC connection is | |
331 // closed and is considered as a lossy connection. Returns 0 if the default | |
332 // value should be used. | |
333 static float GetQuicPacketLossThreshold( | |
334 const VariationParameters& quic_trial_params); | |
335 | |
336 // Returns the size of the QUIC receive buffer to use, or 0 if the default | |
337 // should be used. | |
338 static int GetQuicSocketReceiveBufferSize( | |
339 const VariationParameters& quic_trial_params); | |
340 | |
341 // Returns true if QUIC should delay TCP connection when QUIC works. | |
342 static bool ShouldQuicDelayTcpRace( | |
343 const VariationParameters& quic_trial_params); | |
344 | |
345 // Returns true if QUIC should close sessions when any of the client's IP | |
346 // addresses change. | |
347 static bool ShouldQuicCloseSessionsOnIpChange( | |
348 const VariationParameters& quic_trial_params); | |
349 | |
350 // Returns the idle connection timeout for QUIC connections. Returns 0 if | |
351 // there is an error parsing any of the options, or if the default value | |
352 // should be used. | |
353 static int GetQuicIdleConnectionTimeoutSeconds( | |
354 const VariationParameters& quic_trial_params); | |
355 | |
356 // Returns true if PreConnect should be disabled if QUIC can do 0RTT. | |
357 static bool ShouldQuicDisablePreConnectIfZeroRtt( | |
358 const VariationParameters& quic_trial_params); | |
359 | |
360 // Returns the set of hosts to whitelist for QUIC. | |
361 static std::unordered_set<std::string> GetQuicHostWhitelist( | |
362 const base::CommandLine& command_line, | |
363 const VariationParameters& quic_trial_params); | |
364 | |
365 // Returns true if QUIC should migrate sessions when primary network | |
366 // changes. | |
367 static bool ShouldQuicMigrateSessionsOnNetworkChange( | |
368 const VariationParameters& quic_trial_params); | |
369 | |
370 // Returns true if QUIC should migrate sessions early. | |
371 static bool ShouldQuicMigrateSessionsEarly( | |
372 const VariationParameters& quic_trial_params); | |
373 | |
374 // Returns the maximum length for QUIC packets, based on any flags in | |
375 // |command_line| or the field trial. Returns 0 if there is an error | |
376 // parsing any of the options, or if the default value should be used. | |
377 static size_t GetQuicMaxPacketLength( | |
378 const base::CommandLine& command_line, | |
379 const VariationParameters& quic_trial_params); | |
380 | |
381 // Returns the QUIC versions specified by any flags in |command_line| or | |
382 // |quic_trial_params|. | |
383 static net::QuicVersion GetQuicVersion( | |
384 const base::CommandLine& command_line, | |
385 const VariationParameters& quic_trial_params); | |
386 | |
387 // Returns the QUIC version specified by |quic_version| or | |
388 // QUIC_VERSION_UNSUPPORTED if |quic_version| is invalid. | |
389 static net::QuicVersion ParseQuicVersion(const std::string& quic_version); | |
390 | |
391 // Returns the QUIC connection options specified by any flags in | |
392 // |command_line| or |quic_trial_params|. | |
393 static net::QuicTagVector GetQuicConnectionOptions( | |
394 const base::CommandLine& command_line, | |
395 const VariationParameters& quic_trial_params); | |
396 }; | |
397 | |
398 // |net_log| must either outlive the IOThread or be NULL. | 184 // |net_log| must either outlive the IOThread or be NULL. |
399 IOThread(PrefService* local_state, | 185 IOThread(PrefService* local_state, |
400 policy::PolicyService* policy_service, | 186 policy::PolicyService* policy_service, |
401 net_log::ChromeNetLog* net_log, | 187 net_log::ChromeNetLog* net_log, |
402 extensions::EventRouterForwarder* extension_event_router_forwarder); | 188 extensions::EventRouterForwarder* extension_event_router_forwarder); |
403 | 189 |
404 ~IOThread() override; | 190 ~IOThread() override; |
405 | 191 |
406 static void RegisterPrefs(PrefRegistrySimple* registry); | 192 static void RegisterPrefs(PrefRegistrySimple* registry); |
407 | 193 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 friend class SystemURLRequestContextGetter; | 229 friend class SystemURLRequestContextGetter; |
444 | 230 |
445 friend class test::IOThreadPeer; | 231 friend class test::IOThreadPeer; |
446 | 232 |
447 // BrowserThreadDelegate implementation, runs on the IO thread. | 233 // BrowserThreadDelegate implementation, runs on the IO thread. |
448 // This handles initialization and destruction of state that must | 234 // This handles initialization and destruction of state that must |
449 // live on the IO thread. | 235 // live on the IO thread. |
450 void Init() override; | 236 void Init() override; |
451 void CleanUp() override; | 237 void CleanUp() override; |
452 | 238 |
453 void InitializeNetworkOptions(const base::CommandLine& parsed_command_line); | |
454 | |
455 // Global state must be initialized on the IO thread, then this | 239 // Global state must be initialized on the IO thread, then this |
456 // method must be invoked on the UI thread. | 240 // method must be invoked on the UI thread. |
457 void InitSystemRequestContext(); | 241 void InitSystemRequestContext(); |
458 | 242 |
459 // Lazy initialization of system request context for | 243 // Lazy initialization of system request context for |
460 // SystemURLRequestContextGetter. To be called on IO thread only | 244 // SystemURLRequestContextGetter. To be called on IO thread only |
461 // after global state has been initialized on the IO thread, and | 245 // after global state has been initialized on the IO thread, and |
462 // SystemRequestContext state has been initialized on the UI thread. | 246 // SystemRequestContext state has been initialized on the UI thread. |
463 void InitSystemRequestContextOnIOThread(); | 247 void InitSystemRequestContextOnIOThread(); |
464 | 248 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 // to the IOThread. IOThread owns them all, despite not using scoped_ptr. | 294 // to the IOThread. IOThread owns them all, despite not using scoped_ptr. |
511 // This is because the destructor of IOThread runs on the wrong thread. All | 295 // This is because the destructor of IOThread runs on the wrong thread. All |
512 // member variables should be deleted in CleanUp(). | 296 // member variables should be deleted in CleanUp(). |
513 | 297 |
514 // These member variables are initialized in Init() and do not change for the | 298 // These member variables are initialized in Init() and do not change for the |
515 // lifetime of the IO thread. | 299 // lifetime of the IO thread. |
516 | 300 |
517 Globals* globals_; | 301 Globals* globals_; |
518 | 302 |
519 net::HttpNetworkSession::Params params_; | 303 net::HttpNetworkSession::Params params_; |
520 NetworkSessionConfigurator network_session_configurator_; | |
521 | 304 |
522 // Observer that logs network changes to the ChromeNetLog. | 305 // Observer that logs network changes to the ChromeNetLog. |
523 class LoggingNetworkChangeObserver; | 306 class LoggingNetworkChangeObserver; |
524 std::unique_ptr<LoggingNetworkChangeObserver> network_change_observer_; | 307 std::unique_ptr<LoggingNetworkChangeObserver> network_change_observer_; |
525 | 308 |
526 BooleanPrefMember system_enable_referrers_; | 309 BooleanPrefMember system_enable_referrers_; |
527 | 310 |
528 BooleanPrefMember dns_client_enabled_; | 311 BooleanPrefMember dns_client_enabled_; |
529 | 312 |
530 BooleanPrefMember quick_check_enabled_; | 313 BooleanPrefMember quick_check_enabled_; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 // Callback for updating data use prefs which needs to be initialized on UI | 356 // Callback for updating data use prefs which needs to be initialized on UI |
574 // thread and passed to |ChromeNetworkDelegate|. | 357 // thread and passed to |ChromeNetworkDelegate|. |
575 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; | 358 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; |
576 | 359 |
577 base::WeakPtrFactory<IOThread> weak_factory_; | 360 base::WeakPtrFactory<IOThread> weak_factory_; |
578 | 361 |
579 DISALLOW_COPY_AND_ASSIGN(IOThread); | 362 DISALLOW_COPY_AND_ASSIGN(IOThread); |
580 }; | 363 }; |
581 | 364 |
582 #endif // CHROME_BROWSER_IO_THREAD_H_ | 365 #endif // CHROME_BROWSER_IO_THREAD_H_ |
OLD | NEW |