| 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 "content/browser/loader/resource_dispatcher_host_impl.h" |
| 7 #include "content/browser/loader/resource_hints_controller.h" |
| 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "content/public/browser/resource_context.h" |
| 5 #include "content/public/browser/resource_hints.h" | 10 #include "content/public/browser/resource_hints.h" |
| 6 | |
| 7 #include "content/public/browser/browser_thread.h" | |
| 8 #include "net/base/load_flags.h" | 11 #include "net/base/load_flags.h" |
| 9 #include "net/http/http_network_session.h" | 12 #include "net/http/http_network_session.h" |
| 10 #include "net/http/http_request_info.h" | 13 #include "net/http/http_request_info.h" |
| 11 #include "net/http/http_stream_factory.h" | 14 #include "net/http/http_stream_factory.h" |
| 12 #include "net/http/http_transaction_factory.h" | 15 #include "net/http/http_transaction_factory.h" |
| 13 #include "net/url_request/http_user_agent_settings.h" | 16 #include "net/url_request/http_user_agent_settings.h" |
| 14 #include "net/url_request/url_request_context.h" | 17 #include "net/url_request/url_request_context.h" |
| 15 #include "net/url_request/url_request_context_getter.h" | |
| 16 | 18 |
| 17 namespace content { | 19 namespace content { |
| 18 | 20 |
| 19 void PreconnectUrl(net::URLRequestContextGetter* getter, | 21 void PreconnectUrl(content::ResourceContext* resource_context, |
| 20 const GURL& url, | 22 const GURL& url, |
| 21 const GURL& first_party_for_cookies, | 23 const GURL& first_party_for_cookies, |
| 22 int count, | 24 int count, |
| 23 bool allow_credentials, | 25 bool allow_credentials, |
| 24 net::HttpRequestInfo::RequestMotivation motivation) { | 26 net::HttpRequestInfo::RequestMotivation motivation) { |
| 25 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 27 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 26 DCHECK(getter); | 28 if (!resource_context) |
| 29 return; |
| 27 | 30 |
| 28 net::URLRequestContext* context = getter->GetURLRequestContext(); | 31 net::URLRequestContext* context = resource_context->GetRequestContext(); |
| 29 net::HttpTransactionFactory* factory = context->http_transaction_factory(); | 32 net::HttpTransactionFactory* factory = context->http_transaction_factory(); |
| 30 net::HttpNetworkSession* session = factory->GetSession(); | 33 net::HttpNetworkSession* session = factory->GetSession(); |
| 31 | 34 |
| 32 std::string user_agent; | 35 std::string user_agent; |
| 33 if (context->http_user_agent_settings()) | 36 if (context->http_user_agent_settings()) |
| 34 user_agent = context->http_user_agent_settings()->GetUserAgent(); | 37 user_agent = context->http_user_agent_settings()->GetUserAgent(); |
| 35 net::HttpRequestInfo request_info; | 38 net::HttpRequestInfo request_info; |
| 36 request_info.url = url; | 39 request_info.url = url; |
| 37 request_info.method = "GET"; | 40 request_info.method = "GET"; |
| 38 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, | 41 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 50 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED; | 53 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED; |
| 51 request_info.load_flags = net::LOAD_DO_NOT_SEND_COOKIES | | 54 request_info.load_flags = net::LOAD_DO_NOT_SEND_COOKIES | |
| 52 net::LOAD_DO_NOT_SAVE_COOKIES | | 55 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 53 net::LOAD_DO_NOT_SEND_AUTH_DATA; | 56 net::LOAD_DO_NOT_SEND_AUTH_DATA; |
| 54 } | 57 } |
| 55 | 58 |
| 56 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); | 59 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
| 57 http_stream_factory->PreconnectStreams(count, request_info); | 60 http_stream_factory->PreconnectStreams(count, request_info); |
| 58 } | 61 } |
| 59 | 62 |
| 63 int PreresolveUrl(content::ResourceContext* resource_context, |
| 64 const GURL& url, |
| 65 const net::CompletionCallback& callback) { |
| 66 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 67 if (!resource_context) |
| 68 return net::ERR_FAILED; |
| 69 ResourceDispatcherHostImpl* dispatcher_host = |
| 70 ResourceDispatcherHostImpl::Get(); |
| 71 DCHECK(dispatcher_host); |
| 72 ResourceHintsController* controller = |
| 73 dispatcher_host->resource_hints_controller(); |
| 74 return controller->PreresolveUrl(resource_context, url, callback); |
| 75 } |
| 76 |
| 60 } // namespace content | 77 } // namespace content |
| OLD | NEW |