Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/predictor.h" | 5 #include "chrome/browser/net/predictor.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 BrowserThread::PostTask( | 235 BrowserThread::PostTask( |
| 236 BrowserThread::IO, FROM_HERE, | 236 BrowserThread::IO, FROM_HERE, |
| 237 base::BindOnce(&Predictor::Resolve, base::Unretained(this), | 237 base::BindOnce(&Predictor::Resolve, base::Unretained(this), |
| 238 CanonicalizeUrl(url), motivation)); | 238 CanonicalizeUrl(url), motivation)); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void Predictor::PreconnectUrlAndSubresources(const GURL& url, | 241 void Predictor::PreconnectUrlAndSubresources(const GURL& url, |
| 242 const GURL& first_party_for_cookies) { | 242 const GURL& first_party_for_cookies) { |
| 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 244 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 244 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 245 if (!PredictorEnabled() || !url.is_valid() || | 245 if (!PredictorEnabled()) |
| 246 !url.has_host()) | |
| 247 return; | 246 return; |
| 248 if (!CanPreresolveAndPreconnect()) | 247 if (!CanPreresolveAndPreconnect()) |
| 249 return; | 248 return; |
| 250 | 249 GURL canonicalized_url = CanonicalizeUrl(url); |
|
Charlie Harrison
2017/05/15 17:01:25
nit: const GURL
xunjieli
2017/05/15 17:06:50
Done.
| |
| 250 if (!canonicalized_url.is_valid() || !canonicalized_url.has_host()) | |
| 251 return; | |
| 251 UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED); | 252 UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED); |
| 252 const int kConnectionsNeeded = 1; | 253 const int kConnectionsNeeded = 1; |
| 253 PreconnectUrl(CanonicalizeUrl(url), first_party_for_cookies, motivation, | 254 PreconnectUrl(canonicalized_url, first_party_for_cookies, motivation, |
| 254 kConnectionsNeeded, kAllowCredentialsOnPreconnectByDefault); | 255 kConnectionsNeeded, kAllowCredentialsOnPreconnectByDefault); |
| 255 PredictFrameSubresources(url.GetWithEmptyPath(), first_party_for_cookies); | 256 PredictFrameSubresources(canonicalized_url.GetWithEmptyPath(), |
| 257 first_party_for_cookies); | |
| 256 } | 258 } |
| 257 | 259 |
| 258 std::vector<GURL> Predictor::GetPredictedUrlListAtStartup( | 260 std::vector<GURL> Predictor::GetPredictedUrlListAtStartup( |
| 259 PrefService* user_prefs) { | 261 PrefService* user_prefs) { |
| 260 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 262 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 261 std::vector<GURL> urls; | 263 std::vector<GURL> urls; |
| 262 // Recall list of URLs we learned about during last session. | 264 // Recall list of URLs we learned about during last session. |
| 263 // This may catch secondary hostnames, pulled in by the homepages. It will | 265 // This may catch secondary hostnames, pulled in by the homepages. It will |
| 264 // also catch more of the "primary" home pages, since that was (presumably) | 266 // also catch more of the "primary" home pages, since that was (presumably) |
| 265 // rendered first (and will be rendered first this time too). | 267 // rendered first (and will be rendered first this time too). |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 SerializeReferrers(referral_list); | 720 SerializeReferrers(referral_list); |
| 719 } | 721 } |
| 720 | 722 |
| 721 void Predictor::PreconnectUrl(const GURL& url, | 723 void Predictor::PreconnectUrl(const GURL& url, |
| 722 const GURL& first_party_for_cookies, | 724 const GURL& first_party_for_cookies, |
| 723 UrlInfo::ResolutionMotivation motivation, | 725 UrlInfo::ResolutionMotivation motivation, |
| 724 bool allow_credentials, | 726 bool allow_credentials, |
| 725 int count) { | 727 int count) { |
| 726 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 727 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 729 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 730 DCHECK(url.is_valid()); | |
| 728 | 731 |
| 729 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 732 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 730 PreconnectUrlOnIOThread(url, first_party_for_cookies, motivation, | 733 PreconnectUrlOnIOThread(url, first_party_for_cookies, motivation, |
| 731 allow_credentials, count); | 734 allow_credentials, count); |
| 732 } else { | 735 } else { |
| 733 BrowserThread::PostTask( | 736 BrowserThread::PostTask( |
| 734 BrowserThread::IO, FROM_HERE, | 737 BrowserThread::IO, FROM_HERE, |
| 735 base::BindOnce(&Predictor::PreconnectUrlOnIOThread, | 738 base::BindOnce(&Predictor::PreconnectUrlOnIOThread, |
| 736 base::Unretained(this), url, first_party_for_cookies, | 739 base::Unretained(this), url, first_party_for_cookies, |
| 737 motivation, allow_credentials, count)); | 740 motivation, allow_credentials, count)); |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1197 } | 1200 } |
| 1198 | 1201 |
| 1199 void SimplePredictor::ShutdownOnUIThread() { | 1202 void SimplePredictor::ShutdownOnUIThread() { |
| 1200 SetShutdown(true); | 1203 SetShutdown(true); |
| 1201 } | 1204 } |
| 1202 | 1205 |
| 1203 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } | 1206 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } |
| 1204 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } | 1207 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } |
| 1205 | 1208 |
| 1206 } // namespace chrome_browser_net | 1209 } // namespace chrome_browser_net |
| OLD | NEW |