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

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: Add dependencies for iOS. Created 4 years, 8 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> enable_quic_for_proxies;
149 Optional<bool> quic_always_require_handshake_confirmation;
150 Optional<bool> quic_disable_connection_pooling;
151 Optional<float> quic_load_server_info_timeout_srtt_multiplier;
152 Optional<bool> quic_enable_connection_racing;
153 Optional<bool> quic_enable_non_blocking_io;
154 Optional<bool> quic_disable_disk_cache;
155 Optional<bool> quic_prefer_aes;
156 Optional<int> quic_max_number_of_lossy_connections;
157 Optional<float> quic_packet_loss_threshold;
158 Optional<int> quic_socket_receive_buffer_size;
159 Optional<bool> quic_delay_tcp_race;
160 Optional<size_t> quic_max_packet_length;
161 net::QuicTagVector quic_connection_options;
162 Optional<std::string> quic_user_agent_id;
163 Optional<net::QuicVersionVector> quic_supported_versions;
164 Optional<bool> quic_close_sessions_on_ip_change;
165 }; 131 };
166 132
167 // |net_log| must either outlive the IOSChromeIOThread or be NULL. 133 // |net_log| must either outlive the IOSChromeIOThread or be NULL.
168 IOSChromeIOThread(PrefService* local_state, net_log::ChromeNetLog* net_log); 134 IOSChromeIOThread(PrefService* local_state, net_log::ChromeNetLog* net_log);
169 135
170 ~IOSChromeIOThread() override; 136 ~IOSChromeIOThread() override;
171 137
172 // Can only be called on the IO thread. 138 // Can only be called on the IO thread.
173 Globals* globals(); 139 Globals* globals();
174 140
175 // Allows overriding Globals in tests where IOSChromeIOThread::Init() and 141 // Allows overriding Globals in tests where IOSChromeIOThread::Init() and
176 // IOSChromeIOThread::CleanUp() are not called. This allows for injecting 142 // IOSChromeIOThread::CleanUp() are not called. This allows for injecting
177 // mocks into IOSChromeIOThread global objects. 143 // mocks into IOSChromeIOThread global objects.
178 void SetGlobalsForTesting(Globals* globals); 144 void SetGlobalsForTesting(Globals* globals);
179 145
180 net_log::ChromeNetLog* net_log(); 146 net_log::ChromeNetLog* net_log();
181 147
182 // Handles changing to On The Record mode, discarding confidential data. 148 // Handles changing to On The Record mode, discarding confidential data.
183 void ChangedToOnTheRecord(); 149 void ChangedToOnTheRecord();
184 150
185 // 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.
186 net::URLRequestContextGetter* system_url_request_context_getter(); 152 net::URLRequestContextGetter* system_url_request_context_getter();
187 153
188 // 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
189 // 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
190 // called on the IO thread. 156 // called on the IO thread.
191 void ClearHostCache(); 157 void ClearHostCache();
192 158
193 void InitializeNetworkSessionParams(net::HttpNetworkSession::Params* params); 159 const net::HttpNetworkSession::Params& NetworkSessionParams() const;
194 160
195 base::TimeTicks creation_time() const; 161 base::TimeTicks creation_time() const;
196 162
197 // Returns true if QUIC should be enabled for data reduction proxy as a result
198 // of a field trial.
199 static bool ShouldEnableQuicForDataReductionProxy();
200
201 private: 163 private:
202 // Map from name to value for all parameters associate with a field trial.
203 typedef std::map<std::string, std::string> VariationParameters;
204
205 // Provide SystemURLRequestContextGetter with access to 164 // Provide SystemURLRequestContextGetter with access to
206 // InitSystemRequestContext(). 165 // InitSystemRequestContext().
207 friend class SystemURLRequestContextGetter; 166 friend class SystemURLRequestContextGetter;
208 167
209 // WebThreadDelegate implementation, runs on the IO thread. 168 // WebThreadDelegate implementation, runs on the IO thread.
210 // This handles initialization and destruction of state that must 169 // This handles initialization and destruction of state that must
211 // live on the IO thread. 170 // live on the IO thread.
212 void Init() override; 171 void Init() override;
213 void CleanUp() override; 172 void CleanUp() override;
214 173
215 // Initializes |params| based on the settings in |globals|.
216 static void InitializeNetworkSessionParamsFromGlobals(
217 const Globals& globals,
218 net::HttpNetworkSession::Params* params);
219
220 void InitializeNetworkOptions();
221
222 // Sets up SSL TCP FastOpen if enabled via field trials.
223 void ConfigureSSLTCPFastOpen();
224
225 // Configures available SPDY protocol versions in |globals| based on the SPDY
226 // field trial group and parameters.
227 // Must be called after ConfigureQuicGlobals.
228 static void ConfigureSpdyGlobals(base::StringPiece quic_trial_group,
229 const VariationParameters& quic_trial_params,
230 Globals* globals);
231
232 // Configures Alternative Services in |globals| based on the field trial
233 // group.
234 static void ConfigureAltSvcGlobals(base::StringPiece altsvc_trial_group,
235 IOSChromeIOThread::Globals* globals);
236
237 // Configures NPN in |globals| based on the field trial group.
238 static void ConfigureNPNGlobals(base::StringPiece npn_trial_group,
239 Globals* globals);
240
241 // Global state must be initialized on the IO thread, then this 174 // Global state must be initialized on the IO thread, then this
242 // method must be invoked on the UI thread. 175 // method must be invoked on the UI thread.
243 void InitSystemRequestContext(); 176 void InitSystemRequestContext();
244 177
245 // Lazy initialization of system request context for 178 // Lazy initialization of system request context for
246 // SystemURLRequestContextGetter. To be called on IO thread only 179 // SystemURLRequestContextGetter. To be called on IO thread only
247 // after global state has been initialized on the IO thread, and 180 // after global state has been initialized on the IO thread, and
248 // SystemRequestContext state has been initialized on the UI thread. 181 // SystemRequestContext state has been initialized on the UI thread.
249 void InitSystemRequestContextOnIOThread(); 182 void InitSystemRequestContextOnIOThread();
250 183
251 void CreateDefaultAuthHandlerFactory(); 184 void CreateDefaultAuthHandlerFactory();
252 185
253 // Returns an SSLConfigService instance. 186 // Returns an SSLConfigService instance.
254 net::SSLConfigService* GetSSLConfigService(); 187 net::SSLConfigService* GetSSLConfigService();
255 188
256 void ChangedToOnTheRecordOnIOThread(); 189 void ChangedToOnTheRecordOnIOThread();
257 190
258 // Configure whether we set HTTP/2 dependencies from the
259 // net::RequestPriority.
260 void ConfigurePriorityDependencies();
261
262 // Configures QUIC options based on the QUIC field trial group.
263 void ConfigureQuic();
264
265 // Configures QUIC options in |globals| based on the flags in |command_line|
266 // as well as the QUIC field trial group and parameters.
267 // Must be called before ConfigureSpdyGlobals.
268 static void ConfigureQuicGlobals(base::StringPiece quic_trial_group,
269 const VariationParameters& quic_trial_params,
270 Globals* globals);
271
272 // Returns true if QUIC should be enabled as a result of a field trial.
273 static bool ShouldEnableQuic(base::StringPiece quic_trial_group);
274
275 // Returns true if QUIC should be enabled for proxies as a result of a
276 // field trial.
277 static bool ShouldEnableQuicForProxies(base::StringPiece quic_trial_group);
278
279 // Returns true if QUIC should always require handshake confirmation during
280 // the QUIC handshake.
281 static bool ShouldQuicAlwaysRequireHandshakeConfirmation(
282 const VariationParameters& quic_trial_params);
283
284 // Returns true if QUIC should disable connection pooling.
285 static bool ShouldQuicDisableConnectionPooling(
286 const VariationParameters& quic_trial_params);
287
288 // Returns the ratio of time to load QUIC sever information from disk cache to
289 // 'smoothed RTT' based on field trial. Returns 0 if there is an error parsing
290 // the field trial params, or if the default value should be used.
291 static float GetQuicLoadServerInfoTimeoutSrttMultiplier(
292 const VariationParameters& quic_trial_params);
293
294 // Returns true if QUIC's connection racing should be enabled.
295 static bool ShouldQuicEnableConnectionRacing(
296 const VariationParameters& quic_trial_params);
297
298 // Returns true if QUIC's should use non-blocking IO.
299 static bool ShouldQuicEnableNonBlockingIO(
300 const VariationParameters& quic_trial_params);
301
302 // Returns true if QUIC shouldn't load QUIC server information from the disk
303 // cache.
304 static bool ShouldQuicDisableDiskCache(
305 const VariationParameters& quic_trial_params);
306
307 // Returns true if QUIC should prefer AES-GCN even without hardware support.
308 static bool ShouldQuicPreferAes(const VariationParameters& quic_trial_params);
309
310 // Returns true if QUIC should enable alternative services for different host.
311 static bool ShouldQuicEnableAlternativeServicesForDifferentHost(
312 const VariationParameters& quic_trial_params);
313
314 // Returns the maximum number of QUIC connections with high packet loss in a
315 // row after which QUIC should be disabled. Returns 0 if the default value
316 // should be used.
317 static int GetQuicMaxNumberOfLossyConnections(
318 const VariationParameters& quic_trial_params);
319
320 // Returns the packet loss rate in fraction after which a QUIC connection is
321 // closed and is considered as a lossy connection. Returns 0 if the default
322 // value should be used.
323 static float GetQuicPacketLossThreshold(
324 const VariationParameters& quic_trial_params);
325
326 // Returns the size of the QUIC receive buffer to use, or 0 if
327 // the default should be used.
328 static int GetQuicSocketReceiveBufferSize(
329 const VariationParameters& quic_trial_params);
330
331 // Returns true if QUIC should delay TCP connection when QUIC works.
332 static bool ShouldQuicDelayTcpRace(
333 const VariationParameters& quic_trial_params);
334
335 // Returns true if QUIC should close sessions when any of the client's
336 // IP addresses change.
337 static bool ShouldQuicCloseSessionsOnIpChange(
338 const VariationParameters& quic_trial_params);
339
340 // Returns the maximum length for QUIC packets, based on any flags in the
341 // field trial. Returns 0 if there is an error parsing any of the options,
342 // or if the default value should be used.
343 static size_t GetQuicMaxPacketLength(
344 const VariationParameters& quic_trial_params);
345
346 // Returns the QUIC versions specified by any flags in |quic_trial_params|.
347 static net::QuicVersion GetQuicVersion(
348 const VariationParameters& quic_trial_params);
349
350 // Returns the QUIC version specified by |quic_version| or
351 // QUIC_VERSION_UNSUPPORTED if |quic_version| is invalid.
352 static net::QuicVersion ParseQuicVersion(const std::string& quic_version);
353
354 // Returns the QUIC connection options specified by any flags in
355 // |quic_trial_params|.
356 static net::QuicTagVector GetQuicConnectionOptions(
357 const VariationParameters& quic_trial_params);
358
359 static net::URLRequestContext* ConstructSystemRequestContext( 191 static net::URLRequestContext* ConstructSystemRequestContext(
360 Globals* globals, 192 Globals* globals,
193 const net::HttpNetworkSession::Params& params,
361 net::NetLog* net_log); 194 net::NetLog* net_log);
362 195
363 // 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
364 // 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.
365 net_log::ChromeNetLog* net_log_; 198 net_log::ChromeNetLog* net_log_;
366 199
367 // These member variables are basically global, but their lifetimes are tied 200 // These member variables are basically global, but their lifetimes are tied
368 // to the IOSChromeIOThread. IOSChromeIOThread owns them all, despite not 201 // to the IOSChromeIOThread. IOSChromeIOThread owns them all, despite not
369 // using scoped_ptr. This is because the destructor of IOSChromeIOThread runs 202 // using scoped_ptr. This is because the destructor of IOSChromeIOThread runs
370 // 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().
371 204
372 // 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
373 // lifetime of the IO thread. 206 // lifetime of the IO thread.
374 207
375 Globals* globals_; 208 Globals* globals_;
376 209
210 net::HttpNetworkSession::Params params_;
211
377 // Observer that logs network changes to the ChromeNetLog. 212 // Observer that logs network changes to the ChromeNetLog.
378 class LoggingNetworkChangeObserver; 213 class LoggingNetworkChangeObserver;
379 std::unique_ptr<LoggingNetworkChangeObserver> network_change_observer_; 214 std::unique_ptr<LoggingNetworkChangeObserver> network_change_observer_;
380 215
381 // This is an instance of the default SSLConfigServiceManager for the current 216 // This is an instance of the default SSLConfigServiceManager for the current
382 // platform and it gets SSL preferences from local_state object. 217 // platform and it gets SSL preferences from local_state object.
383 std::unique_ptr<ssl_config::SSLConfigServiceManager> 218 std::unique_ptr<ssl_config::SSLConfigServiceManager>
384 ssl_config_service_manager_; 219 ssl_config_service_manager_;
385 220
386 // 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,
387 // which gets posted by calling certain member functions of IOSChromeIOThread. 222 // which gets posted by calling certain member functions of IOSChromeIOThread.
388 std::unique_ptr<net::ProxyConfigService> system_proxy_config_service_; 223 std::unique_ptr<net::ProxyConfigService> system_proxy_config_service_;
389 224
390 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; 225 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
391 226
392 scoped_refptr<net::URLRequestContextGetter> 227 scoped_refptr<net::URLRequestContextGetter>
393 system_url_request_context_getter_; 228 system_url_request_context_getter_;
394 229
395 const base::TimeTicks creation_time_; 230 const base::TimeTicks creation_time_;
396 231
397 base::WeakPtrFactory<IOSChromeIOThread> weak_factory_; 232 base::WeakPtrFactory<IOSChromeIOThread> weak_factory_;
398 233
399 DISALLOW_COPY_AND_ASSIGN(IOSChromeIOThread); 234 DISALLOW_COPY_AND_ASSIGN(IOSChromeIOThread);
400 }; 235 };
401 236
402 #endif // IOS_CHROME_BROWSER_IOS_CHROME_IO_THREAD_H_ 237 #endif // IOS_CHROME_BROWSER_IOS_CHROME_IO_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698