Commit 2944afa8 authored by mmenke@chromium.org's avatar mmenke@chromium.org

Add URLRequestJobFactories to URLRequestContexts without one.

Currently a URLRequestJobFactory is optional, as the global
URLRequestJobManager passes jobs on to the URLRequestFilter and
global http/https/ws/wss factories.  In order to be able to
eliminate the global URLRequestJobManager object, first have to
give all contexts their own URLRequestJobFactory.

BUG=81979
TBR=ajwong@chromium.org (Who actually signed off on this, but Rietveld ignored his email).

Review URL: https://codereview.chromium.org/311393002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276867 0039d316-1c4b-4281-b951-d872f2087c98
parent 7e885e72
......@@ -259,6 +259,7 @@ ConstructSystemRequestContext(IOThread::Globals* globals,
context->set_proxy_service(globals->system_proxy_service.get());
context->set_http_transaction_factory(
globals->system_http_transaction_factory.get());
context->set_job_factory(globals->system_url_request_job_factory.get());
context->set_cookie_store(globals->system_cookie_store.get());
context->set_server_bound_cert_service(
globals->system_server_bound_cert_service.get());
......@@ -1045,6 +1046,8 @@ void IOThread::InitSystemRequestContextOnIOThread() {
globals_->system_http_transaction_factory.reset(
new net::HttpNetworkLayer(
new net::HttpNetworkSession(system_params)));
globals_->system_url_request_job_factory.reset(
new net::URLRequestJobFactoryImpl());
globals_->system_request_context.reset(
ConstructSystemRequestContext(globals_, net_log_));
......
......@@ -143,6 +143,7 @@ class IOThread : public content::BrowserThreadDelegate {
scoped_ptr<net::URLRequestContext> proxy_script_fetcher_context;
scoped_ptr<net::ProxyService> system_proxy_service;
scoped_ptr<net::HttpTransactionFactory> system_http_transaction_factory;
scoped_ptr<net::URLRequestJobFactory> system_url_request_job_factory;
scoped_ptr<net::URLRequestContext> system_request_context;
SystemRequestContextLeakChecker system_request_context_leak_checker;
// |system_cookie_store| and |system_server_bound_cert_service| are shared
......
......@@ -36,6 +36,7 @@
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_storage.h"
#include "net/url_request/url_request_job_factory_impl.h"
#if !defined(OS_ANDROID) && !defined(OS_IOS)
#include "chrome/browser/net/firefox_proxy_settings.h"
......@@ -134,6 +135,9 @@ class ExperimentURLRequestContext : public net::URLRequestContext {
// In-memory cookie store.
storage_.set_cookie_store(
content::CreateCookieStore(content::CookieStoreConfig()));
// Creating a new job factory avoids added ProtocolHandlers and
// layered URLRequestInterceptingJobFactories.
storage_.set_job_factory(new net::URLRequestJobFactoryImpl());
return net::OK;
}
......
......@@ -21,6 +21,7 @@
#include "net/ssl/ssl_config_service_defaults.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
......@@ -93,9 +94,7 @@ class ConnectionTesterTest : public PlatformTest {
test_server_(net::SpawnedTestServer::TYPE_HTTP,
net::SpawnedTestServer::kLocalhost,
// Nothing is read in this directory.
base::FilePath(FILE_PATH_LITERAL("chrome"))),
proxy_script_fetcher_context_(new net::URLRequestContext) {
InitializeRequestContext();
base::FilePath(FILE_PATH_LITERAL("chrome"))) {
}
protected:
......@@ -107,56 +106,15 @@ class ConnectionTesterTest : public PlatformTest {
base::MessageLoopForIO message_loop_;
content::TestBrowserThread io_thread_;
net::SpawnedTestServer test_server_;
net::TestURLRequestContext proxy_script_fetcher_context_;
ConnectionTesterDelegate test_delegate_;
net::MockHostResolver host_resolver_;
scoped_ptr<net::CertVerifier> cert_verifier_;
scoped_ptr<net::TransportSecurityState> transport_security_state_;
scoped_ptr<net::ProxyService> proxy_service_;
scoped_refptr<net::SSLConfigService> ssl_config_service_;
scoped_ptr<net::HttpTransactionFactory> http_transaction_factory_;
net::HttpAuthHandlerRegistryFactory http_auth_handler_factory_;
net::HttpServerPropertiesImpl http_server_properties_impl_;
scoped_ptr<net::URLRequestContext> proxy_script_fetcher_context_;
private:
void InitializeRequestContext() {
proxy_script_fetcher_context_->set_host_resolver(&host_resolver_);
cert_verifier_.reset(new net::MockCertVerifier);
transport_security_state_.reset(new net::TransportSecurityState);
proxy_script_fetcher_context_->set_cert_verifier(cert_verifier_.get());
proxy_script_fetcher_context_->set_transport_security_state(
transport_security_state_.get());
proxy_script_fetcher_context_->set_http_auth_handler_factory(
&http_auth_handler_factory_);
proxy_service_.reset(net::ProxyService::CreateDirect());
proxy_script_fetcher_context_->set_proxy_service(proxy_service_.get());
ssl_config_service_ = new net::SSLConfigServiceDefaults;
net::HttpNetworkSession::Params session_params;
session_params.host_resolver = &host_resolver_;
session_params.cert_verifier = cert_verifier_.get();
session_params.transport_security_state = transport_security_state_.get();
session_params.http_auth_handler_factory = &http_auth_handler_factory_;
session_params.ssl_config_service = ssl_config_service_.get();
session_params.proxy_service = proxy_service_.get();
session_params.http_server_properties =
http_server_properties_impl_.GetWeakPtr();
scoped_refptr<net::HttpNetworkSession> network_session(
new net::HttpNetworkSession(session_params));
http_transaction_factory_.reset(
new net::HttpNetworkLayer(network_session.get()));
proxy_script_fetcher_context_->set_http_transaction_factory(
http_transaction_factory_.get());
// In-memory cookie store.
proxy_script_fetcher_context_->set_cookie_store(
content::CreateCookieStore(content::CookieStoreConfig()));
}
};
TEST_F(ConnectionTesterTest, RunAllTests) {
ASSERT_TRUE(test_server_.Start());
ConnectionTester tester(&test_delegate_,
proxy_script_fetcher_context_.get(),
&proxy_script_fetcher_context_,
NULL);
// Start the test suite on URL "echoall".
......@@ -183,7 +141,7 @@ TEST_F(ConnectionTesterTest, DeleteWhileInProgress) {
scoped_ptr<ConnectionTester> tester(
new ConnectionTester(&test_delegate_,
proxy_script_fetcher_context_.get(),
&proxy_script_fetcher_context_,
NULL));
// Start the test suite on URL "echoall".
......
......@@ -25,6 +25,7 @@
#include "net/proxy/proxy_service.h"
#include "net/ssl/ssl_config_service_defaults.h"
#include "net/url_request/static_http_user_agent_settings.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_throttler_manager.h"
namespace {
......@@ -136,6 +137,7 @@ ServiceURLRequestContext::ServiceURLRequestContext(
network_session.get(), net::HttpCache::DefaultBackend::InMemory(0)));
// In-memory cookie store.
storage_.set_cookie_store(new net::CookieMonster(NULL, NULL));
storage_.set_job_factory(new net::URLRequestJobFactoryImpl());
storage_.set_http_user_agent_settings(new net::StaticHttpUserAgentSettings(
"en-us,fr", user_agent));
}
......
......@@ -24,6 +24,7 @@
#include "net/spdy/spdy_session.h"
#include "net/spdy/spdy_session_pool.h"
#include "net/spdy/spdy_stream.h"
#include "net/url_request/url_request_job_factory_impl.h"
namespace net {
......@@ -475,6 +476,7 @@ SpdyURLRequestContext::SpdyURLRequestContext(NextProto protocol,
host_resolver()));
storage_.set_http_server_properties(
scoped_ptr<HttpServerProperties>(new HttpServerPropertiesImpl()));
storage_.set_job_factory(new URLRequestJobFactoryImpl());
net::HttpNetworkSession::Params params;
params.client_socket_factory = &socket_factory_;
params.host_resolver = host_resolver();
......
......@@ -15,6 +15,7 @@
#include "net/proxy/proxy_config_service.h"
#include "net/proxy/proxy_service.h"
#include "net/ssl/ssl_config_service_defaults.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "remoting/base/vlog_net_log.h"
#if defined(OS_WIN)
......@@ -95,6 +96,7 @@ URLRequestContext::URLRequestContext(
scoped_ptr<net::HttpServerProperties>(
new net::HttpServerPropertiesImpl()));
storage_.set_transport_security_state(new net::TransportSecurityState);
storage_.set_job_factory(new net::URLRequestJobFactoryImpl());
net::HttpNetworkSession::Params session_params;
session_params.host_resolver = host_resolver();
......
......@@ -16,6 +16,7 @@
#include "net/url_request/static_http_user_agent_settings.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_status.h"
#include "sync/internal_api/public/base/cancelation_signal.h"
......@@ -122,7 +123,8 @@ HttpBridge::RequestContext::RequestContext(
network_task_runner,
const std::string& user_agent)
: baseline_context_(baseline_context),
network_task_runner_(network_task_runner) {
network_task_runner_(network_task_runner),
job_factory_(new net::URLRequestJobFactoryImpl()) {
DCHECK(!user_agent.empty());
// Create empty, in-memory cookie store.
......@@ -133,6 +135,9 @@ HttpBridge::RequestContext::RequestContext(
set_proxy_service(baseline_context->proxy_service());
set_ssl_config_service(baseline_context->ssl_config_service());
// Use its own job factory, which only supports http and https.
set_job_factory(job_factory_.get());
// We want to share the HTTP session data with the network layer factory,
// which includes auth_cache for proxies.
// Session is not refcounted so we need to be careful to not lose the parent
......
......@@ -33,6 +33,7 @@ namespace net {
class HttpResponseHeaders;
class HttpUserAgentSettings;
class URLFetcher;
class URLRequestJobFactory;
}
namespace syncer {
......@@ -72,6 +73,7 @@ class SYNC_EXPORT_PRIVATE HttpBridge
net::URLRequestContext* const baseline_context_;
const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
scoped_ptr<net::HttpUserAgentSettings> http_user_agent_settings_;
scoped_ptr<net::URLRequestJobFactory> job_factory_;
DISALLOW_COPY_AND_ASSIGN(RequestContext);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment