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_thread.h" | 18 #include "chrome/browser/browser_thread.h" |
| 19 #include "chrome/browser/gpu_process_host.h" | 19 #include "chrome/browser/gpu_process_host.h" |
| 20 #include "chrome/browser/in_process_webkit/indexed_db_key_utility_client.h" | 20 #include "chrome/browser/in_process_webkit/indexed_db_key_utility_client.h" |
| 21 #include "chrome/browser/net/chrome_net_log.h" | 21 #include "chrome/browser/net/chrome_net_log.h" |
| 22 #include "chrome/browser/net/chrome_url_request_context.h" | 22 #include "chrome/browser/net/chrome_url_request_context.h" |
| 23 #include "chrome/browser/net/connect_interceptor.h" | 23 #include "chrome/browser/net/connect_interceptor.h" |
| 24 #include "chrome/browser/net/passive_log_collector.h" | 24 #include "chrome/browser/net/passive_log_collector.h" |
| 25 #include "chrome/browser/net/predictor_api.h" | 25 #include "chrome/browser/net/predictor_api.h" |
| 26 #include "chrome/browser/net/proxy_service_factory.h" | |
| 26 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
| 27 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/net/raw_host_resolver_proc.h" | 29 #include "chrome/common/net/raw_host_resolver_proc.h" |
| 29 #include "chrome/common/net/url_fetcher.h" | 30 #include "chrome/common/net/url_fetcher.h" |
| 30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 31 #include "net/base/cert_verifier.h" | 32 #include "net/base/cert_verifier.h" |
| 32 #include "net/base/dnsrr_resolver.h" | 33 #include "net/base/dnsrr_resolver.h" |
| 33 #include "net/base/host_cache.h" | 34 #include "net/base/host_cache.h" |
| 34 #include "net/base/host_resolver.h" | 35 #include "net/base/host_resolver.h" |
| 35 #include "net/base/host_resolver_impl.h" | 36 #include "net/base/host_resolver_impl.h" |
| 36 #include "net/base/mapped_host_resolver.h" | 37 #include "net/base/mapped_host_resolver.h" |
| 37 #include "net/base/net_util.h" | 38 #include "net/base/net_util.h" |
| 39 #include "net/proxy/proxy_config_service.h" | |
| 38 #include "net/http/http_auth_filter.h" | 40 #include "net/http/http_auth_filter.h" |
| 39 #include "net/http/http_auth_handler_factory.h" | 41 #include "net/http/http_auth_handler_factory.h" |
| 40 #include "net/http/http_network_layer.h" | 42 #include "net/http/http_network_layer.h" |
| 41 #include "net/http/http_network_session.h" | 43 #include "net/http/http_network_session.h" |
| 42 #if defined(USE_NSS) | 44 #if defined(USE_NSS) |
| 43 #include "net/ocsp/nss_ocsp.h" | 45 #include "net/ocsp/nss_ocsp.h" |
| 44 #endif // defined(USE_NSS) | 46 #endif // defined(USE_NSS) |
| 45 #include "net/proxy/proxy_script_fetcher_impl.h" | 47 #include "net/proxy/proxy_script_fetcher_impl.h" |
| 46 | 48 |
| 47 namespace { | 49 namespace { |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 globals->http_auth_handler_factory.get()); | 190 globals->http_auth_handler_factory.get()); |
| 189 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); | 191 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); |
| 190 context->set_http_transaction_factory( | 192 context->set_http_transaction_factory( |
| 191 globals->proxy_script_fetcher_http_transaction_factory.get()); | 193 globals->proxy_script_fetcher_http_transaction_factory.get()); |
| 192 // In-memory cookie store. | 194 // In-memory cookie store. |
| 193 context->set_cookie_store(new net::CookieMonster(NULL, NULL)); | 195 context->set_cookie_store(new net::CookieMonster(NULL, NULL)); |
| 194 // TODO(mpcomplete): give it a SystemNetworkDelegate. | 196 // TODO(mpcomplete): give it a SystemNetworkDelegate. |
| 195 return context; | 197 return context; |
| 196 } | 198 } |
| 197 | 199 |
| 200 scoped_refptr<net::URLRequestContext> | |
| 201 ConstructSystemRequestContext(IOThread::Globals* globals, | |
| 202 net::NetLog* net_log) { | |
| 203 scoped_refptr<net::URLRequestContext> context(new net::URLRequestContext); | |
| 204 context->set_net_log(net_log); | |
| 205 context->set_host_resolver(globals->host_resolver.get()); | |
| 206 context->set_cert_verifier(globals->cert_verifier.get()); | |
| 207 context->set_dnsrr_resolver(globals->dnsrr_resolver.get()); | |
| 208 context->set_http_auth_handler_factory( | |
| 209 globals->http_auth_handler_factory.get()); | |
| 210 context->set_proxy_service(globals->system_proxy_service.get()); | |
| 211 context->set_http_transaction_factory( | |
| 212 globals->system_http_transaction_factory.get()); | |
| 213 // In-memory cookie store. | |
| 214 context->set_cookie_store(new net::CookieMonster(NULL, NULL)); | |
| 215 return context; | |
| 216 } | |
| 217 | |
| 198 } // namespace | 218 } // namespace |
| 199 | 219 |
| 220 class SystemURLRequestContextGetter : public URLRequestContextGetter { | |
| 221 public: | |
| 222 explicit SystemURLRequestContextGetter(IOThread* io_thread); | |
| 223 virtual ~SystemURLRequestContextGetter(); | |
| 224 | |
| 225 // Implementation for UrlRequestContextGetter. | |
| 226 virtual net::URLRequestContext* GetURLRequestContext(); | |
| 227 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const; | |
| 228 | |
| 229 private: | |
| 230 IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess. | |
| 231 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; | |
| 232 | |
| 233 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_; | |
| 234 }; | |
| 235 | |
| 236 SystemURLRequestContextGetter::SystemURLRequestContextGetter( | |
| 237 IOThread* io_thread) | |
| 238 : io_thread_(io_thread), | |
| 239 io_message_loop_proxy_(io_thread->message_loop_proxy()) { | |
| 240 } | |
| 241 | |
| 242 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} | |
| 243 | |
| 244 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { | |
| 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 246 | |
| 247 if (!io_thread_->globals()->system_request_context) | |
| 248 io_thread_->InitSystemRequestContext(); | |
| 249 | |
| 250 return io_thread_->globals()->system_request_context; | |
| 251 } | |
| 252 | |
| 253 scoped_refptr<base::MessageLoopProxy> | |
| 254 SystemURLRequestContextGetter::GetIOMessageLoopProxy() const { | |
| 255 return io_message_loop_proxy_; | |
| 256 } | |
| 257 | |
| 200 // The IOThread object must outlive any tasks posted to the IO thread before the | 258 // The IOThread object must outlive any tasks posted to the IO thread before the |
| 201 // Quit task. | 259 // Quit task. |
| 202 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); | 260 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); |
| 203 | 261 |
| 204 IOThread::Globals::Globals() {} | 262 IOThread::Globals::Globals() {} |
| 205 | 263 |
| 206 IOThread::Globals::~Globals() {} | 264 IOThread::Globals::~Globals() {} |
| 207 | 265 |
| 208 // |local_state| is passed in explicitly in order to (1) reduce implicit | 266 // |local_state| is passed in explicitly in order to (1) reduce implicit |
| 209 // dependencies and (2) make IOThread more flexible for testing. | 267 // dependencies and (2) make IOThread more flexible for testing. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 236 | 294 |
| 237 IOThread::Globals* IOThread::globals() { | 295 IOThread::Globals* IOThread::globals() { |
| 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 239 return globals_; | 297 return globals_; |
| 240 } | 298 } |
| 241 | 299 |
| 242 ChromeNetLog* IOThread::net_log() { | 300 ChromeNetLog* IOThread::net_log() { |
| 243 return net_log_; | 301 return net_log_; |
| 244 } | 302 } |
| 245 | 303 |
| 304 void IOThread::SetSystemProxyConfigService( | |
| 305 net::ProxyConfigService* system_proxy_config_service) { | |
| 306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 307 system_proxy_config_service_.reset(system_proxy_config_service); | |
| 308 } | |
| 309 | |
| 246 void IOThread::InitNetworkPredictor( | 310 void IOThread::InitNetworkPredictor( |
| 247 bool prefetching_enabled, | 311 bool prefetching_enabled, |
| 248 base::TimeDelta max_dns_queue_delay, | 312 base::TimeDelta max_dns_queue_delay, |
| 249 size_t max_speculative_parallel_resolves, | 313 size_t max_speculative_parallel_resolves, |
| 250 const chrome_common_net::UrlList& startup_urls, | 314 const chrome_common_net::UrlList& startup_urls, |
| 251 ListValue* referral_list, | 315 ListValue* referral_list, |
| 252 bool preconnect_enabled) { | 316 bool preconnect_enabled) { |
| 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 254 message_loop()->PostTask( | 318 message_loop()->PostTask( |
| 255 FROM_HERE, | 319 FROM_HERE, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 | 351 |
| 288 void IOThread::ChangedToOnTheRecord() { | 352 void IOThread::ChangedToOnTheRecord() { |
| 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 290 message_loop()->PostTask( | 354 message_loop()->PostTask( |
| 291 FROM_HERE, | 355 FROM_HERE, |
| 292 NewRunnableMethod( | 356 NewRunnableMethod( |
| 293 this, | 357 this, |
| 294 &IOThread::ChangedToOnTheRecordOnIOThread)); | 358 &IOThread::ChangedToOnTheRecordOnIOThread)); |
| 295 } | 359 } |
| 296 | 360 |
| 361 scoped_refptr<URLRequestContextGetter> | |
| 362 IOThread::system_url_request_context_getter() { | |
| 363 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
|
willchan no longer on Chromium
2011/02/16 20:02:27
Add a assertion that system_proxy_config_service_
battre
2011/02/21 17:27:57
Done.
| |
| 364 if (!system_url_request_context_getter_) { | |
| 365 system_url_request_context_getter_ = | |
| 366 new SystemURLRequestContextGetter(this); | |
| 367 } | |
| 368 return system_url_request_context_getter_; | |
| 369 } | |
| 370 | |
| 297 void IOThread::Init() { | 371 void IOThread::Init() { |
| 298 // Though this thread is called the "IO" thread, it actually just routes | 372 // 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. | 373 // messages around; it shouldn't be allowed to perform any blocking disk I/O. |
| 300 base::ThreadRestrictions::SetIOAllowed(false); | 374 base::ThreadRestrictions::SetIOAllowed(false); |
| 301 | 375 |
| 302 BrowserProcessSubThread::Init(); | 376 BrowserProcessSubThread::Init(); |
| 303 | 377 |
| 304 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); | 378 DCHECK_EQ(MessageLoop::TYPE_IO, message_loop()->type()); |
| 305 | 379 |
| 306 #if defined(USE_NSS) | 380 #if defined(USE_NSS) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 it != url_request_context_getters.end(); ++it) { | 447 it != url_request_context_getters.end(); ++it) { |
| 374 ChromeURLRequestContextGetter* getter = *it; | 448 ChromeURLRequestContextGetter* getter = *it; |
| 375 // Stop all pending certificate provenance check uploads | 449 // Stop all pending certificate provenance check uploads |
| 376 net::DnsCertProvenanceChecker* checker = | 450 net::DnsCertProvenanceChecker* checker = |
| 377 getter->GetURLRequestContext()->dns_cert_checker(); | 451 getter->GetURLRequestContext()->dns_cert_checker(); |
| 378 if (checker) | 452 if (checker) |
| 379 checker->Shutdown(); | 453 checker->Shutdown(); |
| 380 getter->ReleaseURLRequestContext(); | 454 getter->ReleaseURLRequestContext(); |
| 381 } | 455 } |
| 382 | 456 |
| 457 system_url_request_context_getter_ = NULL; | |
| 458 | |
| 383 // Step 2: Release objects that the net::URLRequestContext could have been | 459 // Step 2: Release objects that the net::URLRequestContext could have been |
| 384 // pointing to. | 460 // pointing to. |
| 385 | 461 |
| 386 // This must be reset before the ChromeNetLog is destroyed. | 462 // This must be reset before the ChromeNetLog is destroyed. |
| 387 network_change_observer_.reset(); | 463 network_change_observer_.reset(); |
| 388 | 464 |
| 389 // Not initialized in Init(). May not be initialized. | 465 // Not initialized in Init(). May not be initialized. |
| 390 if (predictor_) { | 466 if (predictor_) { |
| 391 predictor_->Shutdown(); | 467 predictor_->Shutdown(); |
| 392 | 468 |
| 393 // TODO(willchan): Stop reference counting Predictor. It's owned by | 469 // TODO(willchan): Stop reference counting Predictor. It's owned by |
| 394 // IOThread now. | 470 // IOThread now. |
| 395 predictor_->Release(); | 471 predictor_->Release(); |
| 396 predictor_ = NULL; | 472 predictor_ = NULL; |
| 397 chrome_browser_net::FreePredictorResources(); | 473 chrome_browser_net::FreePredictorResources(); |
| 398 } | 474 } |
| 399 | 475 |
| 400 // Deletion will unregister this interceptor. | 476 // Deletion will unregister this interceptor. |
| 401 delete speculative_interceptor_; | 477 delete speculative_interceptor_; |
| 402 speculative_interceptor_ = NULL; | 478 speculative_interceptor_ = NULL; |
| 403 | 479 |
| 404 // TODO(eroman): hack for http://crbug.com/15513 | 480 // TODO(eroman): hack for http://crbug.com/15513 |
| 405 if (globals_->host_resolver->GetAsHostResolverImpl()) { | 481 if (globals_->host_resolver->GetAsHostResolverImpl()) { |
| 406 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); | 482 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); |
| 407 } | 483 } |
| 408 | 484 |
| 485 system_proxy_config_service_.reset(); | |
| 486 | |
| 409 delete globals_; | 487 delete globals_; |
| 410 globals_ = NULL; | 488 globals_ = NULL; |
| 411 | 489 |
| 412 BrowserProcessSubThread::CleanUp(); | 490 BrowserProcessSubThread::CleanUp(); |
| 413 } | 491 } |
| 414 | 492 |
| 415 void IOThread::CleanUpAfterMessageLoopDestruction() { | 493 void IOThread::CleanUpAfterMessageLoopDestruction() { |
| 416 // This will delete the |notification_service_|. Make sure it's done after | 494 // This will delete the |notification_service_|. Make sure it's done after |
| 417 // anything else can reference it. | 495 // anything else can reference it. |
| 418 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction(); | 496 BrowserProcessSubThread::CleanUpAfterMessageLoopDestruction(); |
| 419 | 497 |
| 420 // net::URLRequest instances must NOT outlive the IO thread. | 498 // net::URLRequest instances must NOT outlive the IO thread. |
| 421 // | 499 // |
| 422 // To allow for URLRequests to be deleted from | 500 // To allow for URLRequests to be deleted from |
| 423 // MessageLoop::DestructionObserver this check has to happen after CleanUp | 501 // MessageLoop::DestructionObserver this check has to happen after CleanUp |
| 424 // (which runs before DestructionObservers). | 502 // (which runs before DestructionObservers). |
| 425 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); | 503 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); |
| 504 | |
| 505 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks(); | |
| 426 } | 506 } |
| 427 | 507 |
| 428 // static | 508 // static |
| 429 void IOThread::RegisterPrefs(PrefService* local_state) { | 509 void IOThread::RegisterPrefs(PrefService* local_state) { |
| 430 local_state->RegisterStringPref(prefs::kAuthSchemes, | 510 local_state->RegisterStringPref(prefs::kAuthSchemes, |
| 431 "basic,digest,ntlm,negotiate"); | 511 "basic,digest,ntlm,negotiate"); |
| 432 local_state->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, | 512 local_state->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, |
| 433 false); | 513 false); |
| 434 local_state->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false); | 514 local_state->RegisterBooleanPref(prefs::kEnableAuthNegotiatePort, false); |
| 435 local_state->RegisterStringPref(prefs::kAuthServerWhitelist, ""); | 515 local_state->RegisterStringPref(prefs::kAuthServerWhitelist, ""); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 void IOThread::ClearHostCache() { | 591 void IOThread::ClearHostCache() { |
| 512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 592 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 513 | 593 |
| 514 if (globals_->host_resolver->GetAsHostResolverImpl()) { | 594 if (globals_->host_resolver->GetAsHostResolverImpl()) { |
| 515 net::HostCache* host_cache = | 595 net::HostCache* host_cache = |
| 516 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); | 596 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); |
| 517 if (host_cache) | 597 if (host_cache) |
| 518 host_cache->clear(); | 598 host_cache->clear(); |
| 519 } | 599 } |
| 520 } | 600 } |
| 601 | |
| 602 void IOThread::InitSystemRequestContext() { | |
| 603 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 604 DCHECK(!globals_->system_proxy_service); | |
| 605 DCHECK(system_proxy_config_service_.get()); | |
| 606 | |
| 607 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 608 globals_->system_proxy_service = | |
| 609 ProxyServiceFactory::CreateProxyService( | |
| 610 net_log_, | |
| 611 globals_->proxy_script_fetcher_context, | |
| 612 system_proxy_config_service_.release(), | |
| 613 command_line); | |
| 614 net::HttpNetworkSession::Params system_params; | |
| 615 system_params.host_resolver = globals_->host_resolver.get(); | |
| 616 system_params.cert_verifier = globals_->cert_verifier.get(); | |
| 617 system_params.dnsrr_resolver = globals_->dnsrr_resolver.get(); | |
| 618 system_params.dns_cert_checker = NULL; | |
| 619 system_params.ssl_host_info_factory = NULL; | |
| 620 system_params.proxy_service = globals_->system_proxy_service.get(); | |
| 621 system_params.ssl_config_service = globals_->ssl_config_service.get(); | |
| 622 system_params.http_auth_handler_factory = | |
| 623 globals_->http_auth_handler_factory.get(); | |
| 624 system_params.network_delegate = &globals_->network_delegate; | |
| 625 system_params.net_log = net_log_; | |
| 626 globals_->system_http_transaction_factory.reset( | |
| 627 new net::HttpNetworkLayer( | |
| 628 new net::HttpNetworkSession(system_params))); | |
| 629 globals_->system_request_context = | |
| 630 ConstructSystemRequestContext(globals_, net_log_); | |
| 631 } | |
| OLD | NEW |