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

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

Issue 1881463003: Add a browsertest suite for net predictor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor, disable preconnect + intercept request for determinism 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 (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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 if (!CanPreresolveAndPreconnect()) 228 if (!CanPreresolveAndPreconnect())
229 return; 229 return;
230 230
231 std::string host = url.HostNoBrackets(); 231 std::string host = url.HostNoBrackets();
232 bool is_new_host_request = (host != last_omnibox_host_); 232 bool is_new_host_request = (host != last_omnibox_host_);
233 last_omnibox_host_ = host; 233 last_omnibox_host_ = host;
234 234
235 UrlInfo::ResolutionMotivation motivation(UrlInfo::OMNIBOX_MOTIVATED); 235 UrlInfo::ResolutionMotivation motivation(UrlInfo::OMNIBOX_MOTIVATED);
236 base::TimeTicks now = base::TimeTicks::Now(); 236 base::TimeTicks now = base::TimeTicks::Now();
237 237
238 if (preconnect_enabled_) { 238 if (preconnect_enabled()) {
239 if (preconnectable && !is_new_host_request) { 239 if (preconnectable && !is_new_host_request) {
240 ++consecutive_omnibox_preconnect_count_; 240 ++consecutive_omnibox_preconnect_count_;
241 // The omnibox suggests a search URL (for which we can preconnect) after 241 // The omnibox suggests a search URL (for which we can preconnect) after
242 // one or two characters are typed, even though such typing often (1 in 242 // one or two characters are typed, even though such typing often (1 in
243 // 3?) becomes a real URL. This code waits till is has more evidence of a 243 // 3?) becomes a real URL. This code waits till is has more evidence of a
244 // preconnectable URL (search URL) before forming a preconnection, so as 244 // preconnectable URL (search URL) before forming a preconnection, so as
245 // to reduce the useless preconnect rate. 245 // to reduce the useless preconnect rate.
246 // Perchance this logic should be pushed back into the omnibox, where the 246 // Perchance this logic should be pushed back into the omnibox, where the
247 // actual characters typed, such as a space, can better forcast whether 247 // actual characters typed, such as a space, can better forcast whether
248 // we need to search/preconnect or not. By waiting for at least 4 248 // we need to search/preconnect or not. By waiting for at least 4
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 BrowserThread::IO, 292 BrowserThread::IO,
293 FROM_HERE, 293 FROM_HERE,
294 base::Bind(&Predictor::Resolve, base::Unretained(this), 294 base::Bind(&Predictor::Resolve, base::Unretained(this),
295 CanonicalizeUrl(url), motivation)); 295 CanonicalizeUrl(url), motivation));
296 } 296 }
297 297
298 void Predictor::PreconnectUrlAndSubresources(const GURL& url, 298 void Predictor::PreconnectUrlAndSubresources(const GURL& url,
299 const GURL& first_party_for_cookies) { 299 const GURL& first_party_for_cookies) {
300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
301 BrowserThread::CurrentlyOn(BrowserThread::IO)); 301 BrowserThread::CurrentlyOn(BrowserThread::IO));
302 if (!predictor_enabled_ || !preconnect_enabled_ || 302 if (!predictor_enabled_ || !preconnect_enabled() || !url.is_valid() ||
303 !url.is_valid() || !url.has_host()) 303 !url.has_host())
304 return; 304 return;
305 if (!CanPreresolveAndPreconnect()) 305 if (!CanPreresolveAndPreconnect())
306 return; 306 return;
307 307
308 UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED); 308 UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED);
309 const int kConnectionsNeeded = 1; 309 const int kConnectionsNeeded = 1;
310 PreconnectUrl(CanonicalizeUrl(url), first_party_for_cookies, motivation, 310 PreconnectUrl(CanonicalizeUrl(url), first_party_for_cookies, motivation,
311 kConnectionsNeeded, kAllowCredentialsOnPreconnectByDefault); 311 kConnectionsNeeded, kAllowCredentialsOnPreconnectByDefault);
312 PredictFrameSubresources(url.GetWithEmptyPath(), first_party_for_cookies); 312 PredictFrameSubresources(url.GetWithEmptyPath(), first_party_for_cookies);
313 } 313 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 void Predictor::LearnFromNavigation(const GURL& referring_url, 458 void Predictor::LearnFromNavigation(const GURL& referring_url,
459 const GURL& target_url) { 459 const GURL& target_url) {
460 DCHECK_CURRENTLY_ON(BrowserThread::IO); 460 DCHECK_CURRENTLY_ON(BrowserThread::IO);
461 if (!predictor_enabled_ || !CanPreresolveAndPreconnect()) 461 if (!predictor_enabled_ || !CanPreresolveAndPreconnect())
462 return; 462 return;
463 DCHECK_EQ(referring_url, Predictor::CanonicalizeUrl(referring_url)); 463 DCHECK_EQ(referring_url, Predictor::CanonicalizeUrl(referring_url));
464 DCHECK_NE(referring_url, GURL::EmptyGURL()); 464 DCHECK_NE(referring_url, GURL::EmptyGURL());
465 DCHECK_EQ(target_url, Predictor::CanonicalizeUrl(target_url)); 465 DCHECK_EQ(target_url, Predictor::CanonicalizeUrl(target_url));
466 DCHECK_NE(target_url, GURL::EmptyGURL()); 466 DCHECK_NE(target_url, GURL::EmptyGURL());
467 467
468 if (observer_)
469 observer_->OnLearnFromNavigation(referring_url, target_url);
468 referrers_[referring_url].SuggestHost(target_url); 470 referrers_[referring_url].SuggestHost(target_url);
469 // Possibly do some referrer trimming. 471 // Possibly do some referrer trimming.
470 TrimReferrers(); 472 TrimReferrers();
471 } 473 }
472 474
473 //----------------------------------------------------------------------------- 475 //-----------------------------------------------------------------------------
474 // This section supports the about:dns page. 476 // This section supports the about:dns page.
475 477
476 void Predictor::PredictorGetHtmlInfo(Predictor* predictor, 478 void Predictor::PredictorGetHtmlInfo(Predictor* predictor,
477 std::string* output) { 479 std::string* output) {
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 DCHECK_CURRENTLY_ON(BrowserThread::IO); 935 DCHECK_CURRENTLY_ON(BrowserThread::IO);
934 DCHECK_EQ(url.GetWithEmptyPath(), url); 936 DCHECK_EQ(url.GetWithEmptyPath(), url);
935 Referrers::iterator it = referrers_.find(url); 937 Referrers::iterator it = referrers_.find(url);
936 if (referrers_.end() == it) { 938 if (referrers_.end() == it) {
937 // Only when we don't know anything about this url, make 2 connections 939 // Only when we don't know anything about this url, make 2 connections
938 // available. We could do this completely via learning (by prepopulating 940 // available. We could do this completely via learning (by prepopulating
939 // the referrer_ list with this expected value), but it would swell the 941 // the referrer_ list with this expected value), but it would swell the
940 // size of the list with all the "Leaf" nodes in the tree (nodes that don't 942 // size of the list with all the "Leaf" nodes in the tree (nodes that don't
941 // load any subresources). If we learn about this resource, we will instead 943 // load any subresources). If we learn about this resource, we will instead
942 // provide a more carefully estimated preconnection count. 944 // provide a more carefully estimated preconnection count.
943 if (preconnect_enabled_) { 945 if (preconnect_enabled()) {
944 PreconnectUrlOnIOThread(url, first_party_for_cookies, 946 PreconnectUrlOnIOThread(url, first_party_for_cookies,
945 UrlInfo::SELF_REFERAL_MOTIVATED, 947 UrlInfo::SELF_REFERAL_MOTIVATED,
946 kAllowCredentialsOnPreconnectByDefault, 2); 948 kAllowCredentialsOnPreconnectByDefault, 2);
947 } 949 }
948 return; 950 return;
949 } 951 }
950 952
951 Referrer* referrer = &(it->second); 953 Referrer* referrer = &(it->second);
952 referrer->IncrementUseCount(); 954 referrer->IncrementUseCount();
953 const UrlInfo::ResolutionMotivation motivation = 955 const UrlInfo::ResolutionMotivation motivation =
954 UrlInfo::LEARNED_REFERAL_MOTIVATED; 956 UrlInfo::LEARNED_REFERAL_MOTIVATED;
955 for (Referrer::iterator future_url = referrer->begin(); 957 for (Referrer::iterator future_url = referrer->begin();
956 future_url != referrer->end(); ++future_url) { 958 future_url != referrer->end(); ++future_url) {
957 SubresourceValue evalution(TOO_NEW); 959 SubresourceValue evalution(TOO_NEW);
958 double connection_expectation = future_url->second.subresource_use_rate(); 960 double connection_expectation = future_url->second.subresource_use_rate();
959 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.PreconnectSubresourceExpectation", 961 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.PreconnectSubresourceExpectation",
960 static_cast<int>(connection_expectation * 100), 962 static_cast<int>(connection_expectation * 100),
961 10, 5000, 50); 963 10, 5000, 50);
962 future_url->second.ReferrerWasObserved(); 964 future_url->second.ReferrerWasObserved();
963 if (preconnect_enabled_ && 965 if (preconnect_enabled() &&
964 connection_expectation > kPreconnectWorthyExpectedValue) { 966 connection_expectation > kPreconnectWorthyExpectedValue) {
965 evalution = PRECONNECTION; 967 evalution = PRECONNECTION;
966 future_url->second.IncrementPreconnectionCount(); 968 future_url->second.IncrementPreconnectionCount();
967 int count = static_cast<int>(std::ceil(connection_expectation)); 969 int count = static_cast<int>(std::ceil(connection_expectation));
968 if (url.host_piece() == future_url->first.host_piece()) 970 if (url.host_piece() == future_url->first.host_piece())
969 ++count; 971 ++count;
970 PreconnectUrlOnIOThread(future_url->first, first_party_for_cookies, 972 PreconnectUrlOnIOThread(future_url->first, first_party_for_cookies,
971 motivation, 973 motivation,
972 kAllowCredentialsOnPreconnectByDefault, count); 974 kAllowCredentialsOnPreconnectByDefault, count);
973 } else if (connection_expectation > kDNSPreresolutionWorthyExpectedValue) { 975 } else if (connection_expectation > kDNSPreresolutionWorthyExpectedValue) {
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 } 1306 }
1305 1307
1306 void SimplePredictor::ShutdownOnUIThread() { 1308 void SimplePredictor::ShutdownOnUIThread() {
1307 SetShutdown(true); 1309 SetShutdown(true);
1308 } 1310 }
1309 1311
1310 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } 1312 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; }
1311 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } 1313 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; }
1312 1314
1313 } // namespace chrome_browser_net 1315 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698