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

Side by Side Diff: mojo/services/network/network_context.cc

Issue 354693004: Switch to using URLRequestContextBuilder to create some URLRequestContexts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update comments Created 6 years, 5 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 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();
32
33 base::Thread::Options options;
34 options.message_loop_type = base::MessageLoop::TYPE_IO;
35 cache_thread_.StartWithOptions(options);
36
37 url_request_context_.reset(new net::URLRequestContext());
38 url_request_context_->set_net_log(net_log_.get());
39
40 storage_.reset(
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. 18 // TODO(darin): This is surely the wrong UA string.
46 storage_->set_http_user_agent_settings( 19 builder.set_user_agent("Mojo/0.1");
47 new net::StaticHttpUserAgentSettings("en-us,en", "Mojo/0.1")); 20 builder.set_proxy_service(net::ProxyService::CreateDirect());
48 21 builder.set_transport_security_persister_path(base_path);
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(
mef 2014/06/30 21:42:58 do we need this?
mmenke 2014/06/30 21:55:25 We do, and I added this to the builder (See line 3
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 22
92 base::FilePath cache_path = base_path.Append(FILE_PATH_LITERAL("Cache")); 23 base::FilePath cache_path = base_path.Append(FILE_PATH_LITERAL("Cache"));
24 net::URLRequestContextBuilder::HttpCacheParams cache_params;
25 cache_params.path = base_path.Append(FILE_PATH_LITERAL("Cache"));
mef 2014/06/30 21:42:58 shouldn't this be |cache_path|?
mmenke 2014/06/30 21:55:25 Actually, I meant to delete the cache_path line (W
26 cache_params.type = net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY;
mef 2014/06/30 21:42:59 Why change from DISK_CACHE to IN_MEMORY?
mmenke 2014/06/30 21:55:25 Eee...That would have been bad! Thanks for catchi
27 builder.EnableHttpCache(cache_params);
93 28
94 net::HttpCache::DefaultBackend* main_backend = 29 builder.set_file_enabled(true);
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 30
102 net::HttpCache* main_cache = new net::HttpCache( 31 url_request_context_.reset(builder.Build());
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 } 32 }
113 33
114 NetworkContext::~NetworkContext() { 34 NetworkContext::~NetworkContext() {
115 // TODO(darin): Be careful about destruction order of member variables? 35 // TODO(darin): Be careful about destruction order of member variables?
116 } 36 }
117 37
118 } // namespace mojo 38 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698