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 <set> | 9 #include <set> |
10 #include <sstream> | 10 #include <sstream> |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 // pool. Currently, we just do a connect, which MAY be reset if we | 255 // pool. Currently, we just do a connect, which MAY be reset if we |
256 // don't use it in 10 secondes!!! As a result, we may do more | 256 // don't use it in 10 secondes!!! As a result, we may do more |
257 // connections, and actually cost the server more than if we did a real | 257 // connections, and actually cost the server more than if we did a real |
258 // get with a fake request (/gen_204 might be the good path on Google). | 258 // get with a fake request (/gen_204 might be the good path on Google). |
259 const int kMaxSearchKeepaliveSeconds(10); | 259 const int kMaxSearchKeepaliveSeconds(10); |
260 if ((now - last_omnibox_preconnect_).InSeconds() < | 260 if ((now - last_omnibox_preconnect_).InSeconds() < |
261 kMaxSearchKeepaliveSeconds) | 261 kMaxSearchKeepaliveSeconds) |
262 return; // We've done a preconnect recently. | 262 return; // We've done a preconnect recently. |
263 last_omnibox_preconnect_ = now; | 263 last_omnibox_preconnect_ = now; |
264 const int kConnectionsNeeded = 1; | 264 const int kConnectionsNeeded = 1; |
265 PreconnectUrl( | 265 PreconnectUrl(CanonicalizeUrl(url), |
266 CanonicalizeUrl(url), GURL(), motivation, kConnectionsNeeded); | 266 GURL(), |
| 267 motivation, |
| 268 kConnectionsNeeded); |
267 return; // Skip pre-resolution, since we'll open a connection. | 269 return; // Skip pre-resolution, since we'll open a connection. |
268 } | 270 } |
269 } else { | 271 } else { |
270 consecutive_omnibox_preconnect_count_ = 0; | 272 consecutive_omnibox_preconnect_count_ = 0; |
271 } | 273 } |
272 } | 274 } |
273 | 275 |
274 // Fall through and consider pre-resolution. | 276 // Fall through and consider pre-resolution. |
275 | 277 |
276 // Omnibox tends to call in pairs (just a few milliseconds apart), and we | 278 // Omnibox tends to call in pairs (just a few milliseconds apart), and we |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 // a frequent occurrence on Android. | 832 // a frequent occurrence on Android. |
831 TrimReferrersNow(); | 833 TrimReferrersNow(); |
832 SerializeReferrers(referral_list); | 834 SerializeReferrers(referral_list); |
833 | 835 |
834 completion->Signal(); | 836 completion->Signal(); |
835 } | 837 } |
836 | 838 |
837 void Predictor::PreconnectUrl(const GURL& url, | 839 void Predictor::PreconnectUrl(const GURL& url, |
838 const GURL& first_party_for_cookies, | 840 const GURL& first_party_for_cookies, |
839 UrlInfo::ResolutionMotivation motivation, | 841 UrlInfo::ResolutionMotivation motivation, |
840 int count) { | 842 int count, |
| 843 bool isAnonymous) { |
841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
842 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 845 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
843 | 846 |
844 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 847 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
845 PreconnectUrlOnIOThread(url, first_party_for_cookies, motivation, count); | 848 PreconnectUrlOnIOThread(url, |
| 849 first_party_for_cookies, |
| 850 motivation, |
| 851 count, |
| 852 isAnonymous); |
846 } else { | 853 } else { |
847 BrowserThread::PostTask( | 854 BrowserThread::PostTask( |
848 BrowserThread::IO, | 855 BrowserThread::IO, |
849 FROM_HERE, | 856 FROM_HERE, |
850 base::Bind(&Predictor::PreconnectUrlOnIOThread, | 857 base::Bind(&Predictor::PreconnectUrlOnIOThread, |
851 base::Unretained(this), url, first_party_for_cookies, | 858 base::Unretained(this), url, first_party_for_cookies, |
852 motivation, count)); | 859 motivation, count, isAnonymous)); |
853 } | 860 } |
854 } | 861 } |
855 | 862 |
856 void Predictor::PreconnectUrlOnIOThread( | 863 void Predictor::PreconnectUrlOnIOThread( |
857 const GURL& original_url, | 864 const GURL& original_url, |
858 const GURL& first_party_for_cookies, | 865 const GURL& first_party_for_cookies, |
859 UrlInfo::ResolutionMotivation motivation, | 866 UrlInfo::ResolutionMotivation motivation, |
860 int count) { | 867 int count, |
| 868 bool isAnonymous) { |
861 // Skip the HSTS redirect. | 869 // Skip the HSTS redirect. |
862 GURL url = GetHSTSRedirectOnIOThread(original_url); | 870 GURL url = GetHSTSRedirectOnIOThread(original_url); |
863 | 871 |
864 if (observer_) { | 872 if (observer_) { |
865 observer_->OnPreconnectUrl( | 873 observer_->OnPreconnectUrl( |
866 url, first_party_for_cookies, motivation, count); | 874 url, first_party_for_cookies, motivation, count); |
867 } | 875 } |
868 | 876 |
869 PreconnectOnIOThread(url, | 877 PreconnectOnIOThread(url, |
870 first_party_for_cookies, | 878 first_party_for_cookies, |
871 motivation, | 879 motivation, |
872 count, | 880 count, |
873 url_request_context_getter_.get()); | 881 url_request_context_getter_.get(), |
| 882 isAnonymous); |
874 } | 883 } |
875 | 884 |
876 void Predictor::PredictFrameSubresources(const GURL& url, | 885 void Predictor::PredictFrameSubresources(const GURL& url, |
877 const GURL& first_party_for_cookies) { | 886 const GURL& first_party_for_cookies) { |
878 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 887 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
879 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 888 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
880 if (!predictor_enabled_) | 889 if (!predictor_enabled_) |
881 return; | 890 return; |
882 if (!CanPreresolveAndPreconnect()) | 891 if (!CanPreresolveAndPreconnect()) |
883 return; | 892 return; |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 } | 1325 } |
1317 | 1326 |
1318 void SimplePredictor::ShutdownOnUIThread() { | 1327 void SimplePredictor::ShutdownOnUIThread() { |
1319 SetShutdown(true); | 1328 SetShutdown(true); |
1320 } | 1329 } |
1321 | 1330 |
1322 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } | 1331 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } |
1323 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } | 1332 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } |
1324 | 1333 |
1325 } // namespace chrome_browser_net | 1334 } // namespace chrome_browser_net |
OLD | NEW |