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