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

Side by Side Diff: chrome/browser/net/preconnect.cc

Issue 1131293004: Add cross origin to Blink-driven preconnect (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more build issues Created 5 years, 4 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/preconnect.h ('k') | chrome/browser/net/predictor.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/net/preconnect.h" 5 #include "chrome/browser/net/preconnect.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 #include "net/base/load_flags.h"
11 #include "net/http/http_network_session.h" 12 #include "net/http/http_network_session.h"
12 #include "net/http/http_request_info.h" 13 #include "net/http/http_request_info.h"
13 #include "net/http/http_stream_factory.h" 14 #include "net/http/http_stream_factory.h"
14 #include "net/http/http_transaction_factory.h" 15 #include "net/http/http_transaction_factory.h"
15 #include "net/log/net_log.h" 16 #include "net/log/net_log.h"
16 #include "net/ssl/ssl_config_service.h" 17 #include "net/ssl/ssl_config_service.h"
17 #include "net/url_request/http_user_agent_settings.h" 18 #include "net/url_request/http_user_agent_settings.h"
18 #include "net/url_request/url_request_context.h" 19 #include "net/url_request/url_request_context.h"
19 #include "net/url_request/url_request_context_getter.h" 20 #include "net/url_request/url_request_context_getter.h"
20 21
21 using content::BrowserThread; 22 using content::BrowserThread;
22 23
23 namespace chrome_browser_net { 24 namespace chrome_browser_net {
24 25
25 void PreconnectOnUIThread( 26 void PreconnectOnUIThread(
26 const GURL& url, 27 const GURL& url,
27 const GURL& first_party_for_cookies, 28 const GURL& first_party_for_cookies,
28 UrlInfo::ResolutionMotivation motivation, 29 UrlInfo::ResolutionMotivation motivation,
29 int count, 30 int count,
30 net::URLRequestContextGetter* getter) { 31 net::URLRequestContextGetter* getter) {
31 // Prewarm connection to Search URL. 32 // Prewarm connection to Search URL.
32 BrowserThread::PostTask( 33 BrowserThread::PostTask(
33 BrowserThread::IO, 34 BrowserThread::IO, FROM_HERE,
34 FROM_HERE,
35 base::Bind(&PreconnectOnIOThread, url, first_party_for_cookies, 35 base::Bind(&PreconnectOnIOThread, url, first_party_for_cookies,
36 motivation, count, make_scoped_refptr(getter))); 36 motivation, count, make_scoped_refptr(getter), true));
37 return; 37 return;
38 } 38 }
39 39
40 40 void PreconnectOnIOThread(const GURL& url,
41 void PreconnectOnIOThread( 41 const GURL& first_party_for_cookies,
42 const GURL& url, 42 UrlInfo::ResolutionMotivation motivation,
43 const GURL& first_party_for_cookies, 43 int count,
44 UrlInfo::ResolutionMotivation motivation, 44 net::URLRequestContextGetter* getter,
45 int count, 45 bool allow_credentials) {
46 net::URLRequestContextGetter* getter) {
47 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { 46 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
48 LOG(DFATAL) << "This must be run only on the IO thread."; 47 LOG(DFATAL) << "This must be run only on the IO thread.";
49 return; 48 return;
50 } 49 }
51 if (!getter) 50 if (!getter)
52 return; 51 return;
53 // We are now commited to doing the async preconnection call. 52 // We are now commited to doing the async preconnection call.
54 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectMotivation", motivation, 53 UMA_HISTOGRAM_ENUMERATION("Net.PreconnectMotivation", motivation,
55 UrlInfo::MAX_MOTIVATED); 54 UrlInfo::MAX_MOTIVATED);
56 55
57 net::URLRequestContext* context = getter->GetURLRequestContext(); 56 net::URLRequestContext* context = getter->GetURLRequestContext();
58 net::HttpTransactionFactory* factory = context->http_transaction_factory(); 57 net::HttpTransactionFactory* factory = context->http_transaction_factory();
59 net::HttpNetworkSession* session = factory->GetSession(); 58 net::HttpNetworkSession* session = factory->GetSession();
60 59
61 std::string user_agent; 60 std::string user_agent;
62 if (context->http_user_agent_settings()) 61 if (context->http_user_agent_settings())
63 user_agent = context->http_user_agent_settings()->GetUserAgent(); 62 user_agent = context->http_user_agent_settings()->GetUserAgent();
64 net::HttpRequestInfo request_info; 63 net::HttpRequestInfo request_info;
65 request_info.url = url; 64 request_info.url = url;
66 request_info.method = "GET"; 65 request_info.method = "GET";
67 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent, 66 request_info.extra_headers.SetHeader(net::HttpRequestHeaders::kUserAgent,
68 user_agent); 67 user_agent);
69 68
70 net::NetworkDelegate* delegate = context->network_delegate(); 69 net::NetworkDelegate* delegate = context->network_delegate();
71 if (delegate->CanEnablePrivacyMode(url, first_party_for_cookies)) 70 // TODO(yoav): Fix this layering violation, since when credentials are not
71 // allowed we should turn on a flag indicating that, rather then turn on
72 // private mode, even if lower layers would treat both the same.
73 if (delegate->CanEnablePrivacyMode(url, first_party_for_cookies) ||
74 !allow_credentials)
72 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED; 75 request_info.privacy_mode = net::PRIVACY_MODE_ENABLED;
Ryan Sleevi 2015/07/23 18:22:41 Sorry, I'm still out rather sick, but saw this end
73 76
74 // Translate the motivation from UrlRequest motivations to HttpRequest 77 // Translate the motivation from UrlRequest motivations to HttpRequest
75 // motivations. 78 // motivations.
76 switch (motivation) { 79 switch (motivation) {
77 case UrlInfo::OMNIBOX_MOTIVATED: 80 case UrlInfo::OMNIBOX_MOTIVATED:
78 request_info.motivation = net::HttpRequestInfo::OMNIBOX_MOTIVATED; 81 request_info.motivation = net::HttpRequestInfo::OMNIBOX_MOTIVATED;
79 break; 82 break;
80 case UrlInfo::LEARNED_REFERAL_MOTIVATED: 83 case UrlInfo::LEARNED_REFERAL_MOTIVATED:
81 request_info.motivation = net::HttpRequestInfo::PRECONNECT_MOTIVATED; 84 request_info.motivation = net::HttpRequestInfo::PRECONNECT_MOTIVATED;
82 break; 85 break;
(...skipping 15 matching lines...) Expand all
98 101
99 // All preconnects should perform EV certificate verification. 102 // All preconnects should perform EV certificate verification.
100 ssl_config.verify_ev_cert = true; 103 ssl_config.verify_ev_cert = true;
101 104
102 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory(); 105 net::HttpStreamFactory* http_stream_factory = session->http_stream_factory();
103 http_stream_factory->PreconnectStreams(count, request_info, ssl_config, 106 http_stream_factory->PreconnectStreams(count, request_info, ssl_config,
104 ssl_config); 107 ssl_config);
105 } 108 }
106 109
107 } // namespace chrome_browser_net 110 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/preconnect.h ('k') | chrome/browser/net/predictor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698