Index: chrome/browser/net/predictor.cc |
diff --git a/chrome/browser/net/predictor.cc b/chrome/browser/net/predictor.cc |
index 3af1cf3a2b5388e70d6a69964fb21b77574991be..fbcf75f2032537f3f6cbc6dacdafddc1cfd1e5ea 100644 |
--- a/chrome/browser/net/predictor.cc |
+++ b/chrome/browser/net/predictor.cc |
@@ -136,6 +136,8 @@ Predictor::Predictor(bool preconnect_enabled) |
host_resolver_(NULL), |
preconnect_enabled_(preconnect_enabled), |
consecutive_omnibox_preconnect_count_(0), |
+ recent_preconnects_( |
+ TimeDelta::FromSeconds(kMaxUnusedSocketLifetimeSecondsWithoutAGet)), |
next_trim_time_(base::TimeTicks::Now() + |
TimeDelta::FromHours(kDurationBetweenTrimmingsHours)) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
@@ -243,9 +245,8 @@ void Predictor::AnticipateOmniboxUrl(const GURL& url, bool preconnectable) { |
return; // We've done a preconnect recently. |
last_omnibox_preconnect_ = now; |
const int kConnectionsNeeded = 1; |
- PreconnectOnUIThread(CanonicalizeUrl(url), GURL(), motivation, |
- kConnectionsNeeded, |
- url_request_context_getter_); |
+ PreconnectUrl(CanonicalizeUrl(url), GURL(), motivation, |
+ kConnectionsNeeded); |
return; // Skip pre-resolution, since we'll open a connection. |
} |
} else { |
@@ -284,9 +285,8 @@ void Predictor::PreconnectUrlAndSubresources(const GURL& url, |
std::string host = url.HostNoBrackets(); |
UrlInfo::ResolutionMotivation motivation(UrlInfo::EARLY_LOAD_MOTIVATED); |
const int kConnectionsNeeded = 1; |
- PreconnectOnUIThread(CanonicalizeUrl(url), first_party_for_cookies, |
- motivation, kConnectionsNeeded, |
- url_request_context_getter_); |
+ PreconnectUrl(CanonicalizeUrl(url), first_party_for_cookies, |
+ motivation, kConnectionsNeeded); |
PredictFrameSubresources(url.GetWithEmptyPath(), first_party_for_cookies); |
} |
} |
@@ -824,6 +824,41 @@ void Predictor::EnablePredictorOnIOThread(bool enable) { |
predictor_enabled_ = enable; |
} |
+void Predictor::PreconnectUrl(const GURL& url, |
+ const GURL& first_party_for_cookies, |
+ UrlInfo::ResolutionMotivation motivation, |
+ int count) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
+ BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ |
+ if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
+ PreconnectUrlOnIOThread(url, first_party_for_cookies, motivation, count); |
+ } else { |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&Predictor::PreconnectUrlOnIOThread, |
+ base::Unretained(this), url, first_party_for_cookies, |
+ motivation, count)); |
mmenke
2013/05/23 15:28:36
I hadn't realized the Predictor lived on multiple
kouhei (in TOK)
2013/05/24 00:34:37
The Predictor instance is created in UIthread, but
mmenke
2013/05/24 18:28:55
Thanks for investigating this! Looks like you're
|
+ } |
+} |
+ |
+void Predictor::PreconnectUrlOnIOThread( |
+ const GURL& url, const GURL& first_party_for_cookies, |
+ UrlInfo::ResolutionMotivation motivation, int count) { |
+ GURL canonical_url(CanonicalizeUrl(url)); |
+ recent_preconnects_.SetRecentlySeen(canonical_url); |
+ |
+ PreconnectOnIOThread(url, first_party_for_cookies, motivation, count, |
+ url_request_context_getter_); |
+} |
+ |
+void Predictor::RecordPreconnectNavigationStats(const GURL& url) { |
+ UMA_HISTOGRAM_BOOLEAN( |
+ "Net.PreconnectedNavigation", |
+ recent_preconnects_.WasRecentlySeen(url)); |
+} |
+ |
void Predictor::PredictFrameSubresources(const GURL& url, |
const GURL& first_party_for_cookies) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
@@ -864,9 +899,8 @@ void Predictor::PrepareFrameSubresources(const GURL& url, |
// load any subresources). If we learn about this resource, we will instead |
// provide a more carefully estimated preconnection count. |
if (preconnect_enabled_) { |
- PreconnectOnIOThread(url, first_party_for_cookies, |
- UrlInfo::SELF_REFERAL_MOTIVATED, 2, |
- url_request_context_getter_); |
+ PreconnectUrlOnIOThread(url, first_party_for_cookies, |
+ UrlInfo::SELF_REFERAL_MOTIVATED, 2); |
} |
return; |
} |
@@ -890,8 +924,8 @@ void Predictor::PrepareFrameSubresources(const GURL& url, |
int count = static_cast<int>(std::ceil(connection_expectation)); |
if (url.host() == future_url->first.host()) |
++count; |
- PreconnectOnIOThread(future_url->first, first_party_for_cookies, |
- motivation, count, url_request_context_getter_); |
+ PreconnectUrlOnIOThread(future_url->first, first_party_for_cookies, |
+ motivation, count); |
} else if (connection_expectation > kDNSPreresolutionWorthyExpectedValue) { |
evalution = PRERESOLUTION; |
future_url->second.preresolution_increment(); |