| 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 close sessions when any of the client's IP | |
| 342 // addresses change. | |
| 343 static bool ShouldQuicCloseSessionsOnIpChange( | |
| 344 const VariationParameters& quic_trial_params); | |
| 345 | |
| 346 // Returns the idle connection timeout for QUIC connections. Returns 0 if | |
| 347 // there is an error parsing any of the options, or if the default value | |
| 348 // should be used. | |
| 349 static int GetQuicIdleConnectionTimeoutSeconds( | |
| 350 const VariationParameters& quic_trial_params); | |
| 351 | |
| 352 // Returns true if PreConnect should be disabled if QUIC can do 0RTT. | |
| 353 static bool ShouldQuicDisablePreConnectIfZeroRtt( | |
| 354 const VariationParameters& quic_trial_params); | |
| 355 | |
| 356 // Returns the set of hosts to whitelist for QUIC. | |
| 357 static std::unordered_set<std::string> GetQuicHostWhitelist( | |
| 358 const base::CommandLine& command_line, | |
| 359 const VariationParameters& quic_trial_params); | |
| 360 | |
| 361 // Returns true if QUIC should migrate sessions when primary network | |
| 362 // changes. | |
| 363 static bool ShouldQuicMigrateSessionsOnNetworkChange( | |
| 364 const VariationParameters& quic_trial_params); | |
| 365 | |
| 366 // Returns true if QUIC should migrate sessions early. | |
| 367 static bool ShouldQuicMigrateSessionsEarly( | |
| 368 const VariationParameters& quic_trial_params); | |
| 369 | |
| 370 // Returns the maximum length for QUIC packets, based on any flags in | |
| 371 // |command_line| or the field trial. Returns 0 if there is an error | |
| 372 // parsing any of the options, or if the default value should be used. | |
| 373 static size_t GetQuicMaxPacketLength( | |
| 374 const base::CommandLine& command_line, | |
| 375 const VariationParameters& quic_trial_params); | |
| 376 | |
| 377 // Returns the QUIC versions specified by any flags in |command_line| or | |
| 378 // |quic_trial_params|. | |
| 379 static net::QuicVersion GetQuicVersion( | |
| 380 const base::CommandLine& command_line, | |
| 381 const VariationParameters& quic_trial_params); | |
| 382 | |
| 383 // Returns the QUIC version specified by |quic_version| or | |
| 384 // QUIC_VERSION_UNSUPPORTED if |quic_version| is invalid. | |
| 385 static net::QuicVersion ParseQuicVersion(const std::string& quic_version); | |
| 386 | |
| 387 // Returns the QUIC connection options specified by any flags in | |
| 388 // |command_line| or |quic_trial_params|. | |
| 389 static net::QuicTagVector GetQuicConnectionOptions( | |
| 390 const base::CommandLine& command_line, | |
| 391 const VariationParameters& quic_trial_params); | |
| 392 }; | |
| 393 | |
| 394 // |net_log| must either outlive the IOThread or be NULL. | 184 // |net_log| must either outlive the IOThread or be NULL. |
| 395 IOThread(PrefService* local_state, | 185 IOThread(PrefService* local_state, |
| 396 policy::PolicyService* policy_service, | 186 policy::PolicyService* policy_service, |
| 397 net_log::ChromeNetLog* net_log, | 187 net_log::ChromeNetLog* net_log, |
| 398 extensions::EventRouterForwarder* extension_event_router_forwarder); | 188 extensions::EventRouterForwarder* extension_event_router_forwarder); |
| 399 | 189 |
| 400 ~IOThread() override; | 190 ~IOThread() override; |
| 401 | 191 |
| 402 static void RegisterPrefs(PrefRegistrySimple* registry); | 192 static void RegisterPrefs(PrefRegistrySimple* registry); |
| 403 | 193 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 friend class SystemURLRequestContextGetter; | 229 friend class SystemURLRequestContextGetter; |
| 440 | 230 |
| 441 friend class test::IOThreadPeer; | 231 friend class test::IOThreadPeer; |
| 442 | 232 |
| 443 // BrowserThreadDelegate implementation, runs on the IO thread. | 233 // BrowserThreadDelegate implementation, runs on the IO thread. |
| 444 // This handles initialization and destruction of state that must | 234 // This handles initialization and destruction of state that must |
| 445 // live on the IO thread. | 235 // live on the IO thread. |
| 446 void Init() override; | 236 void Init() override; |
| 447 void CleanUp() override; | 237 void CleanUp() override; |
| 448 | 238 |
| 449 void InitializeNetworkOptions(const base::CommandLine& parsed_command_line); | |
| 450 | |
| 451 // Global state must be initialized on the IO thread, then this | 239 // Global state must be initialized on the IO thread, then this |
| 452 // method must be invoked on the UI thread. | 240 // method must be invoked on the UI thread. |
| 453 void InitSystemRequestContext(); | 241 void InitSystemRequestContext(); |
| 454 | 242 |
| 455 // Lazy initialization of system request context for | 243 // Lazy initialization of system request context for |
| 456 // SystemURLRequestContextGetter. To be called on IO thread only | 244 // SystemURLRequestContextGetter. To be called on IO thread only |
| 457 // after global state has been initialized on the IO thread, and | 245 // after global state has been initialized on the IO thread, and |
| 458 // SystemRequestContext state has been initialized on the UI thread. | 246 // SystemRequestContext state has been initialized on the UI thread. |
| 459 void InitSystemRequestContextOnIOThread(); | 247 void InitSystemRequestContextOnIOThread(); |
| 460 | 248 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 // 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. |
| 507 // 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 |
| 508 // member variables should be deleted in CleanUp(). | 296 // member variables should be deleted in CleanUp(). |
| 509 | 297 |
| 510 // 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 |
| 511 // lifetime of the IO thread. | 299 // lifetime of the IO thread. |
| 512 | 300 |
| 513 Globals* globals_; | 301 Globals* globals_; |
| 514 | 302 |
| 515 net::HttpNetworkSession::Params params_; | 303 net::HttpNetworkSession::Params params_; |
| 516 NetworkSessionConfigurator network_session_configurator_; | |
| 517 | 304 |
| 518 // Observer that logs network changes to the ChromeNetLog. | 305 // Observer that logs network changes to the ChromeNetLog. |
| 519 class LoggingNetworkChangeObserver; | 306 class LoggingNetworkChangeObserver; |
| 520 std::unique_ptr<LoggingNetworkChangeObserver> network_change_observer_; | 307 std::unique_ptr<LoggingNetworkChangeObserver> network_change_observer_; |
| 521 | 308 |
| 522 BooleanPrefMember system_enable_referrers_; | 309 BooleanPrefMember system_enable_referrers_; |
| 523 | 310 |
| 524 BooleanPrefMember dns_client_enabled_; | 311 BooleanPrefMember dns_client_enabled_; |
| 525 | 312 |
| 526 BooleanPrefMember quick_check_enabled_; | 313 BooleanPrefMember quick_check_enabled_; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 // 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 |
| 570 // thread and passed to |ChromeNetworkDelegate|. | 357 // thread and passed to |ChromeNetworkDelegate|. |
| 571 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; | 358 metrics::UpdateUsagePrefCallbackType metrics_data_use_forwarder_; |
| 572 | 359 |
| 573 base::WeakPtrFactory<IOThread> weak_factory_; | 360 base::WeakPtrFactory<IOThread> weak_factory_; |
| 574 | 361 |
| 575 DISALLOW_COPY_AND_ASSIGN(IOThread); | 362 DISALLOW_COPY_AND_ASSIGN(IOThread); |
| 576 }; | 363 }; |
| 577 | 364 |
| 578 #endif // CHROME_BROWSER_IO_THREAD_H_ | 365 #endif // CHROME_BROWSER_IO_THREAD_H_ |
| OLD | NEW |