| 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 the lifetime of |request| and |addresses| is managed by the caller. |
| 26 void OnResolveComplete(net::SingleRequestHostResolver* request, |
| 27 net::AddressList* addresses, |
| 28 const net::CompletionCallback& callback, |
| 29 int result) { |
| 30 // Plumb the resolution result into the callback if future consumers want |
| 31 // that information. |
| 32 callback.Run(result); |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
| 37 void PreconnectUrl(content::ResourceContext* resource_context, |
| 20 const GURL& url, | 38 const GURL& url, |
| 21 const GURL& first_party_for_cookies, | 39 const GURL& first_party_for_cookies, |
| 22 int count, | 40 int count, |
| 23 bool allow_credentials, | 41 bool allow_credentials, |
| 24 net::HttpRequestInfo::RequestMotivation motivation) { | 42 net::HttpRequestInfo::RequestMotivation motivation) { |
| 25 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 43 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 26 DCHECK(getter); | 44 DCHECK(resource_context); |
| 27 | 45 |
| 28 net::URLRequestContext* context = getter->GetURLRequestContext(); | 46 net::URLRequestContext* context = resource_context->GetRequestContext(); |
| 29 net::HttpTransactionFactory* factory = context->http_transaction_factory(); | 47 net::HttpTransactionFactory* factory = context->http_transaction_factory(); |
| 30 net::HttpNetworkSession* session = factory->GetSession(); | 48 net::HttpNetworkSession* session = factory->GetSession(); |
| 31 | 49 |
| 32 std::string user_agent; | 50 std::string user_agent; |
| 33 if (context->http_user_agent_settings()) | 51 if (context->http_user_agent_settings()) |
| 34 user_agent = context->http_user_agent_settings()->GetUserAgent(); | 52 user_agent = context->http_user_agent_settings()->GetUserAgent(); |
| 35 net::HttpRequestInfo request_info; | 53 net::HttpRequestInfo request_info; |
| 36 request_info.url = url; | 54 request_info.url = url; |
| 37 request_info.method = "GET"; | 55 request_info.method = "GET"; |
| 38 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, | 56 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 50 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED; | 68 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED; |
| 51 request_info.load_flags = net::LOAD_DO_NOT_SEND_COOKIES | | 69 request_info.load_flags = net::LOAD_DO_NOT_SEND_COOKIES | |
| 52 net::LOAD_DO_NOT_SAVE_COOKIES | | 70 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 53 net::LOAD_DO_NOT_SEND_AUTH_DATA; | 71 net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 54 } | 72 } |
| 55 | 73 |
| 56 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); | 74 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 57 http_stream_factory->PreconnectStreams(count, request_info); | 75 http_stream_factory->PreconnectStreams(count, request_info); |
| 58 } | 76 } |
| 59 | 77 |
| 78 int PreresolveUrl(content::ResourceContext* resource_context, |
| 79 const GURL& url, |
| 80 const net::CompletionCallback& callback) { |
| 81 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 82 DCHECK(resource_context); |
| 83 |
| 84 net::AddressList* addresses = new net::AddressList; |
| 85 net::SingleRequestHostResolver* resolver = |
| 86 new net::SingleRequestHostResolver(resource_context->GetHostResolver()); |
| 87 net::HostResolver::RequestInfo resolve_info(net::HostPortPair::FromURL(url)); |
| 88 return resolver->Resolve(resolve_info, net::IDLE, addresses, |
| 89 base::Bind(&OnResolveComplete, base::Owned(resolver), |
| 90 base::Owned(addresses), callback), |
| 91 net::BoundNetLog()); |
| 92 } |
| 93 |
| 60 } // namespace content | 94 } // namespace content |
| OLD | NEW |