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

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

Issue 2908613002: Move common functionality of IOSChromeIOThread to ios/components. (Closed)
Patch Set: Respond to comments. Created 3 years, 6 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 2017 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_COMPONENTS_IO_THREAD_IOS_IO_THREAD_H_
6 #define IOS_CHROME_BROWSER_IOS_CHROME_IO_THREAD_H_ 6 #define IOS_COMPONENTS_IO_THREAD_IOS_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/time/time.h" 21 #include "base/time/time.h"
22 #include "components/prefs/pref_member.h" 22 #include "components/prefs/pref_member.h"
23 #include "components/ssl_config/ssl_config_service_manager.h" 23 #include "components/ssl_config/ssl_config_service_manager.h"
24 #include "ios/web/public/web_thread_delegate.h" 24 #include "ios/web/public/web_thread_delegate.h"
25 #include "net/base/network_change_notifier.h" 25 #include "net/base/network_change_notifier.h"
26 #include "net/http/http_network_session.h" 26 #include "net/http/http_network_session.h"
27 27
28 class PrefProxyConfigTracker; 28 class PrefProxyConfigTracker;
29 class PrefService; 29 class PrefService;
30 class SystemURLRequestContextGetter;
31 30
32 namespace net { 31 namespace net {
33 class CTPolicyEnforcer; 32 class CTPolicyEnforcer;
34 class CertVerifier; 33 class CertVerifier;
35 class ChannelIDService; 34 class ChannelIDService;
36 class CookieStore; 35 class CookieStore;
37 class CTVerifier; 36 class CTVerifier;
38 class HostResolver; 37 class HostResolver;
39 class HttpAuthHandlerFactory; 38 class HttpAuthHandlerFactory;
40 class HttpAuthPreferences; 39 class HttpAuthPreferences;
41 class HttpServerProperties; 40 class HttpServerProperties;
42 class HttpTransactionFactory; 41 class HttpTransactionFactory;
43 class HttpUserAgentSettings; 42 class HttpUserAgentSettings;
44 class NetworkDelegate; 43 class NetworkDelegate;
45 class NetworkQualityEstimator; 44 class NetworkQualityEstimator;
46 class ProxyConfigService; 45 class ProxyConfigService;
47 class ProxyService; 46 class ProxyService;
48 class SSLConfigService; 47 class SSLConfigService;
49 class TransportSecurityState; 48 class TransportSecurityState;
50 class URLRequestContext; 49 class URLRequestContext;
51 class URLRequestContextGetter; 50 class URLRequestContextGetter;
52 class URLRequestJobFactory; 51 class URLRequestJobFactory;
53 } // namespace net 52 } // namespace net
54 53
55 namespace net_log { 54 namespace net_log {
56 class ChromeNetLog; 55 class ChromeNetLog;
57 } // namespace net_log 56 } // namespace net_log
58 57
58 namespace io_thread {
59
59 class SystemURLRequestContextGetter; 60 class SystemURLRequestContextGetter;
60 61
61 // Contains state associated with, initialized and cleaned up on, and 62 // Contains state associated with, initialized and cleaned up on, and
62 // primarily used on, the IO thread. 63 // primarily used on, the IO thread.
63 // 64 //
64 // If you are looking to interact with the IO thread (e.g. post tasks 65 // If you are looking to interact with the IO thread (e.g. post tasks
65 // to it or check if it is the current thread), see web::WebThread. 66 // to it or check if it is the current thread), see web::WebThread.
66 class IOSChromeIOThread : public web::WebThreadDelegate { 67 class IOSIOThread : public web::WebThreadDelegate {
67 public: 68 public:
68 struct Globals { 69 struct Globals {
69 template <typename T> 70 template <typename T>
70 class Optional { 71 class Optional {
71 public: 72 public:
72 Optional() : set_(false) {} 73 Optional() : set_(false) {}
73 74
74 void set(T value) { 75 void set(T value) {
75 set_ = true; 76 set_ = true;
76 value_ = value; 77 value_ = value;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 system_http_transaction_factory; 121 system_http_transaction_factory;
121 std::unique_ptr<net::URLRequestJobFactory> system_url_request_job_factory; 122 std::unique_ptr<net::URLRequestJobFactory> system_url_request_job_factory;
122 std::unique_ptr<net::URLRequestContext> system_request_context; 123 std::unique_ptr<net::URLRequestContext> system_request_context;
123 SystemRequestContextLeakChecker system_request_context_leak_checker; 124 SystemRequestContextLeakChecker system_request_context_leak_checker;
124 std::unique_ptr<net::CookieStore> system_cookie_store; 125 std::unique_ptr<net::CookieStore> system_cookie_store;
125 std::unique_ptr<net::HttpUserAgentSettings> http_user_agent_settings; 126 std::unique_ptr<net::HttpUserAgentSettings> http_user_agent_settings;
126 std::unique_ptr<net::NetworkQualityEstimator> network_quality_estimator; 127 std::unique_ptr<net::NetworkQualityEstimator> network_quality_estimator;
127 std::unique_ptr<net::CTPolicyEnforcer> ct_policy_enforcer; 128 std::unique_ptr<net::CTPolicyEnforcer> ct_policy_enforcer;
128 }; 129 };
129 130
130 // |net_log| must either outlive the IOSChromeIOThread or be NULL. 131 // |net_log| must either outlive the IOSIOThread or be NULL.
131 IOSChromeIOThread(PrefService* local_state, net_log::ChromeNetLog* net_log); 132 IOSIOThread(PrefService* local_state, net_log::ChromeNetLog* net_log);
132 133 ~IOSIOThread() override;
133 ~IOSChromeIOThread() override;
134 134
135 // Can only be called on the IO thread. 135 // Can only be called on the IO thread.
136 Globals* globals(); 136 Globals* globals();
137 137
138 // Allows overriding Globals in tests where IOSChromeIOThread::Init() and 138 // Allows overriding Globals in tests where IOSIOThread::Init() and
139 // IOSChromeIOThread::CleanUp() are not called. This allows for injecting 139 // IOSIOThread::CleanUp() are not called. This allows for injecting mocks
140 // mocks into IOSChromeIOThread global objects. 140 // into IOSIOThread global objects.
141 void SetGlobalsForTesting(Globals* globals); 141 void SetGlobalsForTesting(Globals* globals);
142 142
143 net_log::ChromeNetLog* net_log(); 143 net_log::ChromeNetLog* net_log();
144 144
145 // Handles changing to On The Record mode, discarding confidential data. 145 // Handles changing to On The Record mode, discarding confidential data.
146 void ChangedToOnTheRecord(); 146 void ChangedToOnTheRecord();
147 147
148 // Returns a getter for the URLRequestContext. Only called on the UI thread. 148 // Returns a getter for the URLRequestContext. Only called on the UI thread.
149 net::URLRequestContextGetter* system_url_request_context_getter(); 149 net::URLRequestContextGetter* system_url_request_context_getter();
150 150
151 // Clears the host cache. Intended to be used to prevent exposing recently 151 // Clears the host cache. Intended to be used to prevent exposing recently
152 // visited sites on about:net-internals/#dns and about:dns pages. Must be 152 // visited sites on about:net-internals/#dns and about:dns pages. Must be
153 // called on the IO thread. 153 // called on the IO thread.
154 void ClearHostCache(); 154 void ClearHostCache();
155 155
156 const net::HttpNetworkSession::Params& NetworkSessionParams() const; 156 const net::HttpNetworkSession::Params& NetworkSessionParams() const;
157 157
158 base::TimeTicks creation_time() const; 158 base::TimeTicks creation_time() const;
159 159
160 protected:
161 // A string describing the current application version. For example: "stable"
162 // or "dev". An empty string is an acceptable value. This string is used to
163 // build the user agent id for QUIC.
164 virtual std::string GetChannelString() const = 0;
165
166 // Subclasses should return a NetworkDelegate to be used for
sdefresne 2017/05/29 09:30:40 should → must
michaeldo 2017/05/30 17:16:24 Done.
167 // BrowserState-agnostic network events.
168 virtual std::unique_ptr<net::NetworkDelegate> GetSystemNetworkDelegate() = 0;
sdefresne 2017/05/29 09:30:41 This is a factory method, so maybe rename it "Crea
michaeldo 2017/05/30 17:16:24 Done.
169
160 private: 170 private:
161 // Provide SystemURLRequestContextGetter with access to 171 // Provide SystemURLRequestContextGetter with access to
162 // InitSystemRequestContext(). 172 // InitSystemRequestContext().
163 friend class SystemURLRequestContextGetter; 173 friend class SystemURLRequestContextGetter;
164 174
165 // WebThreadDelegate implementation, runs on the IO thread. 175 // WebThreadDelegate implementation, runs on the IO thread.
166 // This handles initialization and destruction of state that must 176 // This handles initialization and destruction of state that must
167 // live on the IO thread. 177 // live on the IO thread.
168 void Init() override; 178 void Init() override;
169 void CleanUp() override; 179 void CleanUp() override;
170 180
171 // Global state must be initialized on the IO thread, then this 181 // Global state must be initialized on the IO thread, then this
172 // method must be invoked on the UI thread. 182 // method must be invoked on the UI thread.
173 void InitSystemRequestContext(); 183 void InitSystemRequestContext();
174 184
175 // Lazy initialization of system request context for 185 // Lazy initialization of system request context for
176 // SystemURLRequestContextGetter. To be called on IO thread only 186 // SystemURLRequestContextGetter. To be called on IO thread only
177 // after global state has been initialized on the IO thread, and 187 // after global state has been initialized on the IO thread, and
178 // SystemRequestContext state has been initialized on the UI thread. 188 // SystemRequestContext state has been initialized on the UI thread.
179 void InitSystemRequestContextOnIOThread(); 189 void InitSystemRequestContextOnIOThread();
180 190
191 // Set up HttpAuthPreferences and HttpAuthHandlerFactory on Globals.
sdefresne 2017/05/29 09:30:41 Set → Sets
michaeldo 2017/05/30 17:16:24 Done.
181 void CreateDefaultAuthHandlerFactory(); 192 void CreateDefaultAuthHandlerFactory();
182 193
183 // Returns an SSLConfigService instance. 194 // Returns an SSLConfigService instance.
184 net::SSLConfigService* GetSSLConfigService(); 195 net::SSLConfigService* GetSSLConfigService();
185 196
197 // Discards confidental data. To be called on IO thread only.
186 void ChangedToOnTheRecordOnIOThread(); 198 void ChangedToOnTheRecordOnIOThread();
187 199
188 static net::URLRequestContext* ConstructSystemRequestContext( 200 static net::URLRequestContext* ConstructSystemRequestContext(
189 Globals* globals, 201 Globals* globals,
190 const net::HttpNetworkSession::Params& params, 202 const net::HttpNetworkSession::Params& params,
191 net::NetLog* net_log); 203 net::NetLog* net_log);
192 204
193 // The NetLog is owned by the application context, to allow logging from other 205 // The NetLog is owned by the application context, to allow logging from other
194 // threads during shutdown, but is used most frequently on the IO thread. 206 // threads during shutdown, but is used most frequently on the IO thread.
195 net_log::ChromeNetLog* net_log_; 207 net_log::ChromeNetLog* net_log_;
196 208
197 // These member variables are basically global, but their lifetimes are tied 209 // These member variables are basically global, but their lifetimes are tied
198 // to the IOSChromeIOThread. IOSChromeIOThread owns them all, despite not 210 // to the IOSIOThread. IOSIOThread owns them all, despite not using
199 // using scoped_ptr. This is because the destructor of IOSChromeIOThread runs 211 // scoped_ptr. This is because the destructor of IOSIOThread runs on the
200 // on the wrong thread. All member variables should be deleted in CleanUp(). 212 // wrong thread. All member variables should be deleted in CleanUp().
201 213
202 // These member variables are initialized in Init() and do not change for the 214 // These member variables are initialized in Init() and do not change for the
203 // lifetime of the IO thread. 215 // lifetime of the IO thread.
204 216
205 Globals* globals_; 217 Globals* globals_;
206 218
207 net::HttpNetworkSession::Params params_; 219 net::HttpNetworkSession::Params params_;
208 220
209 // Observer that logs network changes to the ChromeNetLog. 221 // Observer that logs network changes to the ChromeNetLog.
210 class LoggingNetworkChangeObserver; 222 class LoggingNetworkChangeObserver;
211 std::unique_ptr<LoggingNetworkChangeObserver> network_change_observer_; 223 std::unique_ptr<LoggingNetworkChangeObserver> network_change_observer_;
212 224
213 // This is an instance of the default SSLConfigServiceManager for the current 225 // This is an instance of the default SSLConfigServiceManager for the current
214 // platform and it gets SSL preferences from local_state object. 226 // platform and it gets SSL preferences from local_state object.
215 std::unique_ptr<ssl_config::SSLConfigServiceManager> 227 std::unique_ptr<ssl_config::SSLConfigServiceManager>
216 ssl_config_service_manager_; 228 ssl_config_service_manager_;
217 229
218 // These member variables are initialized by a task posted to the IO thread, 230 // These member variables are initialized by a task posted to the IO thread,
219 // which gets posted by calling certain member functions of IOSChromeIOThread. 231 // which gets posted by calling certain member functions of IOSIOThread.
220 std::unique_ptr<net::ProxyConfigService> system_proxy_config_service_; 232 std::unique_ptr<net::ProxyConfigService> system_proxy_config_service_;
221 233
222 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; 234 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
223 235
224 scoped_refptr<SystemURLRequestContextGetter> 236 scoped_refptr<SystemURLRequestContextGetter>
225 system_url_request_context_getter_; 237 system_url_request_context_getter_;
226 238
227 const base::TimeTicks creation_time_; 239 const base::TimeTicks creation_time_;
228 240
229 base::WeakPtrFactory<IOSChromeIOThread> weak_factory_; 241 base::WeakPtrFactory<IOSIOThread> weak_factory_;
230 242
231 DISALLOW_COPY_AND_ASSIGN(IOSChromeIOThread); 243 DISALLOW_COPY_AND_ASSIGN(IOSIOThread);
232 }; 244 };
233 245
234 #endif // IOS_CHROME_BROWSER_IOS_CHROME_IO_THREAD_H_ 246 } // namespace io_thread
247
248 #endif // IOS_COMPONENTS_IO_THREAD_IO_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698