OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/net/preconnect.h" | 5 #include "chrome/browser/net/preconnect.h" |
6 | 6 |
7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 PROXY_HAS_RULES, | 47 PROXY_HAS_RULES, |
48 PROXY_MAX, | 48 PROXY_MAX, |
49 }; | 49 }; |
50 | 50 |
51 static void HistogramPreconnectStatus(ProxyStatus status) { | 51 static void HistogramPreconnectStatus(ProxyStatus status) { |
52 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectProxyStatus", status, PROXY_MAX); | 52 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectProxyStatus", status, PROXY_MAX); |
53 } | 53 } |
54 | 54 |
55 // static | 55 // static |
56 void Preconnect::PreconnectOnIOThread(const GURL& url) { | 56 void Preconnect::PreconnectOnIOThread(const GURL& url) { |
| 57 // TODO(jar): This does not handle proxies currently. |
57 URLRequestContextGetter* getter = Profile::GetDefaultRequestContext(); | 58 URLRequestContextGetter* getter = Profile::GetDefaultRequestContext(); |
58 if (!getter) | 59 if (!getter) |
59 return; | 60 return; |
60 if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { | 61 if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
61 LOG(DFATAL) << "This must be run only on the IO thread."; | 62 LOG(DFATAL) << "This must be run only on the IO thread."; |
62 return; | 63 return; |
63 } | 64 } |
64 URLRequestContext* context = getter->GetURLRequestContext(); | 65 URLRequestContext* context = getter->GetURLRequestContext(); |
65 | 66 |
66 if (preconnect_despite_proxy_) { | 67 if (preconnect_despite_proxy_) { |
(...skipping 11 matching lines...) Expand all Loading... |
78 if (!proxy_service->config().proxy_rules().empty()) { | 79 if (!proxy_service->config().proxy_rules().empty()) { |
79 HistogramPreconnectStatus(PROXY_HAS_RULES); | 80 HistogramPreconnectStatus(PROXY_HAS_RULES); |
80 return; | 81 return; |
81 } | 82 } |
82 HistogramPreconnectStatus(PROXY_NOT_USED); | 83 HistogramPreconnectStatus(PROXY_NOT_USED); |
83 } | 84 } |
84 } | 85 } |
85 | 86 |
86 net::HttpTransactionFactory* factory = context->http_transaction_factory(); | 87 net::HttpTransactionFactory* factory = context->http_transaction_factory(); |
87 net::HttpNetworkSession* session = factory->GetSession(); | 88 net::HttpNetworkSession* session = factory->GetSession(); |
88 scoped_refptr<net::TCPClientSocketPool> pool = session->tcp_socket_pool(); | |
89 | |
90 scoped_refptr<net::TCPSocketParams> params = | |
91 new net::TCPSocketParams(url.host(), url.EffectiveIntPort(), net::LOW, | |
92 GURL(), false); | |
93 | 89 |
94 net::ClientSocketHandle handle; | 90 net::ClientSocketHandle handle; |
95 if (!callback_instance_) | 91 if (!callback_instance_) |
96 callback_instance_ = new Preconnect; | 92 callback_instance_ = new Preconnect; |
97 | 93 |
| 94 scoped_refptr<net::TCPSocketParams> tcp_params = |
| 95 new net::TCPSocketParams(url.host(), url.EffectiveIntPort(), net::LOW, |
| 96 GURL(), false); |
| 97 |
98 net::HostPortPair endpoint(url.host(), url.EffectiveIntPort()); | 98 net::HostPortPair endpoint(url.host(), url.EffectiveIntPort()); |
99 std::string group_name = endpoint.ToString(); | 99 std::string group_name = endpoint.ToString(); |
100 if (url.SchemeIs("https")) | 100 |
| 101 if (url.SchemeIs("https")) { |
101 group_name = StringPrintf("ssl/%s", group_name.c_str()); | 102 group_name = StringPrintf("ssl/%s", group_name.c_str()); |
102 | 103 |
103 // TODO(jar): This does not handle proxies currently. | 104 net::SSLConfig ssl_config; |
104 handle.Init(group_name, params, net::LOWEST, | 105 session->ssl_config_service()->GetSSLConfig(&ssl_config); |
105 callback_instance_, pool, net::BoundNetLog()); | 106 // All preconnects should be for main pages. |
| 107 ssl_config.verify_ev_cert = true; |
| 108 |
| 109 scoped_refptr<net::SSLSocketParams> ssl_params = |
| 110 new net::SSLSocketParams(tcp_params, NULL, NULL, |
| 111 net::ProxyServer::SCHEME_DIRECT, |
| 112 url.HostNoBrackets(), ssl_config, |
| 113 0, false); |
| 114 |
| 115 const scoped_refptr<net::SSLClientSocketPool>& pool = |
| 116 session->ssl_socket_pool(); |
| 117 |
| 118 handle.Init(group_name, ssl_params, net::LOWEST, callback_instance_, pool, |
| 119 net::BoundNetLog()); |
| 120 handle.Reset(); |
| 121 return; |
| 122 } |
| 123 |
| 124 const scoped_refptr<net::TCPClientSocketPool>& pool = |
| 125 session->tcp_socket_pool(); |
| 126 handle.Init(group_name, tcp_params, net::LOWEST, callback_instance_, pool, |
| 127 net::BoundNetLog()); |
106 handle.Reset(); | 128 handle.Reset(); |
107 } | 129 } |
108 | 130 |
109 void Preconnect::RunWithParams(const Tuple1<int>& params) { | 131 void Preconnect::RunWithParams(const Tuple1<int>& params) { |
110 // This will rarely be called, as we reset the connection just after creating. | 132 // This will rarely be called, as we reset the connection just after creating. |
111 NOTREACHED(); | 133 NOTREACHED(); |
112 } | 134 } |
113 } // chrome_browser_net | 135 } // chrome_browser_net |
OLD | NEW |