OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/io_thread.h" | 5 #include "chrome/browser/io_thread.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/leak_tracker.h" | 10 #include "base/debug/leak_tracker.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/metrics/field_trial.h" | 12 #include "base/metrics/field_trial.h" |
13 #include "base/stl_util-inl.h" | 13 #include "base/stl_util-inl.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/string_split.h" | 15 #include "base/string_split.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
18 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/extensions/extension_event_router_forwarder.h" | |
20 #include "chrome/browser/net/chrome_network_delegate.h" | |
19 #include "chrome/browser/net/chrome_net_log.h" | 21 #include "chrome/browser/net/chrome_net_log.h" |
20 #include "chrome/browser/net/chrome_url_request_context.h" | 22 #include "chrome/browser/net/chrome_url_request_context.h" |
21 #include "chrome/browser/net/connect_interceptor.h" | 23 #include "chrome/browser/net/connect_interceptor.h" |
22 #include "chrome/browser/net/passive_log_collector.h" | 24 #include "chrome/browser/net/passive_log_collector.h" |
23 #include "chrome/browser/net/predictor_api.h" | 25 #include "chrome/browser/net/predictor_api.h" |
24 #include "chrome/browser/prefs/pref_service.h" | 26 #include "chrome/browser/prefs/pref_service.h" |
25 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/net/raw_host_resolver_proc.h" | 28 #include "chrome/common/net/raw_host_resolver_proc.h" |
27 #include "chrome/common/net/url_fetcher.h" | 29 #include "chrome/common/net/url_fetcher.h" |
28 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
29 #include "content/browser/browser_thread.h" | 31 #include "content/browser/browser_thread.h" |
30 #include "content/browser/gpu_process_host.h" | 32 #include "content/browser/gpu_process_host.h" |
31 #include "content/browser/in_process_webkit/indexed_db_key_utility_client.h" | 33 #include "content/browser/in_process_webkit/indexed_db_key_utility_client.h" |
32 #include "net/base/cert_verifier.h" | 34 #include "net/base/cert_verifier.h" |
33 #include "net/base/cookie_monster.h" | 35 #include "net/base/cookie_monster.h" |
34 #include "net/base/dnsrr_resolver.h" | 36 #include "net/base/dnsrr_resolver.h" |
35 #include "net/base/host_cache.h" | 37 #include "net/base/host_cache.h" |
36 #include "net/base/host_resolver.h" | 38 #include "net/base/host_resolver.h" |
37 #include "net/base/host_resolver_impl.h" | 39 #include "net/base/host_resolver_impl.h" |
38 #include "net/base/mapped_host_resolver.h" | 40 #include "net/base/mapped_host_resolver.h" |
39 #include "net/base/net_util.h" | 41 #include "net/base/net_util.h" |
40 #include "net/base/network_delegate.h" | |
41 #include "net/http/http_auth_filter.h" | 42 #include "net/http/http_auth_filter.h" |
42 #include "net/http/http_auth_handler_factory.h" | 43 #include "net/http/http_auth_handler_factory.h" |
43 #include "net/http/http_network_layer.h" | 44 #include "net/http/http_network_layer.h" |
44 #include "net/http/http_network_session.h" | 45 #include "net/http/http_network_session.h" |
45 #if defined(USE_NSS) | 46 #if defined(USE_NSS) |
46 #include "net/ocsp/nss_ocsp.h" | 47 #include "net/ocsp/nss_ocsp.h" |
47 #endif // defined(USE_NSS) | 48 #endif // defined(USE_NSS) |
48 #include "net/proxy/proxy_script_fetcher_impl.h" | 49 #include "net/proxy/proxy_script_fetcher_impl.h" |
49 | 50 |
50 namespace { | 51 namespace { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 net::NetLog::Source(), | 173 net::NetLog::Source(), |
173 net::NetLog::PHASE_NONE, | 174 net::NetLog::PHASE_NONE, |
174 NULL); | 175 NULL); |
175 } | 176 } |
176 | 177 |
177 private: | 178 private: |
178 net::NetLog* net_log_; | 179 net::NetLog* net_log_; |
179 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); | 180 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); |
180 }; | 181 }; |
181 | 182 |
182 class SystemNetworkDelegate : public net::NetworkDelegate { | |
Matt Perry
2011/02/25 23:28:40
I think Will had other plans for this beyond makin
willchan no longer on Chromium
2011/02/26 02:11:35
I actually forgot to mention this to jochen when h
| |
183 public: | |
184 SystemNetworkDelegate() {} | |
185 ~SystemNetworkDelegate() {} | |
186 | |
187 // NetworkDelegate methods: | |
188 // TODO(willchan): Implement these functions! | |
189 virtual void OnBeforeURLRequest(net::URLRequest* request) {} | |
190 virtual void OnSendHttpRequest(net::HttpRequestHeaders* headers) {} | |
191 virtual void OnResponseStarted(net::URLRequest* request) {} | |
192 virtual void OnReadCompleted(net::URLRequest* request, int bytes_read) {} | |
193 | |
194 private: | |
195 DISALLOW_COPY_AND_ASSIGN(SystemNetworkDelegate); | |
196 }; | |
197 | |
198 scoped_refptr<net::URLRequestContext> | 183 scoped_refptr<net::URLRequestContext> |
199 ConstructProxyScriptFetcherContext(IOThread::Globals* globals, | 184 ConstructProxyScriptFetcherContext(IOThread::Globals* globals, |
200 net::NetLog* net_log) { | 185 net::NetLog* net_log) { |
201 scoped_refptr<net::URLRequestContext> context(new net::URLRequestContext); | 186 scoped_refptr<net::URLRequestContext> context(new net::URLRequestContext); |
202 context->set_net_log(net_log); | 187 context->set_net_log(net_log); |
203 context->set_host_resolver(globals->host_resolver.get()); | 188 context->set_host_resolver(globals->host_resolver.get()); |
204 context->set_cert_verifier(globals->cert_verifier.get()); | 189 context->set_cert_verifier(globals->cert_verifier.get()); |
205 context->set_dnsrr_resolver(globals->dnsrr_resolver.get()); | 190 context->set_dnsrr_resolver(globals->dnsrr_resolver.get()); |
206 context->set_http_auth_handler_factory( | 191 context->set_http_auth_handler_factory( |
207 globals->http_auth_handler_factory.get()); | 192 globals->http_auth_handler_factory.get()); |
208 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); | 193 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); |
209 context->set_http_transaction_factory( | 194 context->set_http_transaction_factory( |
210 globals->proxy_script_fetcher_http_transaction_factory.get()); | 195 globals->proxy_script_fetcher_http_transaction_factory.get()); |
211 // In-memory cookie store. | 196 // In-memory cookie store. |
212 context->set_cookie_store(new net::CookieMonster(NULL, NULL)); | 197 context->set_cookie_store(new net::CookieMonster(NULL, NULL)); |
213 // TODO(mpcomplete): give it a SystemNetworkDelegate. | 198 context->set_network_delegate(globals->system_network_delegate.get()); |
214 return context; | 199 return context; |
215 } | 200 } |
216 | 201 |
217 } // namespace | 202 } // namespace |
218 | 203 |
219 // The IOThread object must outlive any tasks posted to the IO thread before the | 204 // The IOThread object must outlive any tasks posted to the IO thread before the |
220 // Quit task. | 205 // Quit task. |
221 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); | 206 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); |
222 | 207 |
223 IOThread::Globals::Globals() {} | 208 IOThread::Globals::Globals() {} |
224 | 209 |
225 IOThread::Globals::~Globals() {} | 210 IOThread::Globals::~Globals() {} |
226 | 211 |
227 // |local_state| is passed in explicitly in order to (1) reduce implicit | 212 // |local_state| is passed in explicitly in order to (1) reduce implicit |
228 // dependencies and (2) make IOThread more flexible for testing. | 213 // dependencies and (2) make IOThread more flexible for testing. |
229 IOThread::IOThread(PrefService* local_state, ChromeNetLog* net_log) | 214 IOThread::IOThread( |
215 PrefService* local_state, | |
216 ChromeNetLog* net_log, | |
217 ExtensionEventRouterForwarder* extension_event_router_forwarder) | |
230 : BrowserProcessSubThread(BrowserThread::IO), | 218 : BrowserProcessSubThread(BrowserThread::IO), |
231 net_log_(net_log), | 219 net_log_(net_log), |
220 extension_event_router_forwarder_(extension_event_router_forwarder), | |
232 globals_(NULL), | 221 globals_(NULL), |
233 speculative_interceptor_(NULL), | 222 speculative_interceptor_(NULL), |
234 predictor_(NULL) { | 223 predictor_(NULL) { |
235 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make | 224 // We call RegisterPrefs() here (instead of inside browser_prefs.cc) to make |
236 // sure that everything is initialized in the right order. | 225 // sure that everything is initialized in the right order. |
237 RegisterPrefs(local_state); | 226 RegisterPrefs(local_state); |
238 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); | 227 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); |
239 negotiate_disable_cname_lookup_ = local_state->GetBoolean( | 228 negotiate_disable_cname_lookup_ = local_state->GetBoolean( |
240 prefs::kDisableAuthNegotiateCnameLookup); | 229 prefs::kDisableAuthNegotiateCnameLookup); |
241 negotiate_enable_port_ = local_state->GetBoolean( | 230 negotiate_enable_port_ = local_state->GetBoolean( |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 | 326 |
338 DCHECK(!globals_); | 327 DCHECK(!globals_); |
339 globals_ = new Globals; | 328 globals_ = new Globals; |
340 | 329 |
341 // Add an observer that will emit network change events to the ChromeNetLog. | 330 // Add an observer that will emit network change events to the ChromeNetLog. |
342 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be | 331 // Assuming NetworkChangeNotifier dispatches in FIFO order, we should be |
343 // logging the network change before other IO thread consumers respond to it. | 332 // logging the network change before other IO thread consumers respond to it. |
344 network_change_observer_.reset( | 333 network_change_observer_.reset( |
345 new LoggingNetworkChangeObserver(net_log_)); | 334 new LoggingNetworkChangeObserver(net_log_)); |
346 | 335 |
347 globals_->system_network_delegate.reset(new SystemNetworkDelegate); | 336 globals_->extension_event_router_forwarder = |
337 extension_event_router_forwarder_; | |
338 globals_->system_network_delegate.reset(new ChromeNetworkDelegate( | |
339 extension_event_router_forwarder_, NULL)); | |
348 globals_->host_resolver.reset( | 340 globals_->host_resolver.reset( |
349 CreateGlobalHostResolver(net_log_)); | 341 CreateGlobalHostResolver(net_log_)); |
350 globals_->cert_verifier.reset(new net::CertVerifier); | 342 globals_->cert_verifier.reset(new net::CertVerifier); |
351 globals_->dnsrr_resolver.reset(new net::DnsRRResolver); | 343 globals_->dnsrr_resolver.reset(new net::DnsRRResolver); |
352 // TODO(willchan): Use the real SSLConfigService. | 344 // TODO(willchan): Use the real SSLConfigService. |
353 globals_->ssl_config_service = | 345 globals_->ssl_config_service = |
354 net::SSLConfigService::CreateSystemSSLConfigService(); | 346 net::SSLConfigService::CreateSystemSSLConfigService(); |
355 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( | 347 globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( |
356 globals_->host_resolver.get())); | 348 globals_->host_resolver.get())); |
357 // For the ProxyScriptFetcher, we use a direct ProxyService. | 349 // For the ProxyScriptFetcher, we use a direct ProxyService. |
358 globals_->proxy_script_fetcher_proxy_service = | 350 globals_->proxy_script_fetcher_proxy_service = |
359 net::ProxyService::CreateDirectWithNetLog(net_log_); | 351 net::ProxyService::CreateDirectWithNetLog(net_log_); |
360 net::HttpNetworkSession::Params session_params; | 352 net::HttpNetworkSession::Params session_params; |
361 session_params.host_resolver = globals_->host_resolver.get(); | 353 session_params.host_resolver = globals_->host_resolver.get(); |
362 session_params.cert_verifier = globals_->cert_verifier.get(); | 354 session_params.cert_verifier = globals_->cert_verifier.get(); |
363 session_params.proxy_service = | 355 session_params.proxy_service = |
364 globals_->proxy_script_fetcher_proxy_service.get(); | 356 globals_->proxy_script_fetcher_proxy_service.get(); |
365 session_params.http_auth_handler_factory = | 357 session_params.http_auth_handler_factory = |
366 globals_->http_auth_handler_factory.get(); | 358 globals_->http_auth_handler_factory.get(); |
367 // TODO(willchan): Enable for proxy script fetcher context. | |
368 session_params.network_delegate = globals_->system_network_delegate.get(); | 359 session_params.network_delegate = globals_->system_network_delegate.get(); |
369 session_params.net_log = net_log_; | 360 session_params.net_log = net_log_; |
370 session_params.ssl_config_service = globals_->ssl_config_service; | 361 session_params.ssl_config_service = globals_->ssl_config_service; |
371 scoped_refptr<net::HttpNetworkSession> network_session( | 362 scoped_refptr<net::HttpNetworkSession> network_session( |
372 new net::HttpNetworkSession(session_params)); | 363 new net::HttpNetworkSession(session_params)); |
373 globals_->proxy_script_fetcher_http_transaction_factory.reset( | 364 globals_->proxy_script_fetcher_http_transaction_factory.reset( |
374 new net::HttpNetworkLayer(network_session)); | 365 new net::HttpNetworkLayer(network_session)); |
375 | 366 |
376 scoped_refptr<net::URLRequestContext> proxy_script_fetcher_context = | 367 scoped_refptr<net::URLRequestContext> proxy_script_fetcher_context = |
377 ConstructProxyScriptFetcherContext(globals_, net_log_); | 368 ConstructProxyScriptFetcherContext(globals_, net_log_); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 void IOThread::ClearHostCache() { | 533 void IOThread::ClearHostCache() { |
543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
544 | 535 |
545 if (globals_->host_resolver->GetAsHostResolverImpl()) { | 536 if (globals_->host_resolver->GetAsHostResolverImpl()) { |
546 net::HostCache* host_cache = | 537 net::HostCache* host_cache = |
547 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); | 538 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); |
548 if (host_cache) | 539 if (host_cache) |
549 host_cache->clear(); | 540 host_cache->clear(); |
550 } | 541 } |
551 } | 542 } |
OLD | NEW |