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 "chrome/browser/net/preconnect.h" | 5 #include "chrome/browser/net/preconnect.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
11 #include "net/base/net_log.h" | 11 #include "net/base/net_log.h" |
12 #include "net/http/http_network_session.h" | 12 #include "net/http/http_network_session.h" |
13 #include "net/http/http_request_info.h" | 13 #include "net/http/http_request_info.h" |
14 #include "net/http/http_stream_factory.h" | 14 #include "net/http/http_stream_factory.h" |
15 #include "net/http/http_transaction_factory.h" | 15 #include "net/http/http_transaction_factory.h" |
16 #include "net/ssl/ssl_config_service.h" | 16 #include "net/ssl/ssl_config_service.h" |
| 17 #include "net/url_request/http_user_agent_settings.h" |
17 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
18 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
19 | 20 |
20 using content::BrowserThread; | 21 using content::BrowserThread; |
21 | 22 |
22 namespace chrome_browser_net { | 23 namespace chrome_browser_net { |
23 | 24 |
24 void PreconnectOnUIThread( | 25 void PreconnectOnUIThread( |
25 const GURL& url, | 26 const GURL& url, |
26 const GURL& first_party_for_cookies, | 27 const GURL& first_party_for_cookies, |
(...skipping 23 matching lines...) Expand all Loading... |
50 if (!getter) | 51 if (!getter) |
51 return; | 52 return; |
52 // We are now commited to doing the async preconnection call. | 53 // We are now commited to doing the async preconnection call. |
53 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectMotivation", motivation, | 54 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectMotivation", motivation, |
54 UrlInfo::MAX_MOTIVATED); | 55 UrlInfo::MAX_MOTIVATED); |
55 | 56 |
56 net::URLRequestContext* context = getter->GetURLRequestContext(); | 57 net::URLRequestContext* context = getter->GetURLRequestContext(); |
57 net::HttpTransactionFactory* factory = context->http_transaction_factory(); | 58 net::HttpTransactionFactory* factory = context->http_transaction_factory(); |
58 net::HttpNetworkSession* session = factory->GetSession(); | 59 net::HttpNetworkSession* session = factory->GetSession(); |
59 | 60 |
| 61 std::string user_agent; |
| 62 if (context->http_user_agent_settings()) |
| 63 user_agent = context->http_user_agent_settings()->GetUserAgent(url); |
60 net::HttpRequestInfo request_info; | 64 net::HttpRequestInfo request_info; |
61 request_info.url = url; | 65 request_info.url = url; |
62 request_info.method = "GET"; | 66 request_info.method = "GET"; |
63 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, | 67 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, |
64 context->GetUserAgent(url)); | 68 user_agent); |
65 | 69 |
66 net::NetworkDelegate* delegate = context->network_delegate(); | 70 net::NetworkDelegate* delegate = context->network_delegate(); |
67 if (delegate->CanEnablePrivacyMode(url, first_party_for_cookies)) | 71 if (delegate->CanEnablePrivacyMode(url, first_party_for_cookies)) |
68 request_info.privacy_mode = net::kPrivacyModeEnabled; | 72 request_info.privacy_mode = net::kPrivacyModeEnabled; |
69 | 73 |
70 // It almost doesn't matter whether we use net::LOWEST or net::HIGHEST | 74 // It almost doesn't matter whether we use net::LOWEST or net::HIGHEST |
71 // priority here, as we won't make a request, and will surrender the created | 75 // priority here, as we won't make a request, and will surrender the created |
72 // socket to the pool as soon as we can. However, we would like to mark the | 76 // socket to the pool as soon as we can. However, we would like to mark the |
73 // speculative socket as such, and IF we use a net::LOWEST priority, and if | 77 // speculative socket as such, and IF we use a net::LOWEST priority, and if |
74 // a navigation asked for a socket (after us) then it would get our socket, | 78 // a navigation asked for a socket (after us) then it would get our socket, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 112 |
109 // All preconnects should perform EV certificate verification. | 113 // All preconnects should perform EV certificate verification. |
110 ssl_config.verify_ev_cert = true; | 114 ssl_config.verify_ev_cert = true; |
111 | 115 |
112 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); | 116 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
113 http_stream_factory->PreconnectStreams(count, request_info, priority, | 117 http_stream_factory->PreconnectStreams(count, request_info, priority, |
114 ssl_config, ssl_config); | 118 ssl_config, ssl_config); |
115 } | 119 } |
116 | 120 |
117 } // namespace chrome_browser_net | 121 } // namespace chrome_browser_net |
OLD | NEW |