Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/memory/ptr_util.h" | |
| 6 #include "base/memory/ref_counted.h" | |
| 7 #include "content/public/browser/browser_thread.h" | |
| 8 #include "content/public/browser/resource_context.h" | |
| 5 #include "content/public/browser/resource_hints.h" | 9 #include "content/public/browser/resource_hints.h" |
| 6 | 10 #include "net/base/address_list.h" |
| 7 #include "content/public/browser/browser_thread.h" | |
| 8 #include "net/base/load_flags.h" | 11 #include "net/base/load_flags.h" |
| 12 #include "net/dns/host_resolver.h" | |
| 13 #include "net/dns/single_request_host_resolver.h" | |
| 9 #include "net/http/http_network_session.h" | 14 #include "net/http/http_network_session.h" |
| 10 #include "net/http/http_request_info.h" | 15 #include "net/http/http_request_info.h" |
| 11 #include "net/http/http_stream_factory.h" | 16 #include "net/http/http_stream_factory.h" |
| 12 #include "net/http/http_transaction_factory.h" | 17 #include "net/http/http_transaction_factory.h" |
| 13 #include "net/url_request/http_user_agent_settings.h" | 18 #include "net/url_request/http_user_agent_settings.h" |
| 14 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 15 #include "net/url_request/url_request_context_getter.h" | |
| 16 | 20 |
| 17 namespace content { | 21 namespace content { |
| 18 | 22 |
| 19 void PreconnectUrl(net::URLRequestContextGetter* getter, | 23 namespace { |
| 24 | |
| 25 // Note that |request| and |addresses| will be deleted when this function | |
|
eroman
2016/06/01 15:27:38
nit: How about phrasing this as: the lifetime of "
| |
| 26 // returns. | |
| 27 void OnResolveComplete(net::SingleRequestHostResolver* request, | |
| 28 net::AddressList* addresses, | |
| 29 const net::CompletionCallback& callback, | |
| 30 int result) { | |
| 31 // Plumb the resolution result into the callback if future consumers want | |
| 32 // that information. | |
| 33 callback.Run(result); | |
| 34 } | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 void PreconnectUrl(content::ResourceContext* resource_context, | |
| 20 const GURL& url, | 39 const GURL& url, |
| 21 const GURL& first_party_for_cookies, | 40 const GURL& first_party_for_cookies, |
| 22 int count, | 41 int count, |
| 23 bool allow_credentials, | 42 bool allow_credentials, |
| 24 net::HttpRequestInfo::RequestMotivation motivation) { | 43 net::HttpRequestInfo::RequestMotivation motivation) { |
| 25 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 44 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 26 DCHECK(getter); | 45 DCHECK(resource_context); |
| 27 | 46 |
| 28 net::URLRequestContext* context = getter->GetURLRequestContext(); | 47 net::URLRequestContext* context = resource_context->GetRequestContext(); |
| 29 net::HttpTransactionFactory* factory = context->http_transaction_factory(); | 48 net::HttpTransactionFactory* factory = context->http_transaction_factory(); |
| 30 net::HttpNetworkSession* session = factory->GetSession(); | 49 net::HttpNetworkSession* session = factory->GetSession(); |
| 31 | 50 |
| 32 std::string user_agent; | 51 std::string user_agent; |
| 33 if (context->http_user_agent_settings()) | 52 if (context->http_user_agent_settings()) |
| 34 user_agent = context->http_user_agent_settings()->GetUserAgent(); | 53 user_agent = context->http_user_agent_settings()->GetUserAgent(); |
| 35 net::HttpRequestInfo request_info; | 54 net::HttpRequestInfo request_info; |
| 36 request_info.url = url; | 55 request_info.url = url; |
| 37 request_info.method = "GET"; | 56 request_info.method = "GET"; |
| 38 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, | 57 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 50 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED; | 69 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED; |
| 51 request_info.load_flags = net::LOAD_DO_NOT_SEND_COOKIES | | 70 request_info.load_flags = net::LOAD_DO_NOT_SEND_COOKIES | |
| 52 net::LOAD_DO_NOT_SAVE_COOKIES | | 71 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 53 net::LOAD_DO_NOT_SEND_AUTH_DATA; | 72 net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 54 } | 73 } |
| 55 | 74 |
| 56 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); | 75 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 57 http_stream_factory->PreconnectStreams(count, request_info); | 76 http_stream_factory->PreconnectStreams(count, request_info); |
| 58 } | 77 } |
| 59 | 78 |
| 79 int PreresolveUrl(content::ResourceContext* resource_context, | |
| 80 const GURL& url, | |
| 81 const net::CompletionCallback& callback) { | |
| 82 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 83 DCHECK(resource_context); | |
| 84 | |
| 85 net::AddressList* addresses = new net::AddressList; | |
| 86 net::SingleRequestHostResolver* resolver = | |
| 87 new net::SingleRequestHostResolver(resource_context->GetHostResolver()); | |
| 88 net::HostResolver::RequestInfo resolve_info(net::HostPortPair::FromURL(url)); | |
| 89 return resolver->Resolve(resolve_info, net::IDLE, addresses, | |
| 90 base::Bind(&OnResolveComplete, base::Owned(resolver), | |
| 91 base::Owned(addresses), callback), | |
| 92 net::BoundNetLog()); | |
| 93 } | |
| 94 | |
| 60 } // namespace content | 95 } // namespace content |
| OLD | NEW |