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

Side by Side Diff: ios/components/io_thread/io_thread.h

Issue 2894483003: Initialize ios/web_view translate with a system-wide URLRequestContext. (Closed)
Patch Set: Remove unneeded deps. Created 3 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef IOS_COMPONENTS_IO_THREAD_IO_THREAD_H_
6 #define IOS_COMPONENTS_IO_THREAD_IO_THREAD_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <map>
12 #include <memory>
13 #include <set>
14 #include <string>
15 #include <vector>
16
17 #include "base/compiler_specific.h"
18 #include "base/macros.h"
19 #include "base/memory/ref_counted.h"
20 #include "base/memory/weak_ptr.h"
21 #include "base/time/time.h"
22 #include "components/prefs/pref_member.h"
23 #include "components/ssl_config/ssl_config_service_manager.h"
24 #include "ios/web/public/web_thread_delegate.h"
25 #include "net/base/network_change_notifier.h"
26 #include "net/http/http_network_session.h"
27
28 class PrefProxyConfigTracker;
29 class PrefService;
30
31 namespace net {
32 class CTPolicyEnforcer;
33 class CertVerifier;
34 class ChannelIDService;
35 class CookieStore;
36 class CTVerifier;
37 class HostResolver;
38 class HttpAuthHandlerFactory;
39 class HttpAuthPreferences;
40 class HttpServerProperties;
41 class HttpTransactionFactory;
42 class HttpUserAgentSettings;
43 class NetworkDelegate;
44 class NetworkQualityEstimator;
45 class ProxyConfigService;
46 class ProxyService;
47 class SSLConfigService;
48 class TransportSecurityState;
49 class URLRequestContext;
50 class URLRequestContextGetter;
51 class URLRequestJobFactory;
52 } // namespace net
53
54 namespace net_log {
55 class ChromeNetLog;
56 } // namespace net_log
57
58 namespace io_thread {
59
60 class SystemURLRequestContextGetter;
61
62 // Contains state associated with, initialized and cleaned up on, and
63 // primarily used on, the IO thread.
64 //
65 // If you are looking to interact with the IO thread (e.g. post tasks
66 // to it or check if it is the current thread), see web::WebThread.
67 //
68 // TODO(crbug.com/725524): Merge logic common with ios/chrome into a superclass.
69 class IOThread : public web::WebThreadDelegate {
70 public:
71 struct Globals {
72 template <typename T>
73 class Optional {
74 public:
75 Optional() : set_(false) {}
76
77 void set(T value) {
78 set_ = true;
79 value_ = value;
80 }
81 void CopyToIfSet(T* value) const {
82 if (set_) {
83 *value = value_;
84 }
85 }
86
87 private:
88 bool set_;
89 T value_;
90 };
91
92 class SystemRequestContextLeakChecker {
93 public:
94 explicit SystemRequestContextLeakChecker(Globals* globals);
95 ~SystemRequestContextLeakChecker();
96
97 private:
98 Globals* const globals_;
99 };
100
101 Globals();
102 ~Globals();
103
104 // The "system" NetworkDelegate, used for BrowserState-agnostic network
105 // events.
106 std::unique_ptr<net::NetworkDelegate> system_network_delegate;
107 std::unique_ptr<net::HostResolver> host_resolver;
108 std::unique_ptr<net::CertVerifier> cert_verifier;
109 // The ChannelIDService must outlive the HttpTransactionFactory.
110 std::unique_ptr<net::ChannelIDService> system_channel_id_service;
111 // This TransportSecurityState doesn't load or save any state. It's only
112 // used to enforce pinning for system requests and will only use built-in
113 // pins.
114 std::unique_ptr<net::TransportSecurityState> transport_security_state;
115 std::unique_ptr<net::CTVerifier> cert_transparency_verifier;
116 scoped_refptr<net::SSLConfigService> ssl_config_service;
117 std::unique_ptr<net::HttpAuthPreferences> http_auth_preferences;
118 std::unique_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory;
119 std::unique_ptr<net::HttpServerProperties> http_server_properties;
120 std::unique_ptr<net::ProxyService> system_proxy_service;
121 std::unique_ptr<net::HttpNetworkSession> system_http_network_session;
122 std::unique_ptr<net::HttpTransactionFactory>
123 system_http_transaction_factory;
124 std::unique_ptr<net::URLRequestJobFactory> system_url_request_job_factory;
125 std::unique_ptr<net::URLRequestContext> system_request_context;
126 SystemRequestContextLeakChecker system_request_context_leak_checker;
127 std::unique_ptr<net::CookieStore> system_cookie_store;
128 std::unique_ptr<net::HttpUserAgentSettings> http_user_agent_settings;
129 std::unique_ptr<net::NetworkQualityEstimator> network_quality_estimator;
130 std::unique_ptr<net::CTPolicyEnforcer> ct_policy_enforcer;
131 };
132
133 // |net_log| must either outlive the IOThread or be NULL.
134 IOThread(PrefService* local_state, net_log::ChromeNetLog* net_log);
135 ~IOThread() override;
136
137 // Can only be called on the IO thread.
138 Globals* globals();
139
140 // Allows overriding Globals in tests where IOThread::Init() and
141 // IOThread::CleanUp() are not called. This allows for injecting mocks into
142 // IOThread global objects.
143 void SetGlobalsForTesting(Globals* globals);
144
145 net_log::ChromeNetLog* net_log();
146
147 // Handles changing to On The Record mode, discarding confidential data.
148 void ChangedToOnTheRecord();
149
150 // Returns a getter for the URLRequestContext. Only called on the UI thread.
151 net::URLRequestContextGetter* system_url_request_context_getter();
152
153 // Clears the host cache. Intended to be used to prevent exposing recently
154 // visited sites on about:net-internals/#dns and about:dns pages. Must be
155 // called on the IO thread.
156 void ClearHostCache();
157
158 const net::HttpNetworkSession::Params& NetworkSessionParams() const;
159
160 base::TimeTicks creation_time() const;
161
162 protected:
163 virtual std::unique_ptr<net::NetworkDelegate> GetSystemNetworkDelegate() = 0;
164
165 private:
166 // Provide SystemURLRequestContextGetter with access to
167 // InitSystemRequestContext().
168 friend class SystemURLRequestContextGetter;
169
170 // WebThreadDelegate implementation, runs on the IO thread.
171 // This handles initialization and destruction of state that must
172 // live on the IO thread.
173 void Init() override;
174 void CleanUp() override;
175
176 // Global state must be initialized on the IO thread, then this
177 // method must be invoked on the UI thread.
178 void InitSystemRequestContext();
179
180 // Lazy initialization of system request context for
181 // SystemURLRequestContextGetter. To be called on IO thread only
182 // after global state has been initialized on the IO thread, and
183 // SystemRequestContext state has been initialized on the UI thread.
184 void InitSystemRequestContextOnIOThread();
185
186 void CreateDefaultAuthHandlerFactory();
187
188 // Returns an SSLConfigService instance.
189 net::SSLConfigService* GetSSLConfigService();
190
191 void ChangedToOnTheRecordOnIOThread();
192
193 static net::URLRequestContext* ConstructSystemRequestContext(
194 Globals* globals,
195 const net::HttpNetworkSession::Params& params,
196 net::NetLog* net_log);
197
198 // The NetLog is owned by the application context, to allow logging from other
199 // threads during shutdown, but is used most frequently on the IO thread.
200 net_log::ChromeNetLog* net_log_;
201
202 // These member variables are basically global, but their lifetimes are tied
203 // to the IOThread. IOThread owns them all, despite not using
204 // scoped_ptr. This is because the destructor of IOThread runs on the
205 // wrong thread. All member variables should be deleted in CleanUp().
206
207 // These member variables are initialized in Init() and do not change for the
208 // lifetime of the IO thread.
209
210 Globals* globals_;
211
212 net::HttpNetworkSession::Params params_;
213
214 // Observer that logs network changes to the ChromeNetLog.
215 class LoggingNetworkChangeObserver;
216 std::unique_ptr<LoggingNetworkChangeObserver> network_change_observer_;
217
218 // This is an instance of the default SSLConfigServiceManager for the current
219 // platform and it gets SSL preferences from local_state object.
220 std::unique_ptr<ssl_config::SSLConfigServiceManager>
221 ssl_config_service_manager_;
222
223 // These member variables are initialized by a task posted to the IO thread,
224 // which gets posted by calling certain member functions of IOThread.
225 std::unique_ptr<net::ProxyConfigService> system_proxy_config_service_;
226
227 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
228
229 scoped_refptr<SystemURLRequestContextGetter>
230 system_url_request_context_getter_;
231
232 const base::TimeTicks creation_time_;
233
234 base::WeakPtrFactory<IOThread> weak_factory_;
235
236 DISALLOW_COPY_AND_ASSIGN(IOThread);
237 };
238
239 } // namespace io_thread
240
241 #endif // IOS_COMPONENTS_IO_THREAD_IO_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698