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

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

Issue 1892123003: Add components/network_session_configurator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on https://crrev.com/1945513002. Created 4 years, 7 months 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
OLDNEW
1 // Copyright 2015 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 #ifndef IOS_CHROME_BROWSER_IOS_CHROME_IO_THREAD_H_ 5 #ifndef IOS_CHROME_BROWSER_IOS_CHROME_IO_THREAD_H_
6 #define IOS_CHROME_BROWSER_IOS_CHROME_IO_THREAD_H_ 6 #define IOS_CHROME_BROWSER_IOS_CHROME_IO_THREAD_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <set> 13 #include <set>
14 #include <string> 14 #include <string>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/compiler_specific.h" 17 #include "base/compiler_specific.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
20 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
21 #include "base/strings/string_piece.h"
22 #include "base/time/time.h" 21 #include "base/time/time.h"
23 #include "components/prefs/pref_member.h" 22 #include "components/prefs/pref_member.h"
24 #include "components/ssl_config/ssl_config_service_manager.h" 23 #include "components/ssl_config/ssl_config_service_manager.h"
25 #include "ios/web/public/web_thread_delegate.h" 24 #include "ios/web/public/web_thread_delegate.h"
26 #include "net/base/network_change_notifier.h" 25 #include "net/base/network_change_notifier.h"
27 #include "net/http/http_network_session.h" 26 #include "net/http/http_network_session.h"
28 27
29 class PrefProxyConfigTracker; 28 class PrefProxyConfigTracker;
30 class PrefService; 29 class PrefService;
31 class SystemURLRequestContextGetter; 30 class SystemURLRequestContextGetter;
32 31
33 namespace base { 32 namespace base {
34 class CommandLine; 33 class CommandLine;
35 } // namespace base 34 } // namespace base
36 35
37 namespace net { 36 namespace net {
38 class CTPolicyEnforcer; 37 class CTPolicyEnforcer;
39 class CertVerifier; 38 class CertVerifier;
40 class ChannelIDService; 39 class ChannelIDService;
41 class CookieStore; 40 class CookieStore;
42 class CTVerifier; 41 class CTVerifier;
43 class HostResolver; 42 class HostResolver;
44 class HttpAuthHandlerFactory; 43 class HttpAuthHandlerFactory;
45 class HttpAuthPreferences; 44 class HttpAuthPreferences;
46 class HttpNetworkSession;
47 class HttpServerProperties; 45 class HttpServerProperties;
48 class HttpTransactionFactory; 46 class HttpTransactionFactory;
49 class HttpUserAgentSettings; 47 class HttpUserAgentSettings;
50 class NetworkDelegate; 48 class NetworkDelegate;
51 class NetworkQualityEstimator; 49 class NetworkQualityEstimator;
52 class ProxyConfigService; 50 class ProxyConfigService;
53 class ProxyService; 51 class ProxyService;
54 class SSLConfigService; 52 class SSLConfigService;
55 class TransportSecurityState; 53 class TransportSecurityState;
56 class URLRequestBackoffManager; 54 class URLRequestBackoffManager;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 std::unique_ptr<net::NetworkDelegate> system_network_delegate; 106 std::unique_ptr<net::NetworkDelegate> system_network_delegate;
109 std::unique_ptr<net::HostResolver> host_resolver; 107 std::unique_ptr<net::HostResolver> host_resolver;
110 std::unique_ptr<net::CertVerifier> cert_verifier; 108 std::unique_ptr<net::CertVerifier> cert_verifier;
111 // The ChannelIDService must outlive the HttpTransactionFactory. 109 // The ChannelIDService must outlive the HttpTransactionFactory.
112 std::unique_ptr<net::ChannelIDService> system_channel_id_service; 110 std::unique_ptr<net::ChannelIDService> system_channel_id_service;
113 // This TransportSecurityState doesn't load or save any state. It's only 111 // This TransportSecurityState doesn't load or save any state. It's only
114 // used to enforce pinning for system requests and will only use built-in 112 // used to enforce pinning for system requests and will only use built-in
115 // pins. 113 // pins.
116 std::unique_ptr<net::TransportSecurityState> transport_security_state; 114 std::unique_ptr<net::TransportSecurityState> transport_security_state;
117 std::unique_ptr<net::CTVerifier> cert_transparency_verifier; 115 std::unique_ptr<net::CTVerifier> cert_transparency_verifier;
118 std::unique_ptr<net::CTPolicyEnforcer> ct_policy_enforcer;
119 scoped_refptr<net::SSLConfigService> ssl_config_service; 116 scoped_refptr<net::SSLConfigService> ssl_config_service;
120 std::unique_ptr<net::HttpAuthPreferences> http_auth_preferences; 117 std::unique_ptr<net::HttpAuthPreferences> http_auth_preferences;
121 std::unique_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory; 118 std::unique_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory;
122 std::unique_ptr<net::HttpServerProperties> http_server_properties; 119 std::unique_ptr<net::HttpServerProperties> http_server_properties;
123 std::unique_ptr<net::URLRequestBackoffManager> url_request_backoff_manager; 120 std::unique_ptr<net::URLRequestBackoffManager> url_request_backoff_manager;
124 std::unique_ptr<net::ProxyService> system_proxy_service; 121 std::unique_ptr<net::ProxyService> system_proxy_service;
125 std::unique_ptr<net::HttpNetworkSession> system_http_network_session; 122 std::unique_ptr<net::HttpNetworkSession> system_http_network_session;
126 std::unique_ptr<net::HttpTransactionFactory> 123 std::unique_ptr<net::HttpTransactionFactory>
127 system_http_transaction_factory; 124 system_http_transaction_factory;
128 std::unique_ptr<net::URLRequestJobFactory> system_url_request_job_factory; 125 std::unique_ptr<net::URLRequestJobFactory> system_url_request_job_factory;
129 std::unique_ptr<net::URLRequestContext> system_request_context; 126 std::unique_ptr<net::URLRequestContext> system_request_context;
130 SystemRequestContextLeakChecker system_request_context_leak_checker; 127 SystemRequestContextLeakChecker system_request_context_leak_checker;
131 std::unique_ptr<net::CookieStore> system_cookie_store; 128 std::unique_ptr<net::CookieStore> system_cookie_store;
132 std::unique_ptr<net::HttpUserAgentSettings> http_user_agent_settings; 129 std::unique_ptr<net::HttpUserAgentSettings> http_user_agent_settings;
133 std::unique_ptr<net::NetworkQualityEstimator> network_quality_estimator; 130 std::unique_ptr<net::NetworkQualityEstimator> network_quality_estimator;
134 uint16_t testing_fixed_http_port;
135 uint16_t testing_fixed_https_port;
136 Optional<bool> enable_tcp_fast_open_for_ssl;
137
138 Optional<bool> enable_spdy31;
139 Optional<bool> enable_http2;
140 Optional<bool> parse_alternative_services;
141 Optional<bool> enable_alternative_service_with_different_host;
142
143 Optional<bool> enable_npn;
144
145 Optional<bool> enable_priority_dependencies;
146
147 Optional<bool> enable_quic;
148 Optional<bool> quic_always_require_handshake_confirmation;
149 Optional<bool> quic_disable_connection_pooling;
150 Optional<float> quic_load_server_info_timeout_srtt_multiplier;
151 Optional<bool> quic_enable_connection_racing;
152 Optional<bool> quic_enable_non_blocking_io;
153 Optional<bool> quic_disable_disk_cache;
154 Optional<bool> quic_prefer_aes;
155 Optional<int> quic_max_number_of_lossy_connections;
156 Optional<float> quic_packet_loss_threshold;
157 Optional<int> quic_socket_receive_buffer_size;
158 Optional<bool> quic_delay_tcp_race;
159 Optional<size_t> quic_max_packet_length;
160 net::QuicTagVector quic_connection_options;
161 Optional<std::string> quic_user_agent_id;
162 Optional<net::QuicVersionVector> quic_supported_versions;
163 Optional<bool> quic_close_sessions_on_ip_change;
164 }; 131 };
165 132
166 // |net_log| must either outlive the IOSChromeIOThread or be NULL. 133 // |net_log| must either outlive the IOSChromeIOThread or be NULL.
167 IOSChromeIOThread(PrefService* local_state, net_log::ChromeNetLog* net_log); 134 IOSChromeIOThread(PrefService* local_state, net_log::ChromeNetLog* net_log);
168 135
169 ~IOSChromeIOThread() override; 136 ~IOSChromeIOThread() override;
170 137
171 // Can only be called on the IO thread. 138 // Can only be called on the IO thread.
172 Globals* globals(); 139 Globals* globals();
173 140
174 // Allows overriding Globals in tests where IOSChromeIOThread::Init() and 141 // Allows overriding Globals in tests where IOSChromeIOThread::Init() and
175 // IOSChromeIOThread::CleanUp() are not called. This allows for injecting 142 // IOSChromeIOThread::CleanUp() are not called. This allows for injecting
176 // mocks into IOSChromeIOThread global objects. 143 // mocks into IOSChromeIOThread global objects.
177 void SetGlobalsForTesting(Globals* globals); 144 void SetGlobalsForTesting(Globals* globals);
178 145
179 net_log::ChromeNetLog* net_log(); 146 net_log::ChromeNetLog* net_log();
180 147
181 // Handles changing to On The Record mode, discarding confidential data. 148 // Handles changing to On The Record mode, discarding confidential data.
182 void ChangedToOnTheRecord(); 149 void ChangedToOnTheRecord();
183 150
184 // Returns a getter for the URLRequestContext. Only called on the UI thread. 151 // Returns a getter for the URLRequestContext. Only called on the UI thread.
185 net::URLRequestContextGetter* system_url_request_context_getter(); 152 net::URLRequestContextGetter* system_url_request_context_getter();
186 153
187 // Clears the host cache. Intended to be used to prevent exposing recently 154 // Clears the host cache. Intended to be used to prevent exposing recently
188 // visited sites on about:net-internals/#dns and about:dns pages. Must be 155 // visited sites on about:net-internals/#dns and about:dns pages. Must be
189 // called on the IO thread. 156 // called on the IO thread.
190 void ClearHostCache(); 157 void ClearHostCache();
191 158
192 void InitializeNetworkSessionParams(net::HttpNetworkSession::Params* params); 159 const net::HttpNetworkSession::Params& NetworkSessionParams() const;
193 160
194 base::TimeTicks creation_time() const; 161 base::TimeTicks creation_time() const;
195 162
196 private: 163 private:
197 // Map from name to value for all parameters associate with a field trial.
198 typedef std::map<std::string, std::string> VariationParameters;
199
200 // Provide SystemURLRequestContextGetter with access to 164 // Provide SystemURLRequestContextGetter with access to
201 // InitSystemRequestContext(). 165 // InitSystemRequestContext().
202 friend class SystemURLRequestContextGetter; 166 friend class SystemURLRequestContextGetter;
203 167
204 // WebThreadDelegate implementation, runs on the IO thread. 168 // WebThreadDelegate implementation, runs on the IO thread.
205 // This handles initialization and destruction of state that must 169 // This handles initialization and destruction of state that must
206 // live on the IO thread. 170 // live on the IO thread.
207 void Init() override; 171 void Init() override;
208 void CleanUp() override; 172 void CleanUp() override;
209 173
210 // Initializes |params| based on the settings in |globals|.
211 static void InitializeNetworkSessionParamsFromGlobals(
212 const Globals& globals,
213 net::HttpNetworkSession::Params* params);
214
215 void InitializeNetworkOptions();
216
217 // Sets up SSL TCP FastOpen if enabled via field trials.
218 void ConfigureSSLTCPFastOpen();
219
220 // Configures available SPDY protocol versions in |globals| based on the SPDY
221 // field trial group and parameters.
222 // Must be called after ConfigureQuicGlobals.
223 static void ConfigureSpdyGlobals(base::StringPiece quic_trial_group,
224 const VariationParameters& quic_trial_params,
225 Globals* globals);
226
227 // Configures Alternative Services in |globals| based on the field trial
228 // group.
229 static void ConfigureAltSvcGlobals(base::StringPiece altsvc_trial_group,
230 IOSChromeIOThread::Globals* globals);
231
232 // Configures NPN in |globals| based on the field trial group.
233 static void ConfigureNPNGlobals(base::StringPiece npn_trial_group,
234 Globals* globals);
235
236 // Global state must be initialized on the IO thread, then this 174 // Global state must be initialized on the IO thread, then this
237 // method must be invoked on the UI thread. 175 // method must be invoked on the UI thread.
238 void InitSystemRequestContext(); 176 void InitSystemRequestContext();
239 177
240 // Lazy initialization of system request context for 178 // Lazy initialization of system request context for
241 // SystemURLRequestContextGetter. To be called on IO thread only 179 // SystemURLRequestContextGetter. To be called on IO thread only
242 // after global state has been initialized on the IO thread, and 180 // after global state has been initialized on the IO thread, and
243 // SystemRequestContext state has been initialized on the UI thread. 181 // SystemRequestContext state has been initialized on the UI thread.
244 void InitSystemRequestContextOnIOThread(); 182 void InitSystemRequestContextOnIOThread();
245 183
246 void CreateDefaultAuthHandlerFactory(); 184 void CreateDefaultAuthHandlerFactory();
247 185
248 // Returns an SSLConfigService instance. 186 // Returns an SSLConfigService instance.
249 net::SSLConfigService* GetSSLConfigService(); 187 net::SSLConfigService* GetSSLConfigService();
250 188
251 void ChangedToOnTheRecordOnIOThread(); 189 void ChangedToOnTheRecordOnIOThread();
252 190
253 // Configure whether we set HTTP/2 dependencies from the
254 // net::RequestPriority.
255 void ConfigurePriorityDependencies();
256
257 // Configures QUIC options based on the QUIC field trial group.
258 void ConfigureQuic();
259
260 // Configures QUIC options in |globals| based on the flags in |command_line|
261 // as well as the QUIC field trial group and parameters.
262 // Must be called before ConfigureSpdyGlobals.
263 static void ConfigureQuicGlobals(base::StringPiece quic_trial_group,
264 const VariationParameters& quic_trial_params,
265 Globals* globals);
266
267 // Returns true if QUIC should be enabled as a result of a field trial.
268 static bool ShouldEnableQuic(base::StringPiece quic_trial_group);
269
270 // Returns true if QUIC should always require handshake confirmation during
271 // the QUIC handshake.
272 static bool ShouldQuicAlwaysRequireHandshakeConfirmation(
273 const VariationParameters& quic_trial_params);
274
275 // Returns true if QUIC should disable connection pooling.
276 static bool ShouldQuicDisableConnectionPooling(
277 const VariationParameters& quic_trial_params);
278
279 // Returns the ratio of time to load QUIC sever information from disk cache to
280 // 'smoothed RTT' based on field trial. Returns 0 if there is an error parsing
281 // the field trial params, or if the default value should be used.
282 static float GetQuicLoadServerInfoTimeoutSrttMultiplier(
283 const VariationParameters& quic_trial_params);
284
285 // Returns true if QUIC's connection racing should be enabled.
286 static bool ShouldQuicEnableConnectionRacing(
287 const VariationParameters& quic_trial_params);
288
289 // Returns true if QUIC's should use non-blocking IO.
290 static bool ShouldQuicEnableNonBlockingIO(
291 const VariationParameters& quic_trial_params);
292
293 // Returns true if QUIC shouldn't load QUIC server information from the disk
294 // cache.
295 static bool ShouldQuicDisableDiskCache(
296 const VariationParameters& quic_trial_params);
297
298 // Returns true if QUIC should prefer AES-GCN even without hardware support.
299 static bool ShouldQuicPreferAes(const VariationParameters& quic_trial_params);
300
301 // Returns true if QUIC should enable alternative services for different host.
302 static bool ShouldQuicEnableAlternativeServicesForDifferentHost(
303 const VariationParameters& quic_trial_params);
304
305 // Returns the maximum number of QUIC connections with high packet loss in a
306 // row after which QUIC should be disabled. Returns 0 if the default value
307 // should be used.
308 static int GetQuicMaxNumberOfLossyConnections(
309 const VariationParameters& quic_trial_params);
310
311 // Returns the packet loss rate in fraction after which a QUIC connection is
312 // closed and is considered as a lossy connection. Returns 0 if the default
313 // value should be used.
314 static float GetQuicPacketLossThreshold(
315 const VariationParameters& quic_trial_params);
316
317 // Returns the size of the QUIC receive buffer to use, or 0 if
318 // the default should be used.
319 static int GetQuicSocketReceiveBufferSize(
320 const VariationParameters& quic_trial_params);
321
322 // Returns true if QUIC should delay TCP connection when QUIC works.
323 static bool ShouldQuicDelayTcpRace(
324 const VariationParameters& quic_trial_params);
325
326 // Returns true if QUIC should close sessions when any of the client's
327 // IP addresses change.
328 static bool ShouldQuicCloseSessionsOnIpChange(
329 const VariationParameters& quic_trial_params);
330
331 // Returns the maximum length for QUIC packets, based on any flags in the
332 // field trial. Returns 0 if there is an error parsing any of the options,
333 // or if the default value should be used.
334 static size_t GetQuicMaxPacketLength(
335 const VariationParameters& quic_trial_params);
336
337 // Returns the QUIC versions specified by any flags in |quic_trial_params|.
338 static net::QuicVersion GetQuicVersion(
339 const VariationParameters& quic_trial_params);
340
341 // Returns the QUIC version specified by |quic_version| or
342 // QUIC_VERSION_UNSUPPORTED if |quic_version| is invalid.
343 static net::QuicVersion ParseQuicVersion(const std::string& quic_version);
344
345 // Returns the QUIC connection options specified by any flags in
346 // |quic_trial_params|.
347 static net::QuicTagVector GetQuicConnectionOptions(
348 const VariationParameters& quic_trial_params);
349
350 static net::URLRequestContext* ConstructSystemRequestContext( 191 static net::URLRequestContext* ConstructSystemRequestContext(
351 Globals* globals, 192 Globals* globals,
193 const net::HttpNetworkSession::Params& params,
352 net::NetLog* net_log); 194 net::NetLog* net_log);
353 195
354 // The NetLog is owned by the application context, to allow logging from other 196 // The NetLog is owned by the application context, to allow logging from other
355 // threads during shutdown, but is used most frequently on the IO thread. 197 // threads during shutdown, but is used most frequently on the IO thread.
356 net_log::ChromeNetLog* net_log_; 198 net_log::ChromeNetLog* net_log_;
357 199
358 // These member variables are basically global, but their lifetimes are tied 200 // These member variables are basically global, but their lifetimes are tied
359 // to the IOSChromeIOThread. IOSChromeIOThread owns them all, despite not 201 // to the IOSChromeIOThread. IOSChromeIOThread owns them all, despite not
360 // using scoped_ptr. This is because the destructor of IOSChromeIOThread runs 202 // using scoped_ptr. This is because the destructor of IOSChromeIOThread runs
361 // on the wrong thread. All member variables should be deleted in CleanUp(). 203 // on the wrong thread. All member variables should be deleted in CleanUp().
362 204
363 // These member variables are initialized in Init() and do not change for the 205 // These member variables are initialized in Init() and do not change for the
364 // lifetime of the IO thread. 206 // lifetime of the IO thread.
365 207
366 Globals* globals_; 208 Globals* globals_;
367 209
210 net::HttpNetworkSession::Params params_;
211
368 // Observer that logs network changes to the ChromeNetLog. 212 // Observer that logs network changes to the ChromeNetLog.
369 class LoggingNetworkChangeObserver; 213 class LoggingNetworkChangeObserver;
370 std::unique_ptr<LoggingNetworkChangeObserver> network_change_observer_; 214 std::unique_ptr<LoggingNetworkChangeObserver> network_change_observer_;
371 215
372 // This is an instance of the default SSLConfigServiceManager for the current 216 // This is an instance of the default SSLConfigServiceManager for the current
373 // platform and it gets SSL preferences from local_state object. 217 // platform and it gets SSL preferences from local_state object.
374 std::unique_ptr<ssl_config::SSLConfigServiceManager> 218 std::unique_ptr<ssl_config::SSLConfigServiceManager>
375 ssl_config_service_manager_; 219 ssl_config_service_manager_;
376 220
377 // These member variables are initialized by a task posted to the IO thread, 221 // These member variables are initialized by a task posted to the IO thread,
378 // which gets posted by calling certain member functions of IOSChromeIOThread. 222 // which gets posted by calling certain member functions of IOSChromeIOThread.
379 std::unique_ptr<net::ProxyConfigService> system_proxy_config_service_; 223 std::unique_ptr<net::ProxyConfigService> system_proxy_config_service_;
380 224
381 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; 225 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
382 226
383 scoped_refptr<net::URLRequestContextGetter> 227 scoped_refptr<net::URLRequestContextGetter>
384 system_url_request_context_getter_; 228 system_url_request_context_getter_;
385 229
386 const base::TimeTicks creation_time_; 230 const base::TimeTicks creation_time_;
387 231
388 base::WeakPtrFactory<IOSChromeIOThread> weak_factory_; 232 base::WeakPtrFactory<IOSChromeIOThread> weak_factory_;
389 233
390 DISALLOW_COPY_AND_ASSIGN(IOSChromeIOThread); 234 DISALLOW_COPY_AND_ASSIGN(IOSChromeIOThread);
391 }; 235 };
392 236
393 #endif // IOS_CHROME_BROWSER_IOS_CHROME_IO_THREAD_H_ 237 #endif // IOS_CHROME_BROWSER_IOS_CHROME_IO_THREAD_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/browser_state/chrome_browser_state_io_data.cc ('k') | ios/chrome/browser/ios_chrome_io_thread.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698