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

Side by Side Diff: ios/web_view/internal/app/web_view_io_thread.h

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

Powered by Google App Engine
This is Rietveld 408576698