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

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: Move AddressList to unique_ptr Created 4 years, 6 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
« no previous file with comments | « chrome/browser/net/predictor.cc ('k') | content/public/browser/resource_hints.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 std::unique_ptr<net::AddressList> addresses,
27 const net::CompletionCallback& callback,
28 int result) {
29 // Plumb the resolution result into the callback if future consumers want
30 // that information.
31 callback.Run(result);
32 }
33
34 } // namespace
35
36 void PreconnectUrl(content::ResourceContext* resource_context,
20 const GURL& url, 37 const GURL& url,
21 const GURL& first_party_for_cookies, 38 const GURL& first_party_for_cookies,
22 int count, 39 int count,
23 bool allow_credentials, 40 bool allow_credentials,
24 net::HttpRequestInfo::RequestMotivation motivation) { 41 net::HttpRequestInfo::RequestMotivation motivation) {
25 DCHECK_CURRENTLY_ON(BrowserThread::IO); 42 DCHECK_CURRENTLY_ON(BrowserThread::IO);
26 DCHECK(getter); 43 DCHECK(resource_context);
27 44
28 net::URLRequestContext* context = getter->GetURLRequestContext(); 45 net::URLRequestContext* context = resource_context->GetRequestContext();
29 net::HttpTransactionFactory* factory = context->http_transaction_factory(); 46 net::HttpTransactionFactory* factory = context->http_transaction_factory();
30 net::HttpNetworkSession* session = factory->GetSession(); 47 net::HttpNetworkSession* session = factory->GetSession();
31 48
32 std::string user_agent; 49 std::string user_agent;
33 if (context->http_user_agent_settings()) 50 if (context->http_user_agent_settings())
34 user_agent = context->http_user_agent_settings()->GetUserAgent(); 51 user_agent = context->http_user_agent_settings()->GetUserAgent();
35 net::HttpRequestInfo request_info; 52 net::HttpRequestInfo request_info;
36 request_info.url = url; 53 request_info.url = url;
37 request_info.method = "GET"; 54 request_info.method = "GET";
38 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, 55 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent,
(...skipping 11 matching lines...) Expand all
50 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED; 67 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED;
51 request_info.load_flags = net::LOAD_DO_NOT_SEND_COOKIES | 68 request_info.load_flags = net::LOAD_DO_NOT_SEND_COOKIES |
52 net::LOAD_DO_NOT_SAVE_COOKIES | 69 net::LOAD_DO_NOT_SAVE_COOKIES |
53 net::LOAD_DO_NOT_SEND_AUTH_DATA; 70 net::LOAD_DO_NOT_SEND_AUTH_DATA;
54 } 71 }
55 72
56 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); 73 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory();
57 http_stream_factory->PreconnectStreams(count, request_info); 74 http_stream_factory->PreconnectStreams(count, request_info);
58 } 75 }
59 76
77 int PreresolveUrl(content::ResourceContext* resource_context,
78 const GURL& url,
79 const net::CompletionCallback& callback) {
80 DCHECK_CURRENTLY_ON(BrowserThread::IO);
81 DCHECK(resource_context);
82
83 std::unique_ptr<net::AddressList> addresses =
84 base::WrapUnique(new net::AddressList);
85 // The raw address must be taken before the call to Bind(), due to undefined
86 // argument evaluation.
87 net::AddressList* addresses_raw = addresses.get();
88 net::SingleRequestHostResolver* resolver =
89 new net::SingleRequestHostResolver(resource_context->GetHostResolver());
eroman 2016/05/31 23:03:28 style: a different approach is used for |resolver|
Charlie Harrison 2016/06/01 02:18:15 Yeah I think I agree with you. I'll put up another
90 net::HostResolver::RequestInfo resolve_info(net::HostPortPair::FromURL(url));
91 return resolver->Resolve(
92 resolve_info, net::IDLE, addresses_raw,
93 base::Bind(&OnResolveComplete, base::Passed(base::WrapUnique(resolver)),
94 base::Passed(std::move(addresses)), callback),
95 net::BoundNetLog());
96 }
97
60 } // namespace content 98 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/net/predictor.cc ('k') | content/public/browser/resource_hints.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698