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

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

Issue 10299002: Stop refcounting URLRequestContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initialize to NULL Created 8 years, 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 190
191 net_log_->AddGlobalEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED, 191 net_log_->AddGlobalEntry(net::NetLog::TYPE_NETWORK_IP_ADDRESSES_CHANGED,
192 NULL); 192 NULL);
193 } 193 }
194 194
195 private: 195 private:
196 net::NetLog* net_log_; 196 net::NetLog* net_log_;
197 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); 197 DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver);
198 }; 198 };
199 199
200 // Create a separate request context for PAC fetches to avoid reference cycles. 200 // TODO(willchan): Remove proxy script fetcher context since it's not necessary
201 // now that I got rid of refcounting URLRequestContexts.
201 // See IOThread::Globals for details. 202 // See IOThread::Globals for details.
202 scoped_refptr<net::URLRequestContext> 203 net::URLRequestContext*
203 ConstructProxyScriptFetcherContext(IOThread::Globals* globals, 204 ConstructProxyScriptFetcherContext(IOThread::Globals* globals,
204 net::NetLog* net_log) { 205 net::NetLog* net_log) {
205 scoped_refptr<net::URLRequestContext> context( 206 net::URLRequestContext* context = new URLRequestContextWithUserAgent;
206 new URLRequestContextWithUserAgent);
207 context->set_net_log(net_log); 207 context->set_net_log(net_log);
208 context->set_host_resolver(globals->host_resolver.get()); 208 context->set_host_resolver(globals->host_resolver.get());
209 context->set_cert_verifier(globals->cert_verifier.get()); 209 context->set_cert_verifier(globals->cert_verifier.get());
210 context->set_transport_security_state( 210 context->set_transport_security_state(
211 globals->transport_security_state.get()); 211 globals->transport_security_state.get());
212 context->set_http_auth_handler_factory( 212 context->set_http_auth_handler_factory(
213 globals->http_auth_handler_factory.get()); 213 globals->http_auth_handler_factory.get());
214 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); 214 context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get());
215 context->set_http_transaction_factory( 215 context->set_http_transaction_factory(
216 globals->proxy_script_fetcher_http_transaction_factory.get()); 216 globals->proxy_script_fetcher_http_transaction_factory.get());
217 context->set_ftp_transaction_factory( 217 context->set_ftp_transaction_factory(
218 globals->proxy_script_fetcher_ftp_transaction_factory.get()); 218 globals->proxy_script_fetcher_ftp_transaction_factory.get());
219 context->set_cookie_store(globals->system_cookie_store.get()); 219 context->set_cookie_store(globals->system_cookie_store.get());
220 context->set_server_bound_cert_service( 220 context->set_server_bound_cert_service(
221 globals->system_server_bound_cert_service.get()); 221 globals->system_server_bound_cert_service.get());
222 context->set_network_delegate(globals->system_network_delegate.get()); 222 context->set_network_delegate(globals->system_network_delegate.get());
223 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the 223 // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
224 // system URLRequestContext too. There's no reason this should be tied to a 224 // system URLRequestContext too. There's no reason this should be tied to a
225 // profile. 225 // profile.
226 return context; 226 return context;
227 } 227 }
228 228
229 scoped_refptr<net::URLRequestContext> 229 net::URLRequestContext*
230 ConstructSystemRequestContext(IOThread::Globals* globals, 230 ConstructSystemRequestContext(IOThread::Globals* globals,
231 net::NetLog* net_log) { 231 net::NetLog* net_log) {
232 scoped_refptr<net::URLRequestContext> context( 232 net::URLRequestContext* context = new SystemURLRequestContext;
233 new SystemURLRequestContext);
234 context->set_net_log(net_log); 233 context->set_net_log(net_log);
235 context->set_host_resolver(globals->host_resolver.get()); 234 context->set_host_resolver(globals->host_resolver.get());
236 context->set_cert_verifier(globals->cert_verifier.get()); 235 context->set_cert_verifier(globals->cert_verifier.get());
237 context->set_transport_security_state( 236 context->set_transport_security_state(
238 globals->transport_security_state.get()); 237 globals->transport_security_state.get());
239 context->set_http_auth_handler_factory( 238 context->set_http_auth_handler_factory(
240 globals->http_auth_handler_factory.get()); 239 globals->http_auth_handler_factory.get());
241 context->set_proxy_service(globals->system_proxy_service.get()); 240 context->set_proxy_service(globals->system_proxy_service.get());
242 context->set_http_transaction_factory( 241 context->set_http_transaction_factory(
243 globals->system_http_transaction_factory.get()); 242 globals->system_http_transaction_factory.get());
(...skipping 30 matching lines...) Expand all
274 IOThread* io_thread) 273 IOThread* io_thread)
275 : io_thread_(io_thread), 274 : io_thread_(io_thread),
276 io_message_loop_proxy_( 275 io_message_loop_proxy_(
277 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) { 276 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)) {
278 } 277 }
279 278
280 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {} 279 SystemURLRequestContextGetter::~SystemURLRequestContextGetter() {}
281 280
282 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() { 281 net::URLRequestContext* SystemURLRequestContextGetter::GetURLRequestContext() {
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
284 DCHECK(io_thread_->globals()->system_request_context); 283 DCHECK(io_thread_->globals()->system_request_context.get());
285 284
286 return io_thread_->globals()->system_request_context; 285 return io_thread_->globals()->system_request_context.get();
287 } 286 }
288 287
289 scoped_refptr<base::MessageLoopProxy> 288 scoped_refptr<base::MessageLoopProxy>
290 SystemURLRequestContextGetter::GetIOMessageLoopProxy() const { 289 SystemURLRequestContextGetter::GetIOMessageLoopProxy() const {
291 return io_message_loop_proxy_; 290 return io_message_loop_proxy_;
292 } 291 }
293 292
294 IOThread::Globals:: 293 IOThread::Globals::
295 SystemRequestContextLeakChecker::SystemRequestContextLeakChecker( 294 SystemRequestContextLeakChecker::SystemRequestContextLeakChecker(
296 Globals* globals) 295 Globals* globals)
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 448
450 globals_->throttler_manager.reset(new net::URLRequestThrottlerManager()); 449 globals_->throttler_manager.reset(new net::URLRequestThrottlerManager());
451 // Always done in production, disabled only for unit tests. 450 // Always done in production, disabled only for unit tests.
452 globals_->throttler_manager->set_enable_thread_checks(true); 451 globals_->throttler_manager->set_enable_thread_checks(true);
453 if (CommandLine::ForCurrentProcess()->HasSwitch( 452 if (CommandLine::ForCurrentProcess()->HasSwitch(
454 switches::kDisableExtensionsHttpThrottling)) { 453 switches::kDisableExtensionsHttpThrottling)) {
455 globals_->throttler_manager->set_enforce_throttling(false); 454 globals_->throttler_manager->set_enforce_throttling(false);
456 } 455 }
457 globals_->throttler_manager->set_net_log(net_log_); 456 globals_->throttler_manager->set_net_log(net_log_);
458 457
459 globals_->proxy_script_fetcher_context = 458 globals_->proxy_script_fetcher_context.reset(
460 ConstructProxyScriptFetcherContext(globals_, net_log_); 459 ConstructProxyScriptFetcherContext(globals_, net_log_));
461 460
462 sdch_manager_ = new net::SdchManager(); 461 sdch_manager_ = new net::SdchManager();
463 462
464 // InitSystemRequestContext turns right around and posts a task back 463 // InitSystemRequestContext turns right around and posts a task back
465 // to the IO thread, so we can't let it run until we know the IO 464 // to the IO thread, so we can't let it run until we know the IO
466 // thread has started. 465 // thread has started.
467 // 466 //
468 // Note that since we are at BrowserThread::Init time, the UI thread 467 // Note that since we are at BrowserThread::Init time, the UI thread
469 // is blocked waiting for the thread to start. Therefore, posting 468 // is blocked waiting for the thread to start. Therefore, posting
470 // this task to the main thread's message loop here is guaranteed to 469 // this task to the main thread's message loop here is guaranteed to
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 594
596 void IOThread::InitSystemRequestContextOnIOThread() { 595 void IOThread::InitSystemRequestContextOnIOThread() {
597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 596 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
598 DCHECK(!globals_->system_proxy_service.get()); 597 DCHECK(!globals_->system_proxy_service.get());
599 DCHECK(system_proxy_config_service_.get()); 598 DCHECK(system_proxy_config_service_.get());
600 599
601 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 600 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
602 globals_->system_proxy_service.reset( 601 globals_->system_proxy_service.reset(
603 ProxyServiceFactory::CreateProxyService( 602 ProxyServiceFactory::CreateProxyService(
604 net_log_, 603 net_log_,
605 globals_->proxy_script_fetcher_context, 604 globals_->proxy_script_fetcher_context.get(),
606 system_proxy_config_service_.release(), 605 system_proxy_config_service_.release(),
607 command_line)); 606 command_line));
608 net::HttpNetworkSession::Params system_params; 607 net::HttpNetworkSession::Params system_params;
609 system_params.host_resolver = globals_->host_resolver.get(); 608 system_params.host_resolver = globals_->host_resolver.get();
610 system_params.cert_verifier = globals_->cert_verifier.get(); 609 system_params.cert_verifier = globals_->cert_verifier.get();
611 system_params.server_bound_cert_service = 610 system_params.server_bound_cert_service =
612 globals_->system_server_bound_cert_service.get(); 611 globals_->system_server_bound_cert_service.get();
613 system_params.transport_security_state = 612 system_params.transport_security_state =
614 globals_->transport_security_state.get(); 613 globals_->transport_security_state.get();
615 system_params.ssl_host_info_factory = NULL; 614 system_params.ssl_host_info_factory = NULL;
616 system_params.proxy_service = globals_->system_proxy_service.get(); 615 system_params.proxy_service = globals_->system_proxy_service.get();
617 system_params.ssl_config_service = globals_->ssl_config_service.get(); 616 system_params.ssl_config_service = globals_->ssl_config_service.get();
618 system_params.http_auth_handler_factory = 617 system_params.http_auth_handler_factory =
619 globals_->http_auth_handler_factory.get(); 618 globals_->http_auth_handler_factory.get();
620 system_params.http_server_properties = globals_->http_server_properties.get(); 619 system_params.http_server_properties = globals_->http_server_properties.get();
621 system_params.network_delegate = globals_->system_network_delegate.get(); 620 system_params.network_delegate = globals_->system_network_delegate.get();
622 system_params.net_log = net_log_; 621 system_params.net_log = net_log_;
623 globals_->system_http_transaction_factory.reset( 622 globals_->system_http_transaction_factory.reset(
624 new net::HttpNetworkLayer( 623 new net::HttpNetworkLayer(
625 new net::HttpNetworkSession(system_params))); 624 new net::HttpNetworkSession(system_params)));
626 globals_->system_ftp_transaction_factory.reset( 625 globals_->system_ftp_transaction_factory.reset(
627 new net::FtpNetworkLayer(globals_->host_resolver.get())); 626 new net::FtpNetworkLayer(globals_->host_resolver.get()));
628 globals_->system_request_context = 627 globals_->system_request_context.reset(
629 ConstructSystemRequestContext(globals_, net_log_); 628 ConstructSystemRequestContext(globals_, net_log_));
630 629
631 sdch_manager_->set_sdch_fetcher( 630 sdch_manager_->set_sdch_fetcher(
632 new SdchDictionaryFetcher(system_url_request_context_getter_.get())); 631 new SdchDictionaryFetcher(system_url_request_context_getter_.get()));
633 } 632 }
OLDNEW
« no previous file with comments | « chrome/browser/io_thread.h ('k') | chrome/browser/net/chrome_fraudulent_certificate_reporter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698