Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(701)

Side by Side Diff: content/browser/loader/resource_hints_impl.cc

Issue 2004453002: Add a Dns preresolve interface in //content (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@predictor_dns_browsertest
Patch Set: Changed interface to accept ResourceContexts Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 DCHECK(resource_context);
27 29
28 net::URLRequestContext* context = getter->GetURLRequestContext(); 30 net::URLRequestContext* context = resource_context->GetRequestContext();
29 net::HttpTransactionFactory* factory = context->http_transaction_factory(); 31 net::HttpTransactionFactory* factory = context->http_transaction_factory();
30 net::HttpNetworkSession* session = factory->GetSession(); 32 net::HttpNetworkSession* session = factory->GetSession();
31 33
32 std::string user_agent; 34 std::string user_agent;
33 if (context->http_user_agent_settings()) 35 if (context->http_user_agent_settings())
34 user_agent = context->http_user_agent_settings()->GetUserAgent(); 36 user_agent = context->http_user_agent_settings()->GetUserAgent();
35 net::HttpRequestInfo request_info; 37 net::HttpRequestInfo request_info;
36 request_info.url = url; 38 request_info.url = url;
37 request_info.method = "GET"; 39 request_info.method = "GET";
38 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, 40 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent,
(...skipping 11 matching lines...) Expand all
50 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED; 52 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED;
51 request_info.load_flags = net::LOAD_DO_NOT_SEND_COOKIES | 53 request_info.load_flags = net::LOAD_DO_NOT_SEND_COOKIES |
52 net::LOAD_DO_NOT_SAVE_COOKIES | 54 net::LOAD_DO_NOT_SAVE_COOKIES |
53 net::LOAD_DO_NOT_SEND_AUTH_DATA; 55 net::LOAD_DO_NOT_SEND_AUTH_DATA;
54 } 56 }
55 57
56 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); 58 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory();
57 http_stream_factory->PreconnectStreams(count, request_info); 59 http_stream_factory->PreconnectStreams(count, request_info);
58 } 60 }
59 61
62 int PreresolveUrl(content::ResourceContext* resource_context,
63 const GURL& url,
64 const net::CompletionCallback& callback) {
65 DCHECK_CURRENTLY_ON(BrowserThread::IO);
66 ResourceDispatcherHostImpl* dispatcher_host =
67 ResourceDispatcherHostImpl::Get();
68 DCHECK(dispatcher_host);
69 ResourceHintsController* controller =
70 dispatcher_host->resource_hints_controller();
71 return controller->PreresolveUrl(resource_context, url, callback);
72 }
73
60 } // namespace content 74 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698