Chromium Code Reviews| 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/load_flags.h" | |
| 11 #include "net/http/http_network_session.h" | 12 #include "net/http/http_network_session.h" |
| 12 #include "net/http/http_request_info.h" | 13 #include "net/http/http_request_info.h" |
| 13 #include "net/http/http_stream_factory.h" | 14 #include "net/http/http_stream_factory.h" |
| 14 #include "net/http/http_transaction_factory.h" | 15 #include "net/http/http_transaction_factory.h" |
| 15 #include "net/log/net_log.h" | 16 #include "net/log/net_log.h" |
| 16 #include "net/ssl/ssl_config_service.h" | 17 #include "net/ssl/ssl_config_service.h" |
| 17 #include "net/url_request/http_user_agent_settings.h" | 18 #include "net/url_request/http_user_agent_settings.h" |
| 18 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 19 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 20 | 21 |
| 21 using content::BrowserThread; | 22 using content::BrowserThread; |
| 22 | 23 |
| 23 namespace chrome_browser_net { | 24 namespace chrome_browser_net { |
| 24 | 25 |
| 25 void PreconnectOnUIThread( | 26 void PreconnectOnUIThread( |
| 26 const GURL& url, | 27 const GURL& url, |
| 27 const GURL& first_party_for_cookies, | 28 const GURL& first_party_for_cookies, |
| 28 UrlInfo::ResolutionMotivation motivation, | 29 UrlInfo::ResolutionMotivation motivation, |
| 29 int count, | 30 int count, |
| 30 net::URLRequestContextGetter* getter) { | 31 net::URLRequestContextGetter* getter) { |
| 31 // Prewarm connection to Search URL. | 32 // Prewarm connection to Search URL. |
| 32 BrowserThread::PostTask( | 33 BrowserThread::PostTask( |
| 33 BrowserThread::IO, | 34 BrowserThread::IO, |
| 34 FROM_HERE, | 35 FROM_HERE, |
| 35 base::Bind(&PreconnectOnIOThread, url, first_party_for_cookies, | 36 base::Bind(&PreconnectOnIOThread, url, first_party_for_cookies, |
| 36 motivation, count, make_scoped_refptr(getter))); | 37 motivation, count, make_scoped_refptr(getter), false)); |
| 37 return; | 38 return; |
| 38 } | 39 } |
| 39 | 40 |
| 40 | 41 |
| 41 void PreconnectOnIOThread( | 42 void PreconnectOnIOThread( |
| 42 const GURL& url, | 43 const GURL& url, |
| 43 const GURL& first_party_for_cookies, | 44 const GURL& first_party_for_cookies, |
| 44 UrlInfo::ResolutionMotivation motivation, | 45 UrlInfo::ResolutionMotivation motivation, |
| 45 int count, | 46 int count, |
| 46 net::URLRequestContextGetter* getter) { | 47 net::URLRequestContextGetter* getter, |
| 48 bool is_credentials_flag_set) { | |
| 47 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 49 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 48 LOG(DFATAL) << "This must be run only on the IO thread."; | 50 LOG(DFATAL) << "This must be run only on the IO thread."; |
| 49 return; | 51 return; |
| 50 } | 52 } |
| 51 if (!getter) | 53 if (!getter) |
| 52 return; | 54 return; |
| 53 // We are now commited to doing the async preconnection call. | 55 // We are now commited to doing the async preconnection call. |
| 54 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectMotivation", motivation, | 56 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectMotivation", motivation, |
| 55 UrlInfo::MAX_MOTIVATED); | 57 UrlInfo::MAX_MOTIVATED); |
| 56 | 58 |
| 57 net::URLRequestContext* context = getter->GetURLRequestContext(); | 59 net::URLRequestContext* context = getter->GetURLRequestContext(); |
| 58 net::HttpTransactionFactory* factory = context->http_transaction_factory(); | 60 net::HttpTransactionFactory* factory = context->http_transaction_factory(); |
| 59 net::HttpNetworkSession* session = factory->GetSession(); | 61 net::HttpNetworkSession* session = factory->GetSession(); |
| 60 | 62 |
| 61 std::string user_agent; | 63 std::string user_agent; |
| 62 if (context->http_user_agent_settings()) | 64 if (context->http_user_agent_settings()) |
| 63 user_agent = context->http_user_agent_settings()->GetUserAgent(); | 65 user_agent = context->http_user_agent_settings()->GetUserAgent(); |
| 64 net::HttpRequestInfo request_info; | 66 net::HttpRequestInfo request_info; |
| 65 request_info.url = url; | 67 request_info.url = url; |
| 66 request_info.method = "GET"; | 68 request_info.method = "GET"; |
| 67 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, | 69 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, |
| 68 user_agent); | 70 user_agent); |
| 69 | 71 |
| 70 net::NetworkDelegate* delegate = context->network_delegate(); | 72 net::NetworkDelegate* delegate = context->network_delegate(); |
| 71 if (delegate->CanEnablePrivacyMode(url, first_party_for_cookies)) | 73 if (delegate->CanEnablePrivacyMode(url, first_party_for_cookies) |
| 74 || !is_credentials_flag_set) | |
|
Ryan Sleevi
2015/06/11 22:20:15
To be clear: You're going to need to dig in to why
| |
| 72 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED; | 75 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED; |
| 73 | 76 |
| 74 // It almost doesn't matter whether we use net::LOWEST or net::HIGHEST | 77 // It almost doesn't matter whether we use net::LOWEST or net::HIGHEST |
| 75 // priority here, as we won't make a request, and will surrender the created | 78 // priority here, as we won't make a request, and will surrender the created |
| 76 // socket to the pool as soon as we can. However, we would like to mark the | 79 // socket to the pool as soon as we can. However, we would like to mark the |
| 77 // speculative socket as such, and IF we use a net::LOWEST priority, and if | 80 // speculative socket as such, and IF we use a net::LOWEST priority, and if |
| 78 // a navigation asked for a socket (after us) then it would get our socket, | 81 // a navigation asked for a socket (after us) then it would get our socket, |
| 79 // and we'd get its later-arriving socket, which might make us record that | 82 // and we'd get its later-arriving socket, which might make us record that |
| 80 // the speculation didn't help :-/. By using net::HIGHEST, we ensure that | 83 // the speculation didn't help :-/. By using net::HIGHEST, we ensure that |
| 81 // a socket is given to us if "we asked first" and this allows us to mark it | 84 // a socket is given to us if "we asked first" and this allows us to mark it |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 111 | 114 |
| 112 // All preconnects should perform EV certificate verification. | 115 // All preconnects should perform EV certificate verification. |
| 113 ssl_config.verify_ev_cert = true; | 116 ssl_config.verify_ev_cert = true; |
| 114 | 117 |
| 115 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); | 118 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 116 http_stream_factory->PreconnectStreams(count, request_info, priority, | 119 http_stream_factory->PreconnectStreams(count, request_info, priority, |
| 117 ssl_config, ssl_config); | 120 ssl_config, ssl_config); |
| 118 } | 121 } |
| 119 | 122 |
| 120 } // namespace chrome_browser_net | 123 } // namespace chrome_browser_net |
| OLD | NEW |