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/io_thread.h

Issue 2908613002: Move common functionality of IOSChromeIOThread to ios/components. (Closed)
Patch Set: Remove bug todo. 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_IO_THREAD_H_
6 #define IOS_CHROME_BROWSER_IOS_CHROME_IO_THREAD_H_ 6 #define IOS_COMPONENTS_IO_THREAD_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 IOThread : public web::WebThreadDelegate {
Eugene But (OOO till 7-30) 2017/05/25 22:05:22 Should this be IOSIOThread?
michaeldo 2017/05/26 07:24:43 I think IOSIOThread makes sense. Updated.
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 IOThread or be NULL.
131 IOSChromeIOThread(PrefService* local_state, net_log::ChromeNetLog* net_log); 132 IOThread(PrefService* local_state, net_log::ChromeNetLog* net_log);
132 133 ~IOThread() 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 IOThread::Init() and
139 // IOSChromeIOThread::CleanUp() are not called. This allows for injecting 139 // IOThread::CleanUp() are not called. This allows for injecting mocks into
140 // mocks into IOSChromeIOThread global objects. 140 // IOThread 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 std::string GetChannelString();
Eugene But (OOO till 7-30) 2017/05/25 22:05:21 Should this be virtual and const? Otherwise subcla
michaeldo 2017/05/26 07:24:43 Done.
162
163 virtual std::unique_ptr<net::NetworkDelegate> GetSystemNetworkDelegate() = 0;
164
160 private: 165 private:
161 // Provide SystemURLRequestContextGetter with access to 166 // Provide SystemURLRequestContextGetter with access to
162 // InitSystemRequestContext(). 167 // InitSystemRequestContext().
163 friend class SystemURLRequestContextGetter; 168 friend class SystemURLRequestContextGetter;
164 169
165 // WebThreadDelegate implementation, runs on the IO thread. 170 // WebThreadDelegate implementation, runs on the IO thread.
166 // This handles initialization and destruction of state that must 171 // This handles initialization and destruction of state that must
167 // live on the IO thread. 172 // live on the IO thread.
168 void Init() override; 173 void Init() override;
169 void CleanUp() override; 174 void CleanUp() override;
(...skipping 18 matching lines...) Expand all
188 static net::URLRequestContext* ConstructSystemRequestContext( 193 static net::URLRequestContext* ConstructSystemRequestContext(
189 Globals* globals, 194 Globals* globals,
190 const net::HttpNetworkSession::Params& params, 195 const net::HttpNetworkSession::Params& params,
191 net::NetLog* net_log); 196 net::NetLog* net_log);
192 197
193 // The NetLog is owned by the application context, to allow logging from other 198 // 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. 199 // threads during shutdown, but is used most frequently on the IO thread.
195 net_log::ChromeNetLog* net_log_; 200 net_log::ChromeNetLog* net_log_;
196 201
197 // These member variables are basically global, but their lifetimes are tied 202 // These member variables are basically global, but their lifetimes are tied
198 // to the IOSChromeIOThread. IOSChromeIOThread owns them all, despite not 203 // to the IOThread. IOThread owns them all, despite not using
199 // using scoped_ptr. This is because the destructor of IOSChromeIOThread runs 204 // scoped_ptr. This is because the destructor of IOThread runs on the
200 // on the wrong thread. All member variables should be deleted in CleanUp(). 205 // wrong thread. All member variables should be deleted in CleanUp().
201 206
202 // These member variables are initialized in Init() and do not change for the 207 // These member variables are initialized in Init() and do not change for the
203 // lifetime of the IO thread. 208 // lifetime of the IO thread.
204 209
205 Globals* globals_; 210 Globals* globals_;
206 211
207 net::HttpNetworkSession::Params params_; 212 net::HttpNetworkSession::Params params_;
208 213
209 // Observer that logs network changes to the ChromeNetLog. 214 // Observer that logs network changes to the ChromeNetLog.
210 class LoggingNetworkChangeObserver; 215 class LoggingNetworkChangeObserver;
211 std::unique_ptr<LoggingNetworkChangeObserver> network_change_observer_; 216 std::unique_ptr<LoggingNetworkChangeObserver> network_change_observer_;
212 217
213 // This is an instance of the default SSLConfigServiceManager for the current 218 // This is an instance of the default SSLConfigServiceManager for the current
214 // platform and it gets SSL preferences from local_state object. 219 // platform and it gets SSL preferences from local_state object.
215 std::unique_ptr<ssl_config::SSLConfigServiceManager> 220 std::unique_ptr<ssl_config::SSLConfigServiceManager>
216 ssl_config_service_manager_; 221 ssl_config_service_manager_;
217 222
218 // These member variables are initialized by a task posted to the IO thread, 223 // These member variables are initialized by a task posted to the IO thread,
219 // which gets posted by calling certain member functions of IOSChromeIOThread. 224 // which gets posted by calling certain member functions of IOThread.
220 std::unique_ptr<net::ProxyConfigService> system_proxy_config_service_; 225 std::unique_ptr<net::ProxyConfigService> system_proxy_config_service_;
221 226
222 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; 227 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_;
223 228
224 scoped_refptr<SystemURLRequestContextGetter> 229 scoped_refptr<SystemURLRequestContextGetter>
225 system_url_request_context_getter_; 230 system_url_request_context_getter_;
226 231
227 const base::TimeTicks creation_time_; 232 const base::TimeTicks creation_time_;
228 233
229 base::WeakPtrFactory<IOSChromeIOThread> weak_factory_; 234 base::WeakPtrFactory<IOThread> weak_factory_;
230 235
231 DISALLOW_COPY_AND_ASSIGN(IOSChromeIOThread); 236 DISALLOW_COPY_AND_ASSIGN(IOThread);
232 }; 237 };
233 238
234 #endif // IOS_CHROME_BROWSER_IOS_CHROME_IO_THREAD_H_ 239 } // namespace io_thread
240
241 #endif // IOS_COMPONENTS_IO_THREAD_IO_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698