Skip to content

Commit

Permalink
Remove static variables from HttpStreamFactory.
Browse files Browse the repository at this point in the history
Refresh of issue 10389162.

BUG=124900


Review URL: https://chromiumcodereview.appspot.com/10834215

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155485 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
szager@chromium.org committed Sep 7, 2012
1 parent 28196f1 commit c2dad29
Show file tree
Hide file tree
Showing 32 changed files with 316 additions and 303 deletions.
28 changes: 0 additions & 28 deletions chrome/browser/chrome_browser_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,6 @@ void InitializeNetworkOptions(const CommandLine& parsed_command_line) {
net::CookieMonster::EnableFileScheme();
}

if (parsed_command_line.HasSwitch(switches::kIgnoreCertificateErrors))
net::HttpStreamFactory::set_ignore_certificate_errors(true);

if (parsed_command_line.HasSwitch(switches::kHostRules))
net::HttpStreamFactory::SetHostMappingRules(
parsed_command_line.GetSwitchValueASCII(switches::kHostRules));

if (parsed_command_line.HasSwitch(switches::kEnableIPPooling))
net::SpdySessionPool::enable_ip_pooling(true);

Expand All @@ -238,27 +231,6 @@ void InitializeNetworkOptions(const CommandLine& parsed_command_line) {
net::WebSocketJob::set_websocket_over_spdy_enabled(true);
}

if (parsed_command_line.HasSwitch(switches::kEnableHttpPipelining))
net::HttpStreamFactory::set_http_pipelining_enabled(true);

if (parsed_command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
int value;
base::StringToInt(
parsed_command_line.GetSwitchValueASCII(
switches::kTestingFixedHttpPort),
&value);
net::HttpStreamFactory::set_testing_fixed_http_port(value);
}

if (parsed_command_line.HasSwitch(switches::kTestingFixedHttpsPort)) {
int value;
base::StringToInt(
parsed_command_line.GetSwitchValueASCII(
switches::kTestingFixedHttpsPort),
&value);
net::HttpStreamFactory::set_testing_fixed_https_port(value);
}

bool used_spdy_switch = false;
if (parsed_command_line.HasSwitch(switches::kUseSpdy)) {
std::string spdy_mode =
Expand Down
60 changes: 53 additions & 7 deletions chrome/browser/io_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "net/base/cert_verifier.h"
#include "net/base/default_server_bound_cert_store.h"
#include "net/base/host_cache.h"
#include "net/base/host_mapping_rules.h"
#include "net/base/host_resolver.h"
#include "net/base/mapped_host_resolver.h"
#include "net/base/net_util.h"
Expand Down Expand Up @@ -322,7 +323,12 @@ SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() {

IOThread::Globals::Globals()
: ALLOW_THIS_IN_INITIALIZER_LIST(
system_request_context_leak_checker(this)) {}
system_request_context_leak_checker(this)),
ignore_certificate_errors(false),
http_pipelining_enabled(false),
testing_fixed_http_port(0),
testing_fixed_https_port(0) {}

IOThread::Globals::~Globals() {}

// |local_state| is passed in explicitly in order to (1) reduce implicit
Expand Down Expand Up @@ -401,6 +407,8 @@ void IOThread::Init() {
net::SetMessageLoopForNSSHttpIO();
#endif // defined(USE_NSS)

const CommandLine& command_line = *CommandLine::ForCurrentProcess();

DCHECK(!globals_);
globals_ = new Globals;

Expand All @@ -424,10 +432,8 @@ void IOThread::Init() {
NULL,
&system_enable_referrers_,
NULL);
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kDisableExtensionsHttpThrottling)) {
if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling))
network_delegate->NeverThrottleRequests();
}
globals_->system_network_delegate.reset(network_delegate);
globals_->host_resolver.reset(
CreateGlobalHostResolver(net_log_));
Expand All @@ -448,6 +454,32 @@ void IOThread::Init() {
new net::DefaultServerBoundCertStore(NULL),
base::WorkerPool::GetTaskRunner(true)));
globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats());
globals_->host_mapping_rules.reset(new net::HostMappingRules());
if (command_line.HasSwitch(switches::kHostRules)) {
globals_->host_mapping_rules->SetRulesFromString(
command_line.GetSwitchValueASCII(switches::kHostRules));
}
if (command_line.HasSwitch(switches::kIgnoreCertificateErrors))
globals_->ignore_certificate_errors = true;
if (command_line.HasSwitch(switches::kEnableHttpPipelining))
globals_->http_pipelining_enabled = true;
if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) {
int value;
base::StringToInt(
command_line.GetSwitchValueASCII(
switches::kTestingFixedHttpPort),
&value);
globals_->testing_fixed_http_port = value;
}
if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) {
int value;
base::StringToInt(
command_line.GetSwitchValueASCII(
switches::kTestingFixedHttpsPort),
&value);
globals_->testing_fixed_https_port = value;
}

net::HttpNetworkSession::Params session_params;
session_params.host_resolver = globals_->host_resolver.get();
session_params.cert_verifier = globals_->cert_verifier.get();
Expand All @@ -457,16 +489,23 @@ void IOThread::Init() {
globals_->transport_security_state.get();
session_params.proxy_service =
globals_->proxy_script_fetcher_proxy_service.get();
session_params.ssl_config_service = globals_->ssl_config_service.get();
session_params.http_auth_handler_factory =
globals_->http_auth_handler_factory.get();
session_params.http_server_properties =
globals_->http_server_properties.get();
session_params.network_delegate = globals_->system_network_delegate.get();
// TODO(rtenneti): We should probably use HttpServerPropertiesManager for the
// system URLRequestContext too. There's no reason this should be tied to a
// profile.
session_params.http_server_properties =
globals_->http_server_properties.get();
session_params.net_log = net_log_;
session_params.ssl_config_service = globals_->ssl_config_service;
session_params.host_mapping_rules = globals_->host_mapping_rules.get();
session_params.ignore_certificate_errors =
globals_->ignore_certificate_errors;
session_params.http_pipelining_enabled = globals_->http_pipelining_enabled;
session_params.testing_fixed_http_port = globals_->testing_fixed_http_port;
session_params.testing_fixed_https_port = globals_->http_pipelining_enabled;

scoped_refptr<net::HttpNetworkSession> network_session(
new net::HttpNetworkSession(session_params));
globals_->proxy_script_fetcher_http_transaction_factory.reset(
Expand Down Expand Up @@ -628,6 +667,7 @@ void IOThread::InitSystemRequestContextOnIOThread() {
globals_->proxy_script_fetcher_context.get(),
system_proxy_config_service_.release(),
command_line));

net::HttpNetworkSession::Params system_params;
system_params.host_resolver = globals_->host_resolver.get();
system_params.cert_verifier = globals_->cert_verifier.get();
Expand All @@ -642,6 +682,12 @@ void IOThread::InitSystemRequestContextOnIOThread() {
system_params.http_server_properties = globals_->http_server_properties.get();
system_params.network_delegate = globals_->system_network_delegate.get();
system_params.net_log = net_log_;
system_params.host_mapping_rules = globals_->host_mapping_rules.get();
system_params.ignore_certificate_errors = globals_->ignore_certificate_errors;
system_params.http_pipelining_enabled = globals_->http_pipelining_enabled;
system_params.testing_fixed_http_port = globals_->testing_fixed_http_port;
system_params.testing_fixed_https_port = globals_->testing_fixed_https_port;

globals_->system_http_transaction_factory.reset(
new net::HttpNetworkLayer(
new net::HttpNetworkSession(system_params)));
Expand Down
6 changes: 6 additions & 0 deletions chrome/browser/io_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace net {
class CertVerifier;
class CookieStore;
class FtpTransactionFactory;
class HostMappingRules;
class HostResolver;
class HttpAuthHandlerFactory;
class HttpServerProperties;
Expand Down Expand Up @@ -113,6 +114,11 @@ class IOThread : public content::BrowserThreadDelegate {
scoped_ptr<chrome_browser_net::HttpPipeliningCompatibilityClient>
http_pipelining_compatibility_client;
scoped_ptr<chrome_browser_net::LoadTimeStats> load_time_stats;
scoped_ptr<net::HostMappingRules> host_mapping_rules;
bool ignore_certificate_errors;
bool http_pipelining_enabled;
uint16 testing_fixed_http_port;
uint16 testing_fixed_https_port;
};

// |net_log| must either outlive the IOThread or be NULL.
Expand Down
27 changes: 5 additions & 22 deletions chrome/browser/profiles/off_the_record_profile_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "net/base/server_bound_cert_service.h"
#include "net/ftp/ftp_network_layer.h"
#include "net/http/http_cache.h"
#include "net/http/http_network_session.h"
#include "net/http/http_server_properties_impl.h"
#include "net/url_request/file_protocol_handler.h"
#include "net/url_request/ftp_protocol_handler.h"
Expand Down Expand Up @@ -166,7 +167,6 @@ void OffTheRecordProfileIOData::LazyInitializeInternal(

IOThread* const io_thread = profile_params->io_thread;
IOThread::Globals* const io_thread_globals = io_thread->globals();
const CommandLine& command_line = *CommandLine::ForCurrentProcess();

ApplyProfileParamsToContext(main_context);
ApplyProfileParamsToContext(extensions_context);
Expand Down Expand Up @@ -221,27 +221,10 @@ void OffTheRecordProfileIOData::LazyInitializeInternal(

net::HttpCache::BackendFactory* main_backend =
net::HttpCache::DefaultBackend::InMemory(0);

std::string trusted_spdy_proxy;
if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) {
trusted_spdy_proxy = command_line.GetSwitchValueASCII(
switches::kTrustedSpdyProxy);
}

net::HttpCache* cache =
new net::HttpCache(main_context->host_resolver(),
main_context->cert_verifier(),
main_context->server_bound_cert_service(),
main_context->transport_security_state(),
main_context->proxy_service(),
GetSSLSessionCacheShard(),
main_context->ssl_config_service(),
main_context->http_auth_handler_factory(),
main_context->network_delegate(),
main_context->http_server_properties(),
main_context->net_log(),
main_backend,
trusted_spdy_proxy);
net::HttpNetworkSession::Params network_session_params;
PopulateNetworkSessionParams(profile_params, &network_session_params);
net::HttpCache* cache = new net::HttpCache(
network_session_params, main_backend);

main_http_factory_.reset(cache);
main_context->set_http_transaction_factory(cache);
Expand Down
21 changes: 3 additions & 18 deletions chrome/browser/profiles/profile_impl_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,31 +406,16 @@ void ProfileImplIOData::LazyInitializeInternal(
set_server_bound_cert_service(server_bound_cert_service);
main_context->set_server_bound_cert_service(server_bound_cert_service);

std::string trusted_spdy_proxy;
if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) {
trusted_spdy_proxy = command_line.GetSwitchValueASCII(
switches::kTrustedSpdyProxy);
}
net::HttpCache::DefaultBackend* main_backend =
new net::HttpCache::DefaultBackend(
net::DISK_CACHE,
lazy_params_->cache_path,
lazy_params_->cache_max_size,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
net::HttpNetworkSession::Params network_session_params;
PopulateNetworkSessionParams(profile_params, &network_session_params);
net::HttpCache* main_cache = new net::HttpCache(
main_context->host_resolver(),
main_context->cert_verifier(),
main_context->server_bound_cert_service(),
main_context->transport_security_state(),
main_context->proxy_service(),
GetSSLSessionCacheShard(),
main_context->ssl_config_service(),
main_context->http_auth_handler_factory(),
main_context->network_delegate(),
main_context->http_server_properties(),
main_context->net_log(),
main_backend,
trusted_spdy_proxy);
network_session_params, main_backend);

if (record_mode || playback_mode) {
main_cache->set_mode(
Expand Down
33 changes: 33 additions & 0 deletions chrome/browser/profiles/profile_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -652,3 +652,36 @@ void ProfileIOData::set_server_bound_cert_service(
void ProfileIOData::DestroyResourceContext() {
resource_context_.reset();
}

void ProfileIOData::PopulateNetworkSessionParams(
const ProfileParams* profile_params,
net::HttpNetworkSession::Params* params) const {

ChromeURLRequestContext* context = main_request_context();

IOThread* const io_thread = profile_params->io_thread;
IOThread::Globals* const globals = io_thread->globals();

params->host_resolver = context->host_resolver();
params->cert_verifier = context->cert_verifier();
params->server_bound_cert_service = context->server_bound_cert_service();
params->transport_security_state = context->transport_security_state();
params->proxy_service = context->proxy_service();
params->ssl_session_cache_shard = GetSSLSessionCacheShard();
params->ssl_config_service = context->ssl_config_service();
params->http_auth_handler_factory = context->http_auth_handler_factory();
params->network_delegate = context->network_delegate();
params->http_server_properties = context->http_server_properties();
params->net_log = context->net_log();
params->host_mapping_rules = globals->host_mapping_rules.get();
params->ignore_certificate_errors = globals->ignore_certificate_errors;
params->http_pipelining_enabled = globals->http_pipelining_enabled;
params->testing_fixed_http_port = globals->testing_fixed_http_port;
params->testing_fixed_https_port = globals->testing_fixed_https_port;

const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) {
params->trusted_spdy_proxy = command_line.GetSwitchValueASCII(
switches::kTrustedSpdyProxy);
}
}
7 changes: 7 additions & 0 deletions chrome/browser/profiles/profile_io_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "chrome/browser/net/chrome_url_request_context.h"
#include "content/public/browser/resource_context.h"
#include "net/cookies/cookie_monster.h"
#include "net/http/http_network_session.h"
#include "net/url_request/url_request_job_factory.h"

class CookieSettings;
Expand Down Expand Up @@ -270,6 +271,12 @@ class ProfileIOData {
// URLRequests may be accessing.
void DestroyResourceContext();

// Fills in fields of params using values from main_request_context_ and the
// IOThread associated with profile_params.
void PopulateNetworkSessionParams(
const ProfileParams* profile_params,
net::HttpNetworkSession::Params* params) const;

private:
class ResourceContext : public content::ResourceContext {
public:
Expand Down
6 changes: 2 additions & 4 deletions chrome/browser/ui/webui/net_internals/net_internals_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1449,12 +1449,10 @@ void NetInternalsMessageHandler::IOThreadImpl::OnGetHttpPipeliningStatus(
DCHECK(!list);
DictionaryValue* status_dict = new DictionaryValue();

status_dict->Set("pipelining_enabled",
Value::CreateBooleanValue(
net::HttpStreamFactory::http_pipelining_enabled()));

net::HttpNetworkSession* http_network_session =
GetHttpNetworkSession(context_getter_->GetURLRequestContext());
status_dict->Set("pipelining_enabled", Value::CreateBooleanValue(
http_network_session->params().http_pipelining_enabled));
Value* pipelined_connection_info = NULL;
if (http_network_session) {
pipelined_connection_info =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ void AddDummyHttpPipelineFeedbackOnIOThread(

// Called on IO thread. Adds an entry to the list of known HTTP pipelining
// hosts.
void EnableHttpPipeliningOnIOThread(bool enable) {
void EnableHttpPipeliningOnIOThread(
net::URLRequestContextGetter* context_getter, bool enable) {
ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO));
net::HttpStreamFactory::set_http_pipelining_enabled(enable);
net::URLRequestContext* context = context_getter->GetURLRequestContext();
net::HttpNetworkSession* http_network_session =
context->http_transaction_factory()->GetSession();
http_network_session->set_http_pipelining_enabled(enable);
}

} // namespace
Expand Down Expand Up @@ -275,7 +279,9 @@ void NetInternalsTest::MessageHandler::EnableHttpPipelining(
ASSERT_TRUE(list_value->GetBoolean(0, &enable));
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&EnableHttpPipeliningOnIOThread, enable));
base::Bind(&EnableHttpPipeliningOnIOThread,
make_scoped_refptr(browser()->profile()->GetRequestContext()),
enable));
}

void NetInternalsTest::MessageHandler::AddDummyHttpPipelineFeedback(
Expand Down
6 changes: 5 additions & 1 deletion content/shell/shell_browser_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
namespace content {

ShellBrowserContext::ShellBrowserContext(bool off_the_record)
: off_the_record_(off_the_record) {
: off_the_record_(off_the_record),
ignore_certificate_errors_(false) {
InitWhileIOAllowed();
}

Expand All @@ -41,6 +42,8 @@ ShellBrowserContext::~ShellBrowserContext() {

void ShellBrowserContext::InitWhileIOAllowed() {
CommandLine* cmd_line = CommandLine::ForCurrentProcess();
if (cmd_line->HasSwitch(switches::kDumpRenderTree))
ignore_certificate_errors_ = true;
if (cmd_line->HasSwitch(switches::kDumpRenderTree)) {
CHECK(testing_path_.CreateUniqueTempDir());
path_ = testing_path_.path();
Expand Down Expand Up @@ -96,6 +99,7 @@ DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() {
net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() {
if (!url_request_getter_) {
url_request_getter_ = new ShellURLRequestContextGetter(
ignore_certificate_errors_,
GetPath(),
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO),
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE));
Expand Down
Loading

0 comments on commit c2dad29

Please sign in to comment.