Chromium Code Reviews| 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_thread.h" | 19 #include "chrome/browser/browser_thread.h" |
| 20 #if defined(OS_CHROMEOS) | |
| 21 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | |
| 22 #endif // defined(OS_CHROMEOS) | |
| 19 #include "chrome/browser/gpu_process_host.h" | 23 #include "chrome/browser/gpu_process_host.h" |
| 20 #include "chrome/browser/in_process_webkit/indexed_db_key_utility_client.h" | 24 #include "chrome/browser/in_process_webkit/indexed_db_key_utility_client.h" |
| 21 #include "chrome/browser/net/chrome_net_log.h" | 25 #include "chrome/browser/net/chrome_net_log.h" |
| 22 #include "chrome/browser/net/chrome_url_request_context.h" | 26 #include "chrome/browser/net/chrome_url_request_context.h" |
| 23 #include "chrome/browser/net/connect_interceptor.h" | 27 #include "chrome/browser/net/connect_interceptor.h" |
| 24 #include "chrome/browser/net/passive_log_collector.h" | 28 #include "chrome/browser/net/passive_log_collector.h" |
| 25 #include "chrome/browser/net/predictor_api.h" | 29 #include "chrome/browser/net/predictor_api.h" |
| 30 #include "chrome/browser/net/pref_proxy_config_service.h" | |
| 26 #include "chrome/browser/prefs/pref_service.h" | 31 #include "chrome/browser/prefs/pref_service.h" |
| 27 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/net/raw_host_resolver_proc.h" | 33 #include "chrome/common/net/raw_host_resolver_proc.h" |
| 29 #include "chrome/common/net/url_fetcher.h" | 34 #include "chrome/common/net/url_fetcher.h" |
| 30 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 31 #include "net/base/cert_verifier.h" | 36 #include "net/base/cert_verifier.h" |
| 32 #include "net/base/dnsrr_resolver.h" | 37 #include "net/base/dnsrr_resolver.h" |
| 33 #include "net/base/host_cache.h" | 38 #include "net/base/host_cache.h" |
| 34 #include "net/base/host_resolver.h" | 39 #include "net/base/host_resolver.h" |
| 35 #include "net/base/host_resolver_impl.h" | 40 #include "net/base/host_resolver_impl.h" |
| 36 #include "net/base/mapped_host_resolver.h" | 41 #include "net/base/mapped_host_resolver.h" |
| 37 #include "net/base/net_util.h" | 42 #include "net/base/net_util.h" |
| 43 #include "net/proxy/proxy_config_service_fixed.h" | |
| 38 #include "net/http/http_auth_filter.h" | 44 #include "net/http/http_auth_filter.h" |
| 39 #include "net/http/http_auth_handler_factory.h" | 45 #include "net/http/http_auth_handler_factory.h" |
| 40 #include "net/http/http_network_layer.h" | 46 #include "net/http/http_network_layer.h" |
| 41 #include "net/http/http_network_session.h" | 47 #include "net/http/http_network_session.h" |
| 42 #if defined(USE_NSS) | 48 #if defined(USE_NSS) |
| 43 #include "net/ocsp/nss_ocsp.h" | 49 #include "net/ocsp/nss_ocsp.h" |
| 44 #endif // defined(USE_NSS) | 50 #endif // defined(USE_NSS) |
| 45 #include "net/proxy/proxy_script_fetcher_impl.h" | 51 #include "net/proxy/proxy_script_fetcher_impl.h" |
| 46 | 52 |
| 47 namespace { | 53 namespace { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 globals->http_auth_handler_factory.get()); | 194 globals->http_auth_handler_factory.get()); |
| 189 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); | 195 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); |
| 190 context->set_http_transaction_factory( | 196 context->set_http_transaction_factory( |
| 191 globals->proxy_script_fetcher_http_transaction_factory.get()); | 197 globals->proxy_script_fetcher_http_transaction_factory.get()); |
| 192 // In-memory cookie store. | 198 // In-memory cookie store. |
| 193 context->set_cookie_store(new net::CookieMonster(NULL, NULL)); | 199 context->set_cookie_store(new net::CookieMonster(NULL, NULL)); |
| 194 // TODO(mpcomplete): give it a SystemNetworkDelegate. | 200 // TODO(mpcomplete): give it a SystemNetworkDelegate. |
| 195 return context; | 201 return context; |
| 196 } | 202 } |
| 197 | 203 |
| 204 scoped_refptr<net::URLRequestContext> | |
| 205 ConstructSystemRequestContext(IOThread::Globals* globals, | |
| 206 net::NetLog* net_log) { | |
| 207 scoped_refptr<net::URLRequestContext> context(new net::URLRequestContext); | |
| 208 context->set_net_log(net_log); | |
| 209 context->set_host_resolver(globals->host_resolver.get()); | |
| 210 context->set_cert_verifier(globals->cert_verifier.get()); | |
| 211 context->set_dnsrr_resolver(globals->dnsrr_resolver.get()); | |
| 212 context->set_http_auth_handler_factory( | |
| 213 globals->http_auth_handler_factory.get()); | |
| 214 context->set_proxy_service(globals->system_proxy_service.get()); | |
| 215 context->set_http_transaction_factory( | |
| 216 globals->system_http_transaction_factory.get()); | |
| 217 // In-memory cookie store. | |
| 218 context->set_cookie_store(new net::CookieMonster(NULL, NULL)); | |
| 219 return context; | |
| 220 } | |
| 221 | |
| 222 class SystemURLRequestContextGetter : public URLRequestContextGetter { | |
| 223 public: | |
| 224 explicit SystemURLRequestContextGetter(IOThread * io_thread); | |
|
willchan no longer on Chromium
2011/02/15 01:05:58
We don't have spaces between types and '*', so I'd
battre
2011/02/15 19:32:49
Done.
| |
| 225 virtual ~SystemURLRequestContextGetter(); | |
| 226 | |
| 227 // Implementation for UrlRequestContextGetter. | |
| 228 virtual net::URLRequestContext* GetURLRequestContext(); | |
| 229 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const; | |
| 230 | |
| 231 private: | |
| 232 IOThread * const io_thread_; // Weak pointer, owned by BrowserProcess. | |
|
willchan no longer on Chromium
2011/02/15 01:05:58
We don't have spaces between types and '*', so I'd
battre
2011/02/15 19:32:49
Done.
| |
| 233 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | |
| 234 | |
| 235 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; | |
| 236 }; | |
| 237 | |
| 238 SystemURLRequestContextGetter::SystemURLRequestContextGetter( | |
| 239 IOThread* io_thread) | |
| 240 : io_thread_(io_thread), | |
| 241 io_message_loop_proxy_(io_thread->message_loop_proxy()) { | |
| 242 } | |
| 243 | |
| 244 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} | |
| 245 | |
| 246 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { | |
|
willchan no longer on Chromium
2011/02/15 01:05:58
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::I
battre
2011/02/15 19:32:49
Done.
| |
| 247 return io_thread_->globals()->system_request_context; | |
| 248 } | |
| 249 | |
| 250 scoped_refptr<base::MessageLoopProxy> | |
| 251 SystemURLRequestContextGetter::GetIOMessageLoopProxy() const { | |
| 252 return io_message_loop_proxy_; | |
| 253 } | |
| 254 | |
| 198 } // namespace | 255 } // namespace |
| 199 | 256 |
| 200 // The IOThread object must outlive any tasks posted to the IO thread before the | 257 // The IOThread object must outlive any tasks posted to the IO thread before the |
| 201 // Quit task. | 258 // Quit task. |
| 202 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); | 259 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); |
| 203 | 260 |
| 204 IOThread::Globals::Globals() {} | 261 IOThread::Globals::Globals() {} |
| 205 | 262 |
| 206 IOThread::Globals::~Globals() {} | 263 IOThread::Globals::~Globals() {} |
| 207 | 264 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 236 | 293 |
| 237 IOThread::Globals* IOThread::globals() { | 294 IOThread::Globals* IOThread::globals() { |
| 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 239 return globals_; | 296 return globals_; |
| 240 } | 297 } |
| 241 | 298 |
| 242 ChromeNetLog* IOThread::net_log() { | 299 ChromeNetLog* IOThread::net_log() { |
| 243 return net_log_; | 300 return net_log_; |
| 244 } | 301 } |
| 245 | 302 |
| 303 void IOThread::InitSystemRequestContext( | |
| 304 net::ProxyConfigService* config_service) { | |
| 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 306 message_loop()->PostTask( | |
| 307 FROM_HERE, | |
| 308 NewRunnableMethod( | |
| 309 this, | |
| 310 &IOThread::InitSystemRequestContextOnIOThread, | |
| 311 config_service)); | |
| 312 } | |
| 313 | |
| 314 void IOThread::InitSystemRequestContextOnIOThread( | |
| 315 net::ProxyConfigService* config_service) { | |
| 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 317 | |
| 318 size_t num_pac_threads = 0u; // Use default number of threads. | |
| 319 globals_->system_proxy_service = | |
| 320 net::ProxyService::CreateUsingSystemProxyResolver( | |
| 321 config_service, num_pac_threads, net_log_); | |
| 322 net::HttpNetworkSession::Params system_params; | |
| 323 system_params.host_resolver = globals_->host_resolver.get(); | |
| 324 system_params.cert_verifier = globals_->cert_verifier.get(); | |
| 325 system_params.dnsrr_resolver = globals_->dnsrr_resolver.get(); | |
| 326 system_params.dns_cert_checker = NULL; | |
| 327 system_params.ssl_host_info_factory = NULL; | |
| 328 system_params.proxy_service = globals_->system_proxy_service.get(); | |
| 329 system_params.ssl_config_service = globals_->ssl_config_service.get(); | |
| 330 system_params.http_auth_handler_factory = | |
| 331 globals_->http_auth_handler_factory.get(); | |
| 332 system_params.network_delegate = &globals_->network_delegate; | |
| 333 system_params.net_log = net_log_; | |
| 334 globals_->system_http_transaction_factory.reset( | |
| 335 new net::HttpNetworkLayer( | |
| 336 new net::HttpNetworkSession(system_params))); | |
| 337 globals_->system_request_context = | |
| 338 ConstructSystemRequestContext(globals_, net_log_); | |
| 339 } | |
| 340 | |
| 246 void IOThread::InitNetworkPredictor( | 341 void IOThread::InitNetworkPredictor( |
| 247 bool prefetching_enabled, | 342 bool prefetching_enabled, |
| 248 base::TimeDelta max_dns_queue_delay, | 343 base::TimeDelta max_dns_queue_delay, |
| 249 size_t max_speculative_parallel_resolves, | 344 size_t max_speculative_parallel_resolves, |
| 250 const chrome_common_net::UrlList& startup_urls, | 345 const chrome_common_net::UrlList& startup_urls, |
| 251 ListValue* referral_list, | 346 ListValue* referral_list, |
| 252 bool preconnect_enabled) { | 347 bool preconnect_enabled) { |
| 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 254 message_loop()->PostTask( | 349 message_loop()->PostTask( |
| 255 FROM_HERE, | 350 FROM_HERE, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 | 382 |
| 288 void IOThread::ChangedToOnTheRecord() { | 383 void IOThread::ChangedToOnTheRecord() { |
| 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 384 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 290 message_loop()->PostTask( | 385 message_loop()->PostTask( |
| 291 FROM_HERE, | 386 FROM_HERE, |
| 292 NewRunnableMethod( | 387 NewRunnableMethod( |
| 293 this, | 388 this, |
| 294 &IOThread::ChangedToOnTheRecordOnIOThread)); | 389 &IOThread::ChangedToOnTheRecordOnIOThread)); |
| 295 } | 390 } |
| 296 | 391 |
| 392 scoped_refptr<URLRequestContextGetter> | |
| 393 IOThread::system_url_request_context_getter() { | |
| 394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 395 if (!system_url_request_context_getter_) { | |
| 396 system_url_request_context_getter_ = | |
| 397 new SystemURLRequestContextGetter(this); | |
| 398 } | |
| 399 return system_url_request_context_getter_; | |
| 400 } | |
| 401 | |
| 297 void IOThread::Init() { | 402 void IOThread::Init() { |
| 298 // Though this thread is called the "IO" thread, it actually just routes | 403 // Though this thread is called the "IO" thread, it actually just routes |
| 299 // messages around; it shouldn't be allowed to perform any blocking disk I/O. | 404 // messages around; it shouldn't be allowed to perform any blocking disk I/O. |
| 300 base::ThreadRestrictions::SetIOAllowed(false); | 405 base::ThreadRestrictions::SetIOAllowed(false); |
| 301 | 406 |
| 302 BrowserProcessSubThread::Init(); | 407 BrowserProcessSubThread::Init(); |
| 303 | 408 |
| 304 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); | 409 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); |
| 305 | 410 |
| 306 #if defined(USE_NSS) | 411 #if defined(USE_NSS) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 speculative_interceptor_ = NULL; | 507 speculative_interceptor_ = NULL; |
| 403 | 508 |
| 404 // TODO(eroman): hack for http://crbug.com/15513 | 509 // TODO(eroman): hack for http://crbug.com/15513 |
| 405 if (globals_->host_resolver->GetAsHostResolverImpl()) { | 510 if (globals_->host_resolver->GetAsHostResolverImpl()) { |
| 406 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); | 511 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); |
| 407 } | 512 } |
| 408 | 513 |
| 409 delete globals_; | 514 delete globals_; |
| 410 globals_ = NULL; | 515 globals_ = NULL; |
| 411 | 516 |
| 517 system_url_request_context_getter_ = NULL; | |
|
willchan no longer on Chromium
2011/02/15 01:05:58
Please move this line to the end of "Step 1". See
battre
2011/02/15 19:32:49
Done.
| |
| 518 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); | |
|
willchan no longer on Chromium
2011/02/15 01:05:58
Please move this to CleanUpAfterMessageLoopDestruc
battre
2011/02/15 19:32:49
Done.
| |
| 519 | |
| 412 BrowserProcessSubThread::CleanUp(); | 520 BrowserProcessSubThread::CleanUp(); |
| 413 } | 521 } |
| 414 | 522 |
| 415 void IOThread::CleanUpAfterMessageLoopDestruction() { | 523 void IOThread::CleanUpAfterMessageLoopDestruction() { |
| 416 // This will delete the |notification_service_|. Make sure it's done after | 524 // This will delete the |notification_service_|. Make sure it's done after |
| 417 // anything else can reference it. | 525 // anything else can reference it. |
| 418 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction(); | 526 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction(); |
| 419 | 527 |
| 420 // net::URLRequest instances must NOT outlive the IO thread. | 528 // net::URLRequest instances must NOT outlive the IO thread. |
| 421 // | 529 // |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 void IOThread::ClearHostCache() { | 619 void IOThread::ClearHostCache() { |
| 512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 513 | 621 |
| 514 if (globals_->host_resolver->GetAsHostResolverImpl()) { | 622 if (globals_->host_resolver->GetAsHostResolverImpl()) { |
| 515 net::HostCache* host_cache = | 623 net::HostCache* host_cache = |
| 516 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); | 624 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); |
| 517 if (host_cache) | 625 if (host_cache) |
| 518 host_cache->clear(); | 626 host_cache->clear(); |
| 519 } | 627 } |
| 520 } | 628 } |
| OLD | NEW |