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

Side by Side Diff: mojo/loader/url_request_context_getter.cc

Issue 27943002: Teach mojo_shell how to load http URLs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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
« no previous file with comments | « mojo/loader/url_request_context_getter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/loader/url_request_context_getter.h" 5 #include "mojo/loader/url_request_context_getter.h"
6 #include "net/cookies/cookie_monster.h" 6 #include "net/cookies/cookie_monster.h"
7 #include "net/http/http_cache.h"
8 #include "net/http/http_network_session.h"
9 #include "net/http/http_server_properties_impl.h"
7 #include "net/proxy/proxy_service.h" 10 #include "net/proxy/proxy_service.h"
8 #include "net/ssl/ssl_config_service_defaults.h" 11 #include "net/ssl/ssl_config_service_defaults.h"
9 #include "net/url_request/data_protocol_handler.h" 12 #include "net/url_request/data_protocol_handler.h"
13 #include "net/url_request/static_http_user_agent_settings.h"
10 #include "net/url_request/url_request_context.h" 14 #include "net/url_request/url_request_context.h"
11 #include "net/url_request/url_request_job_factory_impl.h" 15 #include "net/url_request/url_request_job_factory_impl.h"
12 16
13 namespace mojo { 17 namespace mojo {
14 namespace loader { 18 namespace loader {
15 19
16 URLRequestContextGetter::URLRequestContextGetter() 20 URLRequestContextGetter::URLRequestContextGetter(
17 : net_log_(new net::NetLog()) { 21 base::SingleThreadTaskRunner* network_task_runner,
22 base::MessageLoopProxy* cache_task_runner)
23 : network_task_runner_(network_task_runner),
24 cache_task_runner_(cache_task_runner),
25 net_log_(new net::NetLog()) {
18 } 26 }
19 27
20 URLRequestContextGetter::~URLRequestContextGetter() { 28 URLRequestContextGetter::~URLRequestContextGetter() {
21 } 29 }
22 30
23 net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { 31 net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
24 if (!url_request_context_) { 32 if (!url_request_context_) {
25 url_request_context_.reset(new net::URLRequestContext()); 33 url_request_context_.reset(new net::URLRequestContext());
26 url_request_context_->set_net_log(net_log_.get()); 34 url_request_context_->set_net_log(net_log_.get());
27 35
28 storage_.reset( 36 storage_.reset(
29 new net::URLRequestContextStorage(url_request_context_.get())); 37 new net::URLRequestContextStorage(url_request_context_.get()));
30 38
31 storage_->set_cookie_store(new net::CookieMonster(NULL, NULL)); 39 storage_->set_cookie_store(new net::CookieMonster(NULL, NULL));
40 storage_->set_http_user_agent_settings(
41 new net::StaticHttpUserAgentSettings("en-us,en", "Mojo/0.1"));
42
32 storage_->set_proxy_service(net::ProxyService::CreateDirect()); 43 storage_->set_proxy_service(net::ProxyService::CreateDirect());
33 storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); 44 storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults);
45 storage_->set_http_server_properties(
46 scoped_ptr<net::HttpServerProperties>(
47 new net::HttpServerPropertiesImpl()));
34 storage_->set_host_resolver(net::HostResolver::CreateDefaultResolver( 48 storage_->set_host_resolver(net::HostResolver::CreateDefaultResolver(
35 url_request_context_->net_log())); 49 url_request_context_->net_log()));
36 50
51 net::HttpNetworkSession::Params network_session_params;
52 network_session_params.net_log =
53 url_request_context_->net_log();
54 network_session_params.proxy_service =
55 url_request_context_->proxy_service();
56 network_session_params.ssl_config_service =
57 url_request_context_->ssl_config_service();
58 network_session_params.http_server_properties =
59 url_request_context_->http_server_properties();
60 network_session_params.host_resolver =
61 url_request_context_->host_resolver();
62
63 base::FilePath cache_path =
64 base::FilePath().Append(FILE_PATH_LITERAL("tmp/mojo/Cache"));
abarth-chromium 2013/10/18 01:20:45 Where do we want to store the HTTP cache?
65
66 net::HttpCache::DefaultBackend* main_backend =
67 new net::HttpCache::DefaultBackend(
68 net::DISK_CACHE,
69 net::CACHE_BACKEND_DEFAULT,
70 cache_path,
71 0,
72 cache_task_runner_.get());
73
74 net::HttpCache* main_cache = new net::HttpCache(
75 network_session_params, main_backend);
76 storage_->set_http_transaction_factory(main_cache);
77
37 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( 78 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory(
38 new net::URLRequestJobFactoryImpl()); 79 new net::URLRequestJobFactoryImpl());
39 80
40 bool set_protocol = job_factory->SetProtocolHandler( 81 bool set_protocol = job_factory->SetProtocolHandler(
41 "data", new net::DataProtocolHandler()); 82 "data", new net::DataProtocolHandler());
42 CHECK(set_protocol); 83 CHECK(set_protocol);
43 84
44 storage_->set_job_factory(job_factory.release()); 85 storage_->set_job_factory(job_factory.release());
45 } 86 }
46 87
47 return url_request_context_.get(); 88 return url_request_context_.get();
48 } 89 }
49 90
50 scoped_refptr<base::SingleThreadTaskRunner> 91 scoped_refptr<base::SingleThreadTaskRunner>
51 URLRequestContextGetter::GetNetworkTaskRunner() const { 92 URLRequestContextGetter::GetNetworkTaskRunner() const {
52 // TODO(abarth): Move network requests to a background thread. 93 return network_task_runner_;
53 return base::MessageLoopProxy::current();
54 } 94 }
55 95
56 } // namespace loader 96 } // namespace loader
57 } // namespace mojo 97 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/loader/url_request_context_getter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698