Cleanup URLRequestContextGetter.

In brightray line length limit is 100 so we could make code formatted more
tidy.
This commit is contained in:
Cheng Zhao 2014-08-20 15:19:25 +08:00
parent 3fefdcba0d
commit 6e420d5137
2 changed files with 31 additions and 42 deletions

View file

@ -116,6 +116,9 @@ URLRequestContextGetter::URLRequestContextGetter(
std::swap(protocol_handlers_, *protocol_handlers); std::swap(protocol_handlers_, *protocol_handlers);
// We must create the proxy config service on the UI loop on Linux because it
// must synchronously run on the glib message loop. This will be passed to
// the URLRequestContextStorage on the IO thread in GetURLRequestContext().
proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService(
io_loop_->message_loop_proxy(), file_loop_)); io_loop_->message_loop_proxy(), file_loop_));
} }
@ -131,28 +134,24 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
const CommandLine& command_line = *CommandLine::ForCurrentProcess(); const CommandLine& command_line = *CommandLine::ForCurrentProcess();
if (!url_request_context_.get()) { if (!url_request_context_.get()) {
url_request_context_.reset(new net::URLRequestContext()); url_request_context_.reset(new net::URLRequestContext);
network_delegate_.reset(delegate_->CreateNetworkDelegate()); network_delegate_.reset(delegate_->CreateNetworkDelegate());
url_request_context_->set_network_delegate(network_delegate_.get()); url_request_context_->set_network_delegate(network_delegate_.get());
storage_.reset(
new net::URLRequestContextStorage(url_request_context_.get())); storage_.reset(new net::URLRequestContextStorage(url_request_context_.get()));
auto cookie_config = content::CookieStoreConfig( auto cookie_config = content::CookieStoreConfig(
base_path_.Append(FILE_PATH_LITERAL("Cookies")), base_path_.Append(FILE_PATH_LITERAL("Cookies")),
content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
nullptr, NULL, NULL);
nullptr);
storage_->set_cookie_store(content::CreateCookieStore(cookie_config)); storage_->set_cookie_store(content::CreateCookieStore(cookie_config));
storage_->set_server_bound_cert_service(new net::ServerBoundCertService( storage_->set_server_bound_cert_service(new net::ServerBoundCertService(
new net::DefaultServerBoundCertStore(NULL), new net::DefaultServerBoundCertStore(NULL),
base::WorkerPool::GetTaskRunner(true))); base::WorkerPool::GetTaskRunner(true)));
storage_->set_http_user_agent_settings( storage_->set_http_user_agent_settings(new net::StaticHttpUserAgentSettings(
new net::StaticHttpUserAgentSettings( "en-us,en", base::EmptyString()));
"en-us,en", base::EmptyString()));
scoped_ptr<net::HostResolver> host_resolver( scoped_ptr<net::HostResolver> host_resolver(net::HostResolver::CreateDefaultResolver(NULL));
net::HostResolver::CreateDefaultResolver(NULL));
// --host-resolver-rules // --host-resolver-rules
if (command_line.HasSwitch(switches::kHostResolverRules)) { if (command_line.HasSwitch(switches::kHostResolverRules)) {
@ -189,33 +188,19 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
new net::HttpServerPropertiesImpl); new net::HttpServerPropertiesImpl);
storage_->set_http_server_properties(server_properties.Pass()); storage_->set_http_server_properties(server_properties.Pass());
base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache"));
net::HttpCache::DefaultBackend* main_backend =
new net::HttpCache::DefaultBackend(
net::DISK_CACHE,
net::CACHE_BACKEND_DEFAULT,
cache_path,
0,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
net::HttpNetworkSession::Params network_session_params; net::HttpNetworkSession::Params network_session_params;
network_session_params.cert_verifier = network_session_params.cert_verifier = url_request_context_->cert_verifier();
url_request_context_->cert_verifier(); network_session_params.proxy_service = url_request_context_->proxy_service();
network_session_params.ssl_config_service = url_request_context_->ssl_config_service();
network_session_params.network_delegate = url_request_context_->network_delegate();
network_session_params.http_server_properties = url_request_context_->http_server_properties();
network_session_params.ignore_certificate_errors = false;
network_session_params.transport_security_state = network_session_params.transport_security_state =
url_request_context_->transport_security_state(); url_request_context_->transport_security_state();
network_session_params.server_bound_cert_service = network_session_params.server_bound_cert_service =
url_request_context_->server_bound_cert_service(); url_request_context_->server_bound_cert_service();
network_session_params.proxy_service =
url_request_context_->proxy_service();
network_session_params.ssl_config_service =
url_request_context_->ssl_config_service();
network_session_params.http_auth_handler_factory = network_session_params.http_auth_handler_factory =
url_request_context_->http_auth_handler_factory(); url_request_context_->http_auth_handler_factory();
network_session_params.network_delegate =
url_request_context_->network_delegate();
network_session_params.http_server_properties =
url_request_context_->http_server_properties();
network_session_params.ignore_certificate_errors = false;
// --host-rules // --host-rules
if (command_line.HasSwitch(kHostRules)) { if (command_line.HasSwitch(kHostRules)) {
@ -226,12 +211,17 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
// Give |storage_| ownership at the end in case it's |mapped_host_resolver|. // Give |storage_| ownership at the end in case it's |mapped_host_resolver|.
storage_->set_host_resolver(host_resolver.Pass()); storage_->set_host_resolver(host_resolver.Pass());
network_session_params.host_resolver = network_session_params.host_resolver = url_request_context_->host_resolver();
url_request_context_->host_resolver();
net::HttpCache* main_cache = new net::HttpCache( base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache"));
network_session_params, main_backend); net::HttpCache::DefaultBackend* backend =
storage_->set_http_transaction_factory(main_cache); new net::HttpCache::DefaultBackend(
net::DISK_CACHE,
net::CACHE_BACKEND_DEFAULT,
cache_path,
0,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
storage_->set_http_transaction_factory(new net::HttpCache(network_session_params, backend));
storage_->set_job_factory(delegate_->CreateURLRequestJobFactory( storage_->set_job_factory(delegate_->CreateURLRequestJobFactory(
&protocol_handlers_, &protocol_interceptors_)); &protocol_handlers_, &protocol_interceptors_));
@ -240,8 +230,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
return url_request_context_.get(); return url_request_context_.get();
} }
scoped_refptr<base::SingleThreadTaskRunner> scoped_refptr<base::SingleThreadTaskRunner> URLRequestContextGetter::GetNetworkTaskRunner() const {
URLRequestContextGetter::GetNetworkTaskRunner() const {
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
} }

View file

@ -47,13 +47,13 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
content::ProtocolHandlerScopedVector protocol_interceptors); content::ProtocolHandlerScopedVector protocol_interceptors);
virtual ~URLRequestContextGetter(); virtual ~URLRequestContextGetter();
net::HostResolver* host_resolver(); // net::URLRequestContextGetter:
virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
virtual scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner() const OVERRIDE;
net::HostResolver* host_resolver();
private: private:
virtual scoped_refptr<base::SingleThreadTaskRunner>
GetNetworkTaskRunner() const OVERRIDE;
Delegate* delegate_; Delegate* delegate_;
base::FilePath base_path_; base::FilePath base_path_;