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

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