| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/services/network/network_context.h" | 5 #include "mojo/services/network/network_context.h" |
| 6 | 6 |
| 7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "net/cert/cert_verifier.h" | |
| 10 #include "net/cookies/cookie_monster.h" | |
| 11 #include "net/http/http_cache.h" | |
| 12 #include "net/http/http_network_session.h" | |
| 13 #include "net/http/http_server_properties_impl.h" | |
| 14 #include "net/http/transport_security_persister.h" | |
| 15 #include "net/http/transport_security_state.h" | |
| 16 #include "net/proxy/proxy_service.h" | 9 #include "net/proxy/proxy_service.h" |
| 17 #include "net/ssl/default_server_bound_cert_store.h" | |
| 18 #include "net/ssl/server_bound_cert_service.h" | |
| 19 #include "net/ssl/ssl_config_service_defaults.h" | |
| 20 #include "net/url_request/file_protocol_handler.h" | |
| 21 #include "net/url_request/static_http_user_agent_settings.h" | |
| 22 #include "net/url_request/url_request_context.h" | 10 #include "net/url_request/url_request_context.h" |
| 23 #include "net/url_request/url_request_context_storage.h" | 11 #include "net/url_request/url_request_context_builder.h" |
| 24 #include "net/url_request/url_request_job_factory_impl.h" | |
| 25 | 12 |
| 26 namespace mojo { | 13 namespace mojo { |
| 27 | 14 |
| 28 NetworkContext::NetworkContext(const base::FilePath& base_path) | 15 NetworkContext::NetworkContext(const base::FilePath& base_path) { |
| 29 : file_thread_("network_file_thread"), | 16 net::URLRequestContextBuilder builder; |
| 30 cache_thread_("network_cache_thread") { | 17 builder.set_accept_language("en-us,en"); |
| 31 file_thread_.Start(); | 18 // TODO(darin): This is surely the wrong UA string. |
| 19 builder.set_user_agent("Mojo/0.1"); |
| 20 builder.set_proxy_service(net::ProxyService::CreateDirect()); |
| 21 builder.set_transport_security_persister_path(base_path); |
| 32 | 22 |
| 33 base::Thread::Options options; | 23 net::URLRequestContextBuilder::HttpCacheParams cache_params; |
| 34 options.message_loop_type = base::MessageLoop::TYPE_IO; | 24 cache_params.path = base_path.Append(FILE_PATH_LITERAL("Cache")); |
| 35 cache_thread_.StartWithOptions(options); | 25 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::DISK; |
| 26 builder.EnableHttpCache(cache_params); |
| 36 | 27 |
| 37 url_request_context_.reset(new net::URLRequestContext()); | 28 builder.set_file_enabled(true); |
| 38 url_request_context_->set_net_log(net_log_.get()); | |
| 39 | 29 |
| 40 storage_.reset( | 30 url_request_context_.reset(builder.Build()); |
| 41 new net::URLRequestContextStorage(url_request_context_.get())); | |
| 42 | |
| 43 storage_->set_cookie_store(new net::CookieMonster(NULL, NULL)); | |
| 44 | |
| 45 // TODO(darin): This is surely the wrong UA string. | |
| 46 storage_->set_http_user_agent_settings( | |
| 47 new net::StaticHttpUserAgentSettings("en-us,en", "Mojo/0.1")); | |
| 48 | |
| 49 storage_->set_proxy_service(net::ProxyService::CreateDirect()); | |
| 50 storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); | |
| 51 storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); | |
| 52 | |
| 53 net::TransportSecurityState* transport_security_state = | |
| 54 new net::TransportSecurityState(); | |
| 55 storage_->set_transport_security_state(transport_security_state); | |
| 56 | |
| 57 transport_security_persister_.reset( | |
| 58 new net::TransportSecurityPersister( | |
| 59 transport_security_state, | |
| 60 base_path, | |
| 61 file_thread_.message_loop_proxy(), | |
| 62 false)); | |
| 63 | |
| 64 storage_->set_server_bound_cert_service( | |
| 65 new net::ServerBoundCertService( | |
| 66 new net::DefaultServerBoundCertStore(NULL), | |
| 67 file_thread_.message_loop_proxy())); | |
| 68 storage_->set_http_server_properties( | |
| 69 scoped_ptr<net::HttpServerProperties>( | |
| 70 new net::HttpServerPropertiesImpl())); | |
| 71 storage_->set_host_resolver(net::HostResolver::CreateDefaultResolver( | |
| 72 url_request_context_->net_log())); | |
| 73 | |
| 74 net::HttpNetworkSession::Params network_session_params; | |
| 75 network_session_params.cert_verifier = | |
| 76 url_request_context_->cert_verifier(); | |
| 77 network_session_params.transport_security_state = | |
| 78 url_request_context_->transport_security_state(); | |
| 79 network_session_params.server_bound_cert_service = | |
| 80 url_request_context_->server_bound_cert_service(); | |
| 81 network_session_params.net_log = | |
| 82 url_request_context_->net_log(); | |
| 83 network_session_params.proxy_service = | |
| 84 url_request_context_->proxy_service(); | |
| 85 network_session_params.ssl_config_service = | |
| 86 url_request_context_->ssl_config_service(); | |
| 87 network_session_params.http_server_properties = | |
| 88 url_request_context_->http_server_properties(); | |
| 89 network_session_params.host_resolver = | |
| 90 url_request_context_->host_resolver(); | |
| 91 | |
| 92 base::FilePath cache_path = base_path.Append(FILE_PATH_LITERAL("Cache")); | |
| 93 | |
| 94 net::HttpCache::DefaultBackend* main_backend = | |
| 95 new net::HttpCache::DefaultBackend( | |
| 96 net::DISK_CACHE, | |
| 97 net::CACHE_BACKEND_DEFAULT, | |
| 98 cache_path, | |
| 99 0, | |
| 100 cache_thread_.message_loop_proxy()); | |
| 101 | |
| 102 net::HttpCache* main_cache = new net::HttpCache( | |
| 103 network_session_params, main_backend); | |
| 104 storage_->set_http_transaction_factory(main_cache); | |
| 105 | |
| 106 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | |
| 107 new net::URLRequestJobFactoryImpl()); | |
| 108 job_factory->SetProtocolHandler( | |
| 109 "file", | |
| 110 new net::FileProtocolHandler(file_thread_.message_loop_proxy())); | |
| 111 storage_->set_job_factory(job_factory.release()); | |
| 112 } | 31 } |
| 113 | 32 |
| 114 NetworkContext::~NetworkContext() { | 33 NetworkContext::~NetworkContext() { |
| 115 // TODO(darin): Be careful about destruction order of member variables? | 34 // TODO(darin): Be careful about destruction order of member variables? |
| 116 } | 35 } |
| 117 | 36 |
| 118 } // namespace mojo | 37 } // namespace mojo |
| OLD | NEW |