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

Side by Side Diff: chrome/browser/io_thread.cc

Issue 6292017: Extended: Add "system" URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
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" 19 #include "chrome/browser/extensions/extension_event_router_forwarder.h"
20 #include "chrome/browser/net/chrome_network_delegate.h" 20 #include "chrome/browser/net/chrome_network_delegate.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/pref_proxy_config_service.h"
27 #include "chrome/browser/net/proxy_service_factory.h"
26 #include "chrome/browser/prefs/pref_service.h" 28 #include "chrome/browser/prefs/pref_service.h"
27 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/net/raw_host_resolver_proc.h" 30 #include "chrome/common/net/raw_host_resolver_proc.h"
29 #include "chrome/common/net/url_fetcher.h" 31 #include "chrome/common/net/url_fetcher.h"
30 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
31 #include "content/browser/browser_thread.h" 33 #include "content/browser/browser_thread.h"
32 #include "content/browser/gpu_process_host.h" 34 #include "content/browser/gpu_process_host.h"
33 #include "content/browser/in_process_webkit/indexed_db_key_utility_client.h" 35 #include "content/browser/in_process_webkit/indexed_db_key_utility_client.h"
34 #include "net/base/cert_verifier.h" 36 #include "net/base/cert_verifier.h"
35 #include "net/base/cookie_monster.h" 37 #include "net/base/cookie_monster.h"
36 #include "net/base/dnsrr_resolver.h" 38 #include "net/base/dnsrr_resolver.h"
37 #include "net/base/host_cache.h" 39 #include "net/base/host_cache.h"
38 #include "net/base/host_resolver.h" 40 #include "net/base/host_resolver.h"
39 #include "net/base/host_resolver_impl.h" 41 #include "net/base/host_resolver_impl.h"
40 #include "net/base/mapped_host_resolver.h" 42 #include "net/base/mapped_host_resolver.h"
41 #include "net/base/net_util.h" 43 #include "net/base/net_util.h"
44 #include "net/proxy/proxy_config_service.h"
42 #include "net/http/http_auth_filter.h" 45 #include "net/http/http_auth_filter.h"
43 #include "net/http/http_auth_handler_factory.h" 46 #include "net/http/http_auth_handler_factory.h"
44 #include "net/http/http_network_layer.h" 47 #include "net/http/http_network_layer.h"
45 #include "net/http/http_network_session.h" 48 #include "net/http/http_network_session.h"
46 #if defined(USE_NSS) 49 #if defined(USE_NSS)
47 #include "net/ocsp/nss_ocsp.h" 50 #include "net/ocsp/nss_ocsp.h"
48 #endif // defined(USE_NSS) 51 #endif // defined(USE_NSS)
49 #include "net/proxy/proxy_script_fetcher_impl.h" 52 #include "net/proxy/proxy_script_fetcher_impl.h"
50 53
51 namespace { 54 namespace {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 globals->http_auth_handler_factory.get()); 195 globals->http_auth_handler_factory.get());
193 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); 196 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get());
194 context->set_http_transaction_factory( 197 context->set_http_transaction_factory(
195 globals->proxy_script_fetcher_http_transaction_factory.get()); 198 globals->proxy_script_fetcher_http_transaction_factory.get());
196 // In-memory cookie store. 199 // In-memory cookie store.
197 context->set_cookie_store(new net::CookieMonster(NULL, NULL)); 200 context->set_cookie_store(new net::CookieMonster(NULL, NULL));
198 context->set_network_delegate(globals->system_network_delegate.get()); 201 context->set_network_delegate(globals->system_network_delegate.get());
199 return context; 202 return context;
200 } 203 }
201 204
205 scoped_refptr<net::URLRequestContext>
206 ConstructSystemRequestContext(IOThread::Globals* globals,
207 net::NetLog* net_log) {
208 scoped_refptr<net::URLRequestContext> context(new net::URLRequestContext);
209 context->set_net_log(net_log);
210 context->set_host_resolver(globals->host_resolver.get());
211 context->set_cert_verifier(globals->cert_verifier.get());
212 context->set_dnsrr_resolver(globals->dnsrr_resolver.get());
213 context->set_http_auth_handler_factory(
214 globals->http_auth_handler_factory.get());
215 context->set_proxy_service(globals->system_proxy_service.get());
216 context->set_http_transaction_factory(
217 globals->system_http_transaction_factory.get());
218 // In-memory cookie store.
219 context->set_cookie_store(new net::CookieMonster(NULL, NULL));
220 return context;
221 }
222
202 } // namespace 223 } // namespace
203 224
225 class SystemURLRequestContextGetter : public URLRequestContextGetter {
226 public:
227 explicit SystemURLRequestContextGetter(IOThread* io_thread);
228 virtual ~SystemURLRequestContextGetter();
229
230 // Implementation for UrlRequestContextGetter.
231 virtual net::URLRequestContext* GetURLRequestContext();
232 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const;
233
234 private:
235 IOThread* const io_thread_; // Weak pointer, owned by BrowserProcess.
236 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
237
238 base::debug::LeakTracker<SystemURLRequestContextGetter> leak_tracker_;
239 };
240
241 SystemURLRequestContextGetter::SystemURLRequestContextGetter(
242 IOThread* io_thread)
243 : io_thread_(io_thread),
244 io_message_loop_proxy_(io_thread->message_loop_proxy()) {
245 }
246
247 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {}
248
249 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() {
250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
251
252 if (!io_thread_->globals()->system_request_context)
253 io_thread_->InitSystemRequestContext();
254
255 return io_thread_->globals()->system_request_context;
256 }
257
258 scoped_refptr<base::MessageLoopProxy>
259 SystemURLRequestContextGetter::GetIOMessageLoopProxy() const {
260 return io_message_loop_proxy_;
261 }
262
204 // The IOThread object must outlive any tasks posted to the IO thread before the 263 // The IOThread object must outlive any tasks posted to the IO thread before the
205 // Quit task. 264 // Quit task.
206 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread); 265 DISABLE_RUNNABLE_METHOD_REFCOUNT(IOThread);
207 266
208 IOThread::Globals::Globals() {} 267 IOThread::Globals::Globals() {}
209 268
210 IOThread::Globals::~Globals() {} 269 IOThread::Globals::~Globals() {}
211 270
212 // |local_state| is passed in explicitly in order to (1) reduce implicit 271 // |local_state| is passed in explicitly in order to (1) reduce implicit
213 // dependencies and (2) make IOThread more flexible for testing. 272 // dependencies and (2) make IOThread more flexible for testing.
(...skipping 12 matching lines...) Expand all
226 RegisterPrefs(local_state); 285 RegisterPrefs(local_state);
227 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes); 286 auth_schemes_ = local_state->GetString(prefs::kAuthSchemes);
228 negotiate_disable_cname_lookup_ = local_state->GetBoolean( 287 negotiate_disable_cname_lookup_ = local_state->GetBoolean(
229 prefs::kDisableAuthNegotiateCnameLookup); 288 prefs::kDisableAuthNegotiateCnameLookup);
230 negotiate_enable_port_ = local_state->GetBoolean( 289 negotiate_enable_port_ = local_state->GetBoolean(
231 prefs::kEnableAuthNegotiatePort); 290 prefs::kEnableAuthNegotiatePort);
232 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist); 291 auth_server_whitelist_ = local_state->GetString(prefs::kAuthServerWhitelist);
233 auth_delegate_whitelist_ = local_state->GetString( 292 auth_delegate_whitelist_ = local_state->GetString(
234 prefs::kAuthNegotiateDelegateWhitelist); 293 prefs::kAuthNegotiateDelegateWhitelist);
235 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName); 294 gssapi_library_name_ = local_state->GetString(prefs::kGSSAPILibraryName);
295 pref_proxy_config_tracker_ = new PrefProxyConfigTracker(local_state);
236 } 296 }
237 297
238 IOThread::~IOThread() { 298 IOThread::~IOThread() {
299 if (pref_proxy_config_tracker_)
300 pref_proxy_config_tracker_->DetachFromPrefService();
239 // We cannot rely on our base class to stop the thread since we want our 301 // We cannot rely on our base class to stop the thread since we want our
240 // CleanUp function to run. 302 // CleanUp function to run.
241 Stop(); 303 Stop();
242 DCHECK(!globals_); 304 DCHECK(!globals_);
243 } 305 }
244 306
245 IOThread::Globals* IOThread::globals() { 307 IOThread::Globals* IOThread::globals() {
246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
247 return globals_; 309 return globals_;
248 } 310 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 357
296 void IOThread::ChangedToOnTheRecord() { 358 void IOThread::ChangedToOnTheRecord() {
297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
298 message_loop()->PostTask( 360 message_loop()->PostTask(
299 FROM_HERE, 361 FROM_HERE,
300 NewRunnableMethod( 362 NewRunnableMethod(
301 this, 363 this,
302 &IOThread::ChangedToOnTheRecordOnIOThread)); 364 &IOThread::ChangedToOnTheRecordOnIOThread));
303 } 365 }
304 366
367 URLRequestContextGetter* IOThread::system_url_request_context_getter() {
368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
369 if (!system_url_request_context_getter_) {
370 system_proxy_config_service_.reset(
371 ProxyServiceFactory::CreateProxyConfigService(
372 pref_proxy_config_tracker_));
373 system_url_request_context_getter_ =
374 new SystemURLRequestContextGetter(this);
375 }
376 return system_url_request_context_getter_;
377 }
378
305 void IOThread::ClearNetworkingHistory() { 379 void IOThread::ClearNetworkingHistory() {
306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
307 ClearHostCache(); 381 ClearHostCache();
308 // Discard acrued data used to speculate in the future. 382 // Discard acrued data used to speculate in the future.
309 chrome_browser_net::DiscardInitialNavigationHistory(); 383 chrome_browser_net::DiscardInitialNavigationHistory();
310 if (predictor_) 384 if (predictor_)
311 predictor_->DiscardAllResults(); 385 predictor_->DiscardAllResults();
312 } 386 }
313 387
314 void IOThread::Init() { 388 void IOThread::Init() {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 it != url_request_context_getters.end(); ++it) { 468 it != url_request_context_getters.end(); ++it) {
395 ChromeURLRequestContextGetter* getter = *it; 469 ChromeURLRequestContextGetter* getter = *it;
396 // Stop all pending certificate provenance check uploads 470 // Stop all pending certificate provenance check uploads
397 net::DnsCertProvenanceChecker* checker = 471 net::DnsCertProvenanceChecker* checker =
398 getter->GetURLRequestContext()->dns_cert_checker(); 472 getter->GetURLRequestContext()->dns_cert_checker();
399 if (checker) 473 if (checker)
400 checker->Shutdown(); 474 checker->Shutdown();
401 getter->ReleaseURLRequestContext(); 475 getter->ReleaseURLRequestContext();
402 } 476 }
403 477
478 system_url_request_context_getter_ = NULL;
479
404 // Step 2: Release objects that the net::URLRequestContext could have been 480 // Step 2: Release objects that the net::URLRequestContext could have been
405 // pointing to. 481 // pointing to.
406 482
407 // This must be reset before the ChromeNetLog is destroyed. 483 // This must be reset before the ChromeNetLog is destroyed.
408 network_change_observer_.reset(); 484 network_change_observer_.reset();
409 485
410 // Not initialized in Init(). May not be initialized. 486 // Not initialized in Init(). May not be initialized.
411 if (predictor_) { 487 if (predictor_) {
412 predictor_->Shutdown(); 488 predictor_->Shutdown();
413 489
414 // TODO(willchan): Stop reference counting Predictor. It's owned by 490 // TODO(willchan): Stop reference counting Predictor. It's owned by
415 // IOThread now. 491 // IOThread now.
416 predictor_->Release(); 492 predictor_->Release();
417 predictor_ = NULL; 493 predictor_ = NULL;
418 chrome_browser_net::FreePredictorResources(); 494 chrome_browser_net::FreePredictorResources();
419 } 495 }
420 496
421 // Deletion will unregister this interceptor. 497 // Deletion will unregister this interceptor.
422 delete speculative_interceptor_; 498 delete speculative_interceptor_;
423 speculative_interceptor_ = NULL; 499 speculative_interceptor_ = NULL;
424 500
425 // TODO(eroman): hack for http://crbug.com/15513 501 // TODO(eroman): hack for http://crbug.com/15513
426 if (globals_->host_resolver->GetAsHostResolverImpl()) { 502 if (globals_->host_resolver->GetAsHostResolverImpl()) {
427 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown(); 503 globals_->host_resolver.get()->GetAsHostResolverImpl()->Shutdown();
428 } 504 }
429 505
506 system_proxy_config_service_.reset();
507
430 delete globals_; 508 delete globals_;
431 globals_ = NULL; 509 globals_ = NULL;
432 510
433 // net::URLRequest instances must NOT outlive the IO thread. 511 // net::URLRequest instances must NOT outlive the IO thread.
434 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks(); 512 base::debug::LeakTracker<net::URLRequest>::CheckForLeaks();
435 513
514 base::debug::LeakTracker<SystemURLRequestContextGetter>::CheckForLeaks();
515
436 // This will delete the |notification_service_|. Make sure it's done after 516 // This will delete the |notification_service_|. Make sure it's done after
437 // anything else can reference it. 517 // anything else can reference it.
438 BrowserProcessSubThread::CleanUp(); 518 BrowserProcessSubThread::CleanUp();
439 } 519 }
440 520
441 // static 521 // static
442 void IOThread::RegisterPrefs(PrefService* local_state) { 522 void IOThread::RegisterPrefs(PrefService* local_state) {
443 local_state->RegisterStringPref(prefs::kAuthSchemes, 523 local_state->RegisterStringPref(prefs::kAuthSchemes,
444 "basic,digest,ntlm,negotiate"); 524 "basic,digest,ntlm,negotiate");
445 local_state->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup, 525 local_state->RegisterBooleanPref(prefs::kDisableAuthNegotiateCnameLookup,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 void IOThread::ClearHostCache() { 605 void IOThread::ClearHostCache() {
526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 606 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
527 607
528 if (globals_->host_resolver->GetAsHostResolverImpl()) { 608 if (globals_->host_resolver->GetAsHostResolverImpl()) {
529 net::HostCache* host_cache = 609 net::HostCache* host_cache =
530 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache(); 610 globals_->host_resolver.get()->GetAsHostResolverImpl()->cache();
531 if (host_cache) 611 if (host_cache)
532 host_cache->clear(); 612 host_cache->clear();
533 } 613 }
534 } 614 }
615
616 void IOThread::InitSystemRequestContext() {
617 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
618 DCHECK(!globals_->system_proxy_service);
619 DCHECK(system_proxy_config_service_.get());
620
621 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
622 globals_->system_proxy_service =
623 ProxyServiceFactory::CreateProxyService(
624 net_log_,
625 globals_->proxy_script_fetcher_context,
626 system_proxy_config_service_.release(),
627 command_line);
628 net::HttpNetworkSession::Params system_params;
629 system_params.host_resolver = globals_->host_resolver.get();
630 system_params.cert_verifier = globals_->cert_verifier.get();
631 system_params.dnsrr_resolver = globals_->dnsrr_resolver.get();
632 system_params.dns_cert_checker = NULL;
633 system_params.ssl_host_info_factory = NULL;
634 system_params.proxy_service = globals_->system_proxy_service.get();
635 system_params.ssl_config_service = globals_->ssl_config_service.get();
636 system_params.http_auth_handler_factory =
637 globals_->http_auth_handler_factory.get();
638 system_params.network_delegate = globals_->system_network_delegate.get();
639 system_params.net_log = net_log_;
640 globals_->system_http_transaction_factory.reset(
641 new net::HttpNetworkLayer(
642 new net::HttpNetworkSession(system_params)));
643 globals_->system_request_context =
644 ConstructSystemRequestContext(globals_, net_log_);
645 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698