OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/shell/shell_url_request_context_getter.h" | 5 #include "content/shell/shell_url_request_context_getter.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 | 32 |
33 ShellURLRequestContextGetter::ShellURLRequestContextGetter( | 33 ShellURLRequestContextGetter::ShellURLRequestContextGetter( |
34 bool ignore_certificate_errors, | 34 bool ignore_certificate_errors, |
35 const FilePath& base_path, | 35 const FilePath& base_path, |
36 MessageLoop* io_loop, | 36 MessageLoop* io_loop, |
37 MessageLoop* file_loop) | 37 MessageLoop* file_loop) |
38 : ignore_certificate_errors_(ignore_certificate_errors), | 38 : ignore_certificate_errors_(ignore_certificate_errors), |
39 base_path_(base_path), | 39 base_path_(base_path), |
40 io_loop_(io_loop), | 40 io_loop_(io_loop), |
41 file_loop_(file_loop) { | 41 file_loop_(file_loop) { |
42 // Must first be created on the UI thread. | |
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
44 | |
45 // We must create the proxy config service on the UI loop on Linux because it | |
46 // must synchronously run on the glib message loop. This will be passed to | |
47 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). | |
48 proxy_config_service_.reset( | |
49 net::ProxyService::CreateSystemProxyConfigService( | |
50 io_loop_->message_loop_proxy(), file_loop_)); | |
51 } | 42 } |
52 | 43 |
53 ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { | 44 ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { |
54 } | 45 } |
55 | 46 |
| 47 void ShellURLRequestContextGetter::StartTearDown() { |
| 48 if (url_request_context_.get()) |
| 49 url_request_context_->proxy_service()->StartTearDown(); |
| 50 } |
| 51 |
56 net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { | 52 net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { |
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
58 | 54 |
59 if (!url_request_context_.get()) { | 55 if (!url_request_context_.get()) { |
60 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 56 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
61 | 57 |
62 url_request_context_.reset(new net::URLRequestContext()); | 58 url_request_context_.reset(new net::URLRequestContext()); |
63 network_delegate_.reset(new ShellNetworkDelegate); | 59 network_delegate_.reset(new ShellNetworkDelegate); |
64 url_request_context_->set_network_delegate(network_delegate_.get()); | 60 url_request_context_->set_network_delegate(network_delegate_.get()); |
65 storage_.reset( | 61 storage_.reset( |
66 new net::URLRequestContextStorage(url_request_context_.get())); | 62 new net::URLRequestContextStorage(url_request_context_.get())); |
67 storage_->set_cookie_store(new net::CookieMonster(NULL, NULL)); | 63 storage_->set_cookie_store(new net::CookieMonster(NULL, NULL)); |
68 storage_->set_server_bound_cert_service(new net::ServerBoundCertService( | 64 storage_->set_server_bound_cert_service(new net::ServerBoundCertService( |
69 new net::DefaultServerBoundCertStore(NULL), | 65 new net::DefaultServerBoundCertStore(NULL), |
70 base::WorkerPool::GetTaskRunner(true))); | 66 base::WorkerPool::GetTaskRunner(true))); |
71 url_request_context_->set_accept_language("en-us,en"); | 67 url_request_context_->set_accept_language("en-us,en"); |
72 url_request_context_->set_accept_charset("iso-8859-1,*,utf-8"); | 68 url_request_context_->set_accept_charset("iso-8859-1,*,utf-8"); |
73 | 69 |
74 storage_->set_host_resolver( | 70 storage_->set_host_resolver( |
75 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, | 71 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, |
76 net::HostResolver::kDefaultRetryAttempts, | 72 net::HostResolver::kDefaultRetryAttempts, |
77 NULL)); | 73 NULL)); |
78 storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); | 74 storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); |
79 // TODO(jam): use v8 if possible, look at chrome code. | 75 // TODO(jam): use v8 if possible, look at chrome code. |
80 storage_->set_proxy_service( | 76 storage_->set_proxy_service( |
81 net::ProxyService::CreateUsingSystemProxyResolver( | 77 net::ProxyService::CreateUsingSystemProxyResolver( |
82 proxy_config_service_.release(), | 78 net::ProxyService::CreateSystemProxyConfigService( |
83 0, | 79 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), |
84 NULL)); | 80 file_loop_), |
| 81 0, |
| 82 NULL)); |
85 storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); | 83 storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); |
86 storage_->set_http_auth_handler_factory( | 84 storage_->set_http_auth_handler_factory( |
87 net::HttpAuthHandlerFactory::CreateDefault( | 85 net::HttpAuthHandlerFactory::CreateDefault( |
88 url_request_context_->host_resolver())); | 86 url_request_context_->host_resolver())); |
89 storage_->set_http_server_properties(new net::HttpServerPropertiesImpl); | 87 storage_->set_http_server_properties(new net::HttpServerPropertiesImpl); |
90 | 88 |
91 FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); | 89 FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); |
92 net::HttpCache::DefaultBackend* main_backend = | 90 net::HttpCache::DefaultBackend* main_backend = |
93 new net::HttpCache::DefaultBackend( | 91 new net::HttpCache::DefaultBackend( |
94 net::DISK_CACHE, | 92 net::DISK_CACHE, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 scoped_refptr<base::SingleThreadTaskRunner> | 147 scoped_refptr<base::SingleThreadTaskRunner> |
150 ShellURLRequestContextGetter::GetNetworkTaskRunner() const { | 148 ShellURLRequestContextGetter::GetNetworkTaskRunner() const { |
151 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 149 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
152 } | 150 } |
153 | 151 |
154 net::HostResolver* ShellURLRequestContextGetter::host_resolver() { | 152 net::HostResolver* ShellURLRequestContextGetter::host_resolver() { |
155 return url_request_context_->host_resolver(); | 153 return url_request_context_->host_resolver(); |
156 } | 154 } |
157 | 155 |
158 } // namespace content | 156 } // namespace content |
OLD | NEW |